c6dd30c69e206b2627d1481843526ba0c1edb2a5
[~bandali/configs] / init.el
1 ;;; init.el --- bandali's emacs configuration -*- lexical-binding: t -*-
2
3 ;; Copyright (C) 2018-2020 Amin Bandali <bandali@gnu.org>
4
5 ;; This program is free software: you can redistribute it and/or modify
6 ;; it under the terms of the GNU General Public License as published by
7 ;; the Free Software Foundation, either version 3 of the License, or
8 ;; (at your option) any later version.
9
10 ;; This program is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;; GNU General Public License for more details.
14
15 ;; You should have received a copy of the GNU General Public License
16 ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
17
18 ;;; Commentary:
19
20 ;; GNU Emacs configuration of Amin Bandali, computer scientist,
21 ;; Free Software activist, and GNU maintainer & webmaster. Packages
22 ;; are installed through using Borg for a fully reproducible setup.
23
24 ;; Over the years, I've taken inspiration from configurations of many
25 ;; great people. Some that I can remember off the top of my head are:
26 ;;
27 ;; - https://github.com/dieggsy/dotfiles
28 ;; - https://github.com/dakra/dmacs
29 ;; - http://pages.sachachua.com/.emacs.d/Sacha.html
30 ;; - https://github.com/dakrone/eos
31 ;; - http://doc.rix.si/cce/cce.html
32 ;; - https://github.com/jwiegley/dot-emacs
33 ;; - https://github.com/wasamasa/dotemacs
34 ;; - https://github.com/hlissner/doom-emacs
35
36 ;;; Code:
37
38 ;;; Emacs initialization
39
40 (defvar b/before-user-init-time (current-time)
41 "Value of `current-time' when Emacs begins loading `user-init-file'.")
42 (defvar b/emacs-initialized nil
43 "Whether Emacs has been initialized.")
44 (defvar b/exwm-p (string= (system-name) "chaman")
45 "Whether or not we will be using `exwm'.")
46
47 (when (not (bound-and-true-p b/emacs-initialized))
48 (message "Loading Emacs...done (%.3fs)"
49 (float-time (time-subtract b/before-user-init-time
50 before-init-time))))
51
52 ;; temporarily increase `gc-cons-threshhold' and `gc-cons-percentage'
53 ;; during startup to reduce garbage collection frequency. clearing
54 ;; `file-name-handler-alist' seems to help reduce startup time too.
55 (defvar b/gc-cons-threshold gc-cons-threshold)
56 (defvar b/gc-cons-percentage gc-cons-percentage)
57 (defvar b/file-name-handler-alist file-name-handler-alist)
58 (setq gc-cons-threshold (* 30 1024 1024) ; 30 MiB
59 gc-cons-percentage 0.6
60 file-name-handler-alist nil
61 ;; sidesteps a bug when profiling with esup
62 esup-child-profile-require-level 0)
63
64 ;; set them back to their defaults once we're done initializing
65 (defun b/post-init ()
66 "My post-initialize function, run after loading `user-init-file'."
67 (setq b/emacs-initialized t
68 gc-cons-threshold b/gc-cons-threshold
69 gc-cons-percentage b/gc-cons-percentage
70 file-name-handler-alist b/file-name-handler-alist)
71 (when b/exwm-p
72 (with-eval-after-load 'exwm-workspace
73 (setq-default
74 mode-line-format
75 (append
76 mode-line-format
77 '((:eval
78 (format
79 "[%s]" (number-to-string
80 exwm-workspace-current-index)))))))))
81 (add-hook 'after-init-hook #'b/post-init)
82
83 ;; increase number of lines kept in *Messages* log
84 (setq message-log-max 20000)
85
86 ;; optionally, uncomment to supress some byte-compiler warnings
87 ;; (see C-h v byte-compile-warnings RET for more info)
88 ;; (setq byte-compile-warnings
89 ;; '(not free-vars unresolved noruntime lexical make-local))
90
91 \f
92 ;;; whoami
93
94 (setq user-full-name "Amin Bandali"
95 user-mail-address "bandali@gnu.org")
96
97 \f
98 ;;; Package management
99
100 (progn ; `borg'
101 (add-to-list 'load-path
102 (expand-file-name "lib/borg" user-emacs-directory))
103 (require 'borg)
104 (borg-initialize)
105 (setq borg-rewrite-urls-alist
106 '(("git@github.com:" . "https://github.com/")
107 ("git@gitlab.com:" . "https://gitlab.com/"))))
108
109 ;; use-package
110 (if nil ; set to t when need to debug init
111 (progn
112 (setq use-package-verbose t
113 use-package-expand-minimally nil
114 use-package-compute-statistics t
115 debug-on-error t)
116 (require 'use-package))
117 (setq use-package-verbose nil
118 use-package-expand-minimally t))
119
120 (setq use-package-always-defer t)
121 (require 'bind-key)
122
123 \f
124 ;;; Initial setup
125
126 ;; keep ~/.emacs.d clean
127 (use-package no-littering
128 :demand
129 :config
130 (defalias 'b/etc 'no-littering-expand-etc-file-name)
131 (defalias 'b/var 'no-littering-expand-var-file-name))
132
133 (use-package auto-compile
134 :demand
135 :config
136 (auto-compile-on-load-mode)
137 (auto-compile-on-save-mode)
138 (setq auto-compile-display-buffer nil)
139 (setq auto-compile-mode-line-counter t)
140 (setq auto-compile-source-recreate-deletes-dest t)
141 (setq auto-compile-toggle-deletes-nonlib-dest t)
142 (setq auto-compile-update-autoloads t))
143
144 ;; separate custom file (don't want it mixing with init.el)
145 (use-package custom
146 :no-require
147 :config
148 (setq custom-file (b/etc "custom.el"))
149 (when (file-exists-p custom-file)
150 (load custom-file))
151 ;; while at it, treat themes as safe
152 (setf custom-safe-themes t)
153 ;; only one custom theme at a time
154 (comment
155 (defadvice load-theme (before clear-previous-themes activate)
156 "Clear existing theme settings instead of layering them"
157 (mapc #'disable-theme custom-enabled-themes))))
158
159 ;; load the secrets file if it exists, otherwise show a warning
160 (comment
161 (with-demoted-errors
162 (load (b/etc "secrets"))))
163
164 ;; start up emacs server. see
165 ;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Server.html#Emacs-Server
166 (use-package server
167 :defer 0.5
168 :config
169 (declare-function server-edit "server")
170 (bind-key "C-c F D" 'server-edit)
171 (declare-function server-running-p "server")
172 (or (server-running-p) (server-mode)))
173
174 \f
175 ;;; Defaults
176
177 ;;;; C-level customizations
178
179 (setq
180 ;; minibuffer
181 enable-recursive-minibuffers t
182 resize-mini-windows t
183 ;; more useful frame titles
184 frame-title-format '("" invocation-name " - "
185 (:eval
186 (if (buffer-file-name)
187 (abbreviate-file-name (buffer-file-name))
188 "%b")))
189 ;; i don't feel like jumping out of my chair every now and again; so
190 ;; don't BEEP! at me, emacs
191 ring-bell-function 'ignore
192 ;; better scrolling
193 ;; scroll-margin 1
194 ;; scroll-conservatively 10000
195 scroll-step 1
196 scroll-conservatively 101
197 scroll-preserve-screen-position 1
198 ;; focus follows mouse
199 mouse-autoselect-window t)
200
201 (setq-default
202 ;; always use space for indentation
203 indent-tabs-mode nil
204 tab-width 4
205 ;; cursor shape
206 cursor-type t)
207
208 ;; unicode support
209 (comment
210 (dolist (ft (fontset-list))
211 (set-fontset-font
212 ft
213 'unicode
214 (font-spec :name "Source Code Pro" :size 14))
215 (set-fontset-font
216 ft
217 'unicode
218 (font-spec :name "DejaVu Sans Mono")
219 nil
220 'append)
221 ;; (set-fontset-font
222 ;; ft
223 ;; 'unicode
224 ;; (font-spec
225 ;; :name "Symbola monospacified for DejaVu Sans Mono")
226 ;; nil
227 ;; 'append)
228 ;; (set-fontset-font
229 ;; ft
230 ;; #x2115 ; ℕ
231 ;; (font-spec :name "DejaVu Sans Mono")
232 ;; nil
233 ;; 'append)
234 (set-fontset-font
235 ft
236 (cons ?Α ?ω)
237 (font-spec :name "DejaVu Sans Mono" :size 14)
238 nil
239 'prepend)))
240
241 ;;;; Elisp-level customizations
242
243 (use-package startup
244 :no-require
245 :demand
246 :config
247 ;; don't need to see the startup echo area message
248 (advice-add #'display-startup-echo-area-message :override #'ignore)
249 :custom
250 ;; i want *scratch* as my startup buffer
251 (initial-buffer-choice t)
252 ;; i don't need the default hint
253 (initial-scratch-message nil)
254 ;; use customizable text-mode as major mode for *scratch*
255 ;; (initial-major-mode 'text-mode)
256 ;; inhibit buffer list when more than 2 files are loaded
257 (inhibit-startup-buffer-menu t)
258 ;; don't need to see the startup screen or echo area message
259 (inhibit-startup-screen t)
260 (inhibit-startup-echo-area-message user-login-name))
261
262 (use-package files
263 :no-require
264 :demand
265 :custom
266 ;; backups (C-h v make-backup-files RET)
267 (backup-by-copying t)
268 (version-control t)
269 (delete-old-versions t)
270
271 ;; auto-save
272 (auto-save-file-name-transforms
273 `((".*" ,(b/var "auto-save/") t)))
274
275 ;; insert newline at the end of files
276 (require-final-newline t)
277
278 ;; open read-only file buffers in view-mode
279 ;; (enables niceties like `q' for quit)
280 (view-read-only t))
281
282 ;; disable disabled commands
283 (setq disabled-command-function nil)
284
285 ;; lazy-person-friendly yes/no prompts
286 (defalias 'yes-or-no-p #'y-or-n-p)
287
288 ;; enable automatic reloading of changed buffers and files
289 (use-package autorevert
290 :demand
291 :config
292 (global-auto-revert-mode 1)
293 :custom
294 (auto-revert-verbose nil)
295 (global-auto-revert-non-file-buffers nil))
296
297 ;; time and battery in mode-line
298 (use-package time
299 :demand
300 :config
301 (display-time-mode)
302 :custom
303 (display-time-default-load-average nil)
304 (display-time-format " %a %b %-e %-l:%M%P")
305 (display-time-mail-icon '(image :type xpm :file "gnus/gnus-pointer.xpm" :ascent center))
306 (display-time-use-mail-icon t))
307
308 (use-package battery
309 :demand
310 :config
311 (display-battery-mode)
312 :custom
313 (battery-mode-line-format "%p%% %t"))
314
315 (use-package fringe
316 :demand
317 :config
318 ;; smaller fringe
319 ;; (fringe-mode '(3 . 1))
320 (fringe-mode nil))
321
322 (use-package winner
323 :demand
324 :config
325 ;; enable winner-mode (C-h f winner-mode RET)
326 (winner-mode 1))
327
328 (use-package compile
329 :config
330 ;; don't display *compilation* buffer on success. based on
331 ;; https://stackoverflow.com/a/17788551, with changes to use `cl-letf'
332 ;; instead of the now obsolete `flet'.
333 (defun b/compilation-finish-function (buffer outstr)
334 (unless (string-match "finished" outstr)
335 (switch-to-buffer-other-window buffer))
336 t)
337
338 (setq compilation-finish-functions #'b/compilation-finish-function)
339
340 (require 'cl-macs)
341
342 (defadvice compilation-start
343 (around inhibit-display
344 (command &optional mode name-function highlight-regexp))
345 (if (not (string-match "^\\(find\\|grep\\)" command))
346 (cl-letf (((symbol-function 'display-buffer) #'ignore))
347 (save-window-excursion ad-do-it))
348 ad-do-it))
349 (ad-activate 'compilation-start))
350
351 (use-package isearch
352 :custom
353 ;; allow scrolling in Isearch
354 (isearch-allow-scroll t)
355 ;; search for non-ASCII characters: i’d like non-ASCII characters such
356 ;; as ‘’“”«»‹›áⓐ𝒶 to be selected when i search for their ASCII
357 ;; counterpart. shoutout to
358 ;; http://endlessparentheses.com/new-in-emacs-25-1-easily-search-non-ascii-characters.html
359 (search-default-mode #'char-fold-to-regexp))
360
361 ;; uncomment to extend the above behaviour to query-replace
362 (comment
363 (use-package replace
364 :custom
365 (replace-char-fold t)))
366
367 (use-package vc
368 :bind ("C-x v C-=" . vc-ediff))
369
370 (use-package vc-git
371 :after vc
372 :custom
373 (vc-git-print-log-follow t))
374
375 (use-package ediff
376 :config (add-hook 'ediff-after-quit-hook-internal 'winner-undo)
377 :custom ((ediff-window-setup-function 'ediff-setup-windows-plain)
378 (ediff-split-window-function 'split-window-horizontally)))
379
380 (use-package face-remap
381 :custom
382 ;; gentler font resizing
383 (text-scale-mode-step 1.05))
384
385 (use-package mwheel
386 :defer 0.4
387 :config
388 (setq mouse-wheel-scroll-amount '(1 ((shift) . 1)) ; one line at a time
389 mouse-wheel-progressive-speed nil ; don't accelerate scrolling
390 mouse-wheel-follow-mouse t)) ; scroll window under mouse
391
392 (use-package pixel-scroll
393 :defer 0.4
394 :config (pixel-scroll-mode 1))
395
396 (use-package epg-config
397 :config
398 ;; ask for GPG passphrase in minibuffer
399 ;; this will fail if gpg>=2.1 is not available
400 (setq epg-pinentry-mode 'loopback)
401 :custom
402 (epg-gpg-program (executable-find "gpg")))
403
404 (use-package epg
405 :after epg-config)
406
407 (use-package pinentry
408 :disabled
409 :demand
410 :after (epa epg server)
411 :config
412 ;; workaround for systemd-based distros:
413 ;; (setq pinentry--socket-dir server-socket-dir)
414 (pinentry-start))
415
416 (use-package auth-source
417 :custom
418 (auth-sources '("~/.authinfo.gpg"))
419 (authinfo-hidden (regexp-opt '("password" "client-secret" "token"))))
420
421 \f
422 ;;; General bindings
423
424 (bind-keys
425 ("C-a" . b/move-indentation-or-beginning-of-line)
426 ("C-c a i" . ielm)
427 ("C-c d" . b/duplicate-line-or-region)
428
429 ("C-c e b" . eval-buffer)
430 ("C-c e e" . eval-last-sexp)
431 ("C-c e p" . pp-macroexpand-last-sexp)
432 ("C-c e r" . eval-region)
433
434 ("C-c e i" . emacs-init-time)
435 ("C-c e u" . emacs-uptime)
436 ("C-c e v" . emacs-version)
437
438 ("C-c f ." . find-file)
439 ("C-c f d" . find-name-dired)
440 ("C-c f l" . find-library)
441
442 ("C-c F m" . make-frame-command)
443 ("C-c F d" . delete-frame)
444
445 ("C-S-h C" . describe-char)
446 ("C-S-h F" . describe-face)
447
448 ("C-S-j" . b/join-line-top)
449
450 ("C-c x" . execute-extended-command)
451
452 ("C-x k" . b/kill-current-buffer)
453 ("C-x K" . kill-buffer)
454 ("C-x s" . save-buffer)
455 ("C-x S" . save-some-buffers)
456
457 :map emacs-lisp-mode-map
458 ("<C-return>" . b/add-elisp-section))
459
460 (when (display-graphic-p)
461 (unbind-key "C-z" global-map))
462
463 (bind-keys
464 ;; for back and forward mouse keys
465 ("<XF86Back>" . previous-buffer)
466 ("<mouse-8>" . previous-buffer)
467 ;; ("<drag-mouse-8>" . previous-buffer)
468 ("<XF86Forward>" . next-buffer)
469 ("<mouse-9>" . next-buffer)
470 ;; ("<drag-mouse-9>" . next-buffer)
471 ;; ("<drag-mouse-2>" . kill-this-buffer)
472 ;; ("<drag-mouse-3>" . switch-to-buffer)
473 )
474
475 \f
476 ;;; Essential packages
477
478 (when b/exwm-p
479 (require 'bandali-exwm))
480
481 (require 'bandali-org)
482
483 (require 'bandali-theme)
484
485 ;; *the* right way to do git
486 (use-package magit
487 :bind (("C-x g" . magit-status)
488 ("C-c g g" . magit-status)
489 ("C-c g b" . magit-blame-addition)
490 ("C-c g l" . magit-log-buffer-file))
491 :config
492 (declare-function magit-add-section-hook "magit-section"
493 (hook function &optional at append local))
494 (magit-add-section-hook 'magit-status-sections-hook
495 'magit-insert-modules
496 'magit-insert-stashes
497 'append)
498 ;; (magit-add-section-hook 'magit-status-sections-hook
499 ;; 'magit-insert-ignored-files
500 ;; 'magit-insert-untracked-files
501 ;; 'append)
502 (setq magit-repository-directories '(("~/.emacs.d/" . 0)
503 ("~/src/git/" . 2)))
504 (nconc magit-section-initial-visibility-alist
505 '(([unpulled status] . show)
506 ([unpushed status] . show)))
507 (declare-function magit-display-buffer-fullframe-status-v1 "magit-mode" (buffer))
508 :custom
509 (magit-diff-refine-hunk t)
510 (magit-display-buffer-function #'magit-display-buffer-fullframe-status-v1)
511 ;; (magit-completing-read-function 'magit-ido-completing-read)
512 :custom-face (magit-diff-file-heading ((t (:weight normal)))))
513
514 ;; recently opened files
515 (use-package recentf
516 :defer 0.2
517 :config
518 (add-to-list 'recentf-keep 'file-remote-p)
519 :config
520 (recentf-mode)
521 :custom
522 (recentf-max-saved-items 2000))
523
524 ;; needed for history for counsel
525 (use-package amx
526 :defer 0.3
527 :config
528 (amx-mode))
529
530 ;; (require 'bandali-ido)
531 (require 'bandali-ivy)
532
533 (require 'bandali-eshell)
534 ;; (require 'bandali-multi-term)
535
536 (require 'bandali-ibuffer)
537
538 (use-package outline
539 :disabled
540 :hook (prog-mode . outline-minor-mode)
541 :bind
542 (:map
543 outline-minor-mode-map
544 ("<s-tab>" . outline-toggle-children)
545 ("M-p" . outline-previous-visible-heading)
546 ("M-n" . outline-next-visible-heading)
547 :prefix-map b/outline-prefix-map
548 :prefix "s-O"
549 ("TAB" . outline-toggle-children)
550 ("a" . outline-hide-body)
551 ("H" . outline-hide-body)
552 ("S" . outline-show-all)
553 ("h" . outline-hide-subtree)
554 ("s" . outline-show-subtree))
555 :config
556 (when (featurep 'which-key)
557 (which-key-add-key-based-replacements
558 "C-c @" "outline"
559 "s-O" "outline")))
560
561 (require 'bandali-dired)
562
563 (use-package help
564 :bind
565 (:map help-mode-map
566 ("p" . backward-button)
567 ("n" . forward-button))
568 :config
569 (temp-buffer-resize-mode)
570 (setq help-window-select t))
571
572 (use-package tramp
573 :config
574 (add-to-list 'tramp-default-proxies-alist '(nil "\\`root\\'" "/ssh:%h:"))
575 (add-to-list 'tramp-default-proxies-alist '("localhost" nil nil))
576 (add-to-list 'tramp-default-proxies-alist
577 (list (regexp-quote (system-name)) nil nil)))
578
579 (use-package doc-view
580 :bind (:map doc-view-mode-map
581 ("M-RET" . image-previous-line)))
582
583 ;; Email (with Gnus, message, and EBDB)
584 (require 'bandali-gnus)
585 (use-package sendmail
586 :config
587 (setq sendmail-program (executable-find "msmtp")
588 ;; message-sendmail-extra-arguments '("-v" "-d")
589 mail-specify-envelope-from t
590 mail-envelope-from 'header))
591 (require 'bandali-message)
592 (require 'bandali-ebdb)
593
594 ;; IRC (with ERC and ZNC)
595 (require 'bandali-erc)
596
597 (use-package scpaste
598 :config
599 (setq scpaste-http-destination "https://p.bndl.org"
600 scpaste-scp-destination "p:~"))
601
602 \f
603 ;;; Editing
604
605 ;; highlight uncommitted changes in the left fringe
606 (use-package diff-hl
607 :defer 0.6
608 :config
609 (setq diff-hl-draw-borders nil)
610 (global-diff-hl-mode)
611 :hook
612 ((magit-pre-refresh . diff-hl-magit-pre-refresh)
613 (magit-post-refresh . diff-hl-magit-post-refresh)))
614
615 ;; display Lisp objects at point in the echo area
616 (use-package eldoc
617 :when (version< "25" emacs-version)
618 :config (global-eldoc-mode))
619
620 ;; highlight matching parens
621 (use-package paren
622 :demand
623 :config (show-paren-mode))
624
625 (use-package elec-pair
626 :demand
627 :config (electric-pair-mode))
628
629 (use-package simple
630 :config (column-number-mode)
631 :custom
632 ;; Save what I copy into clipboard from other applications into Emacs'
633 ;; kill-ring, which would allow me to still be able to easily access
634 ;; it in case I kill (cut or copy) something else inside Emacs before
635 ;; yanking (pasting) what I'd originally intended to.
636 (save-interprogram-paste-before-kill t))
637
638 ;; save minibuffer history
639 (use-package savehist
640 :demand
641 :config
642 (savehist-mode)
643 (add-to-list 'savehist-additional-variables 'kill-ring))
644
645 ;; automatically save place in files
646 (use-package saveplace
647 :when (version< "25" emacs-version)
648 :config (save-place-mode))
649
650 (use-package prog-mode
651 :config (global-prettify-symbols-mode)
652 (defun indicate-buffer-boundaries-left ()
653 (setq indicate-buffer-boundaries 'left))
654 (add-hook 'prog-mode-hook #'indicate-buffer-boundaries-left))
655
656 (use-package text-mode
657 :bind (:map text-mode-map ("C-*" . b/insert-asterism))
658 :hook ((text-mode . indicate-buffer-boundaries-left)
659 (text-mode . flyspell-mode)))
660
661 (use-package conf-mode
662 :mode "\\.*rc$")
663
664 (use-package sh-script
665 :mode ("\\.bashrc$" . sh-mode))
666
667 (use-package company
668 :disabled
669 :bind
670 (:map company-active-map
671 ([tab] . company-complete-common-or-cycle)
672 ([escape] . company-abort)
673 ("C-p" . company-select-previous-or-abort)
674 ("C-n" . company-select-next-or-abort))
675 :custom
676 (company-minimum-prefix-length 1)
677 (company-selection-wrap-around t)
678 (company-dabbrev-char-regexp "\\sw\\|\\s_\\|[-_]")
679 (company-dabbrev-downcase nil)
680 (company-dabbrev-ignore-case nil)
681 ;; :config
682 ;; (global-company-mode t)
683 )
684
685 (use-package flycheck
686 :disabled
687 :defer 0.6
688 :hook (prog-mode . flycheck-mode)
689 :bind
690 (:map flycheck-mode-map
691 ("M-P" . flycheck-previous-error)
692 ("M-N" . flycheck-next-error))
693 :config
694 ;; Use the load-path from running Emacs when checking elisp files
695 (setq flycheck-emacs-lisp-load-path 'inherit)
696
697 ;; Only flycheck when I actually save the buffer
698 (setq flycheck-check-syntax-automatically '(mode-enabled save))
699 :custom (flycheck-mode-line-prefix "flyc"))
700
701 ;; (use-package flyspell)
702
703 ;; http://endlessparentheses.com/ispell-and-apostrophes.html
704 (use-package ispell
705 :disabled
706 :defer 0.6
707 :config
708 ;; ’ can be part of a word
709 (setq ispell-local-dictionary-alist
710 `((nil "[[:alpha:]]" "[^[:alpha:]]"
711 "['\x2019]" nil ("-B") nil utf-8))
712 ispell-program-name (executable-find "hunspell"))
713 ;; don't send ’ to the subprocess
714 (defun endless/replace-apostrophe (args)
715 (cons (replace-regexp-in-string
716 "’" "'" (car args))
717 (cdr args)))
718 (advice-add #'ispell-send-string :filter-args
719 #'endless/replace-apostrophe)
720
721 ;; convert ' back to ’ from the subprocess
722 (defun endless/replace-quote (args)
723 (if (not (derived-mode-p 'org-mode))
724 args
725 (cons (replace-regexp-in-string
726 "'" "’" (car args))
727 (cdr args))))
728 (advice-add #'ispell-parse-output :filter-args
729 #'endless/replace-quote))
730
731 (use-package abbrev
732 :hook (text-mode . abbrev-mode))
733
734 \f
735 ;;; Programming modes
736
737 (use-package lisp-mode
738 :config
739 (defun indent-spaces-mode ()
740 (setq indent-tabs-mode nil))
741 (add-hook 'lisp-interaction-mode-hook #'indent-spaces-mode))
742
743 (use-package alloy-mode
744 :mode "\\.\\(als\\|dsh\\)\\'"
745 :config
746 (setq alloy-basic-offset 2)
747 ;; (defun b/alloy-simple-indent (start end)
748 ;; (interactive "r")
749 ;; ;; (if (region-active-p)
750 ;; ;; (indent-rigidly start end alloy-basic-offset)
751 ;; ;; (if (bolp)
752 ;; ;; (indent-rigidly (line-beginning-position)
753 ;; ;; (line-end-position)
754 ;; ;; alloy-basic-offset)))
755 ;; (indent-to (+ (current-column) alloy-basic-offset)))
756 :bind (:map alloy-mode-map
757 ("RET" . electric-newline-and-maybe-indent)
758 ;; ("TAB" . b/alloy-simple-indent)
759 ("TAB" . indent-for-tab-command))
760 :hook (alloy-mode . (lambda () (setq-local indent-tabs-mode nil))))
761
762 (use-package lean-mode
763 :disabled
764 :defer 0.4
765 :init (eval-when-compile (defvar lean-mode-map))
766 :bind (:map lean-mode-map
767 ("S-SPC" . company-complete))
768 :config
769 (require 'lean-input)
770 (setq default-input-method "Lean"
771 lean-input-tweak-all '(lean-input-compose
772 (lean-input-prepend "/")
773 (lean-input-nonempty))
774 lean-input-user-translations '(("/" "/")))
775 (lean-input-setup))
776
777 (use-package sgml-mode
778 :config
779 (setq sgml-basic-offset 0))
780
781 (use-package css-mode
782 :config
783 (setq css-indent-offset 2))
784
785 (use-package geiser
786 :disabled)
787
788 (use-package geiser-guile
789 :disabled
790 :config
791 (setq geiser-guile-load-path "~/src/git/guix"))
792
793 (use-package guix
794 :disabled)
795
796 (use-package go-mode
797 :disabled)
798
799 (use-package po-mode
800 :disabled
801 :hook
802 (po-mode . (lambda () (run-with-timer 0.1 nil 'View-exit))))
803
804 (use-package auctex
805 :disabled
806 :custom
807 (font-latex-fontify-sectioning 'color))
808
809 (use-package tex-mode
810 :config
811 (cl-delete-if
812 (lambda (p) (string-match "^---?" (car p)))
813 tex--prettify-symbols-alist)
814 :hook ((tex-mode . auto-fill-mode)
815 (tex-mode . flyspell-mode)))
816
817 ;; (use-package george-mode
818 ;; :straight (:host nil :repo "https://git.shemshak.org/amin/george-mode")
819 ;; :mode "\\.grg\\'")
820
821 \f
822 ;;; Emacs enhancements & auxiliary packages
823
824 (use-package man
825 :config (setq Man-width 80))
826
827 (use-package which-key
828 :defer 0.4
829 :config
830 (which-key-add-key-based-replacements
831 ;; prefixes for global prefixes and minor modes
832 "C-c !" "flycheck"
833 "C-x RET" "coding system"
834 "C-x 8" "unicode"
835 "C-x @" "event modifiers"
836 "C-x a" "abbrev/expand"
837 "C-x r" "rectangle/register/bookmark"
838 "C-x t" "tabs"
839 "C-x v" "version control"
840 "C-x X" "edebug"
841 "C-x C-a" "edebug"
842 "C-x C-k" "kmacro"
843 ;; prefixes for my personal bindings
844 "C-c &" "yasnippet"
845 "C-c a" "applications"
846 "C-c a e" "erc"
847 "C-c a o" "org"
848 "C-c a s" "shells"
849 "C-c b" "buffers"
850 "C-c c" "compile-and-comments"
851 "C-c e" "eval"
852 "C-c f" "files"
853 "C-c F" "frames"
854 "C-c g" "magit"
855 "C-S-h" "help(ful)"
856 "C-c q" "boxquote"
857 "C-c t" "themes")
858
859 ;; prefixes for major modes
860 (which-key-add-major-mode-key-based-replacements 'org-mode
861 "C-c C-v" "org-babel")
862
863 (which-key-mode)
864 :custom
865 (which-key-add-column-padding 5)
866 (which-key-idle-delay 10000)
867 (which-key-idle-secondary-delay 0.05)
868 (which-key-max-description-length 32)
869 (which-key-show-early-on-C-h t))
870
871 ;; (require 'bandali-projectile)
872
873 (use-package helpful
874 :disabled
875 :defer 0.6
876 :bind
877 (("C-S-h c" . helpful-command)
878 ("C-S-h f" . helpful-callable) ; helpful-function
879 ("C-S-h v" . helpful-variable)
880 ("C-S-h k" . helpful-key)
881 ("C-S-h p" . helpful-at-point)))
882
883 (use-package unkillable-scratch
884 :defer 0.6
885 :config
886 (unkillable-scratch 1)
887 :custom
888 (unkillable-buffers '("^\\*scratch\\*$" "^\\*Messages\\*$")))
889
890 ;; ,----
891 ;; | make pretty boxed quotes like this
892 ;; `----
893 (use-package boxquote
894 :defer 0.6
895 :bind
896 (:prefix-map
897 b/boxquote-prefix-map
898 :prefix "C-c q"
899 ("b" . boxquote-buffer)
900 ("B" . boxquote-insert-buffer)
901 ("d" . boxquote-defun)
902 ("F" . boxquote-insert-file)
903 ("hf" . boxquote-describe-function)
904 ("hk" . boxquote-describe-key)
905 ("hv" . boxquote-describe-variable)
906 ("hw" . boxquote-where-is)
907 ("k" . boxquote-kill)
908 ("p" . boxquote-paragraph)
909 ("q" . boxquote-boxquote)
910 ("r" . boxquote-region)
911 ("s" . boxquote-shell-command)
912 ("t" . boxquote-text)
913 ("T" . boxquote-title)
914 ("u" . boxquote-unbox)
915 ("U" . boxquote-unbox-region)
916 ("y" . boxquote-yank)
917 ("M-q" . boxquote-fill-paragraph)
918 ("M-w" . boxquote-kill-ring-save)))
919
920 (use-package hl-todo
921 ;; highlight TODOs in buffers
922 :defer 0.5
923 :config
924 (global-hl-todo-mode))
925
926 (use-package page-break-lines
927 :defer 0.5
928 :custom
929 (page-break-lines-max-width fill-column)
930 :config
931 (global-page-break-lines-mode))
932
933 (use-package expand-region
934 :bind ("C-=" . er/expand-region))
935
936 (require 'bandali-yasnippet)
937
938 (use-package debbugs
939 :bind
940 (("C-c D d" . debbugs-gnu)
941 ("C-c D b" . debbugs-gnu-bugs)
942 ("C-c D e" .
943 (lambda ()
944 (interactive) ; bug-gnu-emacs
945 (setq debbugs-gnu-current-suppress t)
946 (debbugs-gnu debbugs-gnu-default-severities '("emacs"))))
947 ("C-c D g" . ; bug-gnuzilla
948 (lambda ()
949 (interactive)
950 (setq debbugs-gnu-current-suppress t)
951 (debbugs-gnu debbugs-gnu-default-severities '("gnuzilla"))))
952 ("C-c D G b" . ; bug-guix
953 (lambda ()
954 (interactive)
955 (setq debbugs-gnu-current-suppress t)
956 (debbugs-gnu debbugs-gnu-default-severities '("guix"))))
957 ("C-c D G p" . ; guix-patches
958 (lambda ()
959 (interactive)
960 (setq debbugs-gnu-current-suppress t)
961 (debbugs-gnu debbugs-gnu-default-severities '("guix-patches"))))))
962
963 (comment
964
965 (use-package org-ref
966 :init
967 (b/setq-every '("~/usr/org/references.bib")
968 reftex-default-bibliography
969 org-ref-default-bibliography)
970 (setq
971 org-ref-bibliography-notes "~/usr/org/notes.org"
972 org-ref-pdf-directory "~/usr/org/bibtex-pdfs/"))
973
974 ;; (use-package fill-column-indicator)
975
976 (use-package window
977 :bind
978 (("C-c w s l" . (lambda ()
979 (interactive)
980 (split-window-right)
981 (other-window 1)))
982 ("C-c w s j" . (lambda ()
983 (interactive)
984 (split-window-below)
985 (other-window 1)))
986 ("C-c w q" . quit-window))
987 :custom
988 (split-width-threshold 150))
989
990 (use-package windmove
991 :defer 0.6
992 :bind
993 (("C-c w h" . windmove-left)
994 ("C-c w j" . windmove-down)
995 ("C-c w k" . windmove-up)
996 ("C-c w l" . windmove-right)
997 ("C-c w H" . windmove-swap-states-left)
998 ("C-c w J" . windmove-swap-states-down)
999 ("C-c w K" . windmove-swap-states-up)
1000 ("C-c w L" . windmove-swap-states-right)))
1001
1002 (use-package pass
1003 :commands pass
1004 :bind ("C-c a p" . pass)
1005 :hook (pass-mode . View-exit))
1006
1007 (use-package pdf-tools
1008 :defer 0.5
1009 :bind (:map pdf-view-mode-map
1010 ("<C-XF86Back>" . pdf-history-backward)
1011 ("<mouse-8>" . pdf-history-backward)
1012 ("<drag-mouse-8>" . pdf-history-backward)
1013 ("<C-XF86Forward>" . pdf-history-forward)
1014 ("<mouse-9>" . pdf-history-forward)
1015 ("<drag-mouse-9>" . pdf-history-forward)
1016 ("M-RET" . image-previous-line)
1017 ("C-s" . isearch-forward)
1018 ("s s" . isearch-forward))
1019 :config (pdf-tools-install nil t)
1020 :custom (pdf-view-resize-factor 1.05))
1021
1022 (use-package org-pdftools
1023 :disabled
1024 :straight (:host github :repo "fuxialexander/org-pdftools")
1025 :demand
1026 :after org
1027 :config
1028 (with-eval-after-load 'org
1029 (require 'org-pdftools)))
1030
1031 (use-package biblio)
1032
1033 (use-package reftex
1034 :hook (latex-mode . reftex-mode))
1035
1036 (use-package reftex-cite
1037 :after reftex
1038 :disabled ; enable to disable
1039 ; reftex-cite's default choice
1040 ; of previous word
1041 :config
1042 (defun reftex-get-bibkey-default ()
1043 "If the cursor is in a citation macro, return the word before the macro."
1044 (let* ((macro (reftex-what-macro 1)))
1045 (save-excursion
1046 (when (and macro (string-match "cite" (car macro)))
1047 (goto-char (cdr macro)))
1048 (reftex-this-word)))))
1049
1050 (use-package dmenu
1051 :custom
1052 (dmenu-prompt-string "run: ")
1053 (dmenu-save-file (b/var "dmenu-items")))
1054
1055 (use-package eosd
1056 ;; TODO: fix build by properly building the eosd-pixbuf.c module
1057 ;; e.g. see https://github.com/raxod502/straight.el/issues/386
1058 :disabled
1059 :straight (:host github :repo "clarete/eosd")
1060 :demand
1061 :after exwm
1062 :config
1063 (eosd-start))
1064
1065 (use-package eww
1066 :bind ("C-c a e w" . eww)
1067 :custom
1068 (eww-download-directory (file-name-as-directory
1069 (getenv "XDG_DOWNLOAD_DIR"))))
1070
1071 \f
1072 ;;; Post initialization
1073
1074 )
1075 (message "Loading %s...done (%.3fs)" user-init-file
1076 (float-time (time-subtract (current-time)
1077 b/before-user-init-time)))
1078
1079 ;;; init.el ends here