601d8e3810006f25eafc5fcfc79517a220dbcc45
[~bandali/configs] / .emacs.d / init.el
1 ;;; init.el --- bandali's emacs configuration -*- lexical-binding: t -*-
2
3 ;; Copyright (C) 2018-2019 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 ;; Emacs configuration of Amin Bandali, computer scientist, functional
21 ;; programmer, and free software activist. Uses straight.el for
22 ;; purely functional and fully reproducible package management.
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 (message "Loading Emacs...done (%.3fs)"
43 (float-time (time-subtract b/before-user-init-time
44 before-init-time)))
45
46 ;; temporarily increase `gc-cons-threshhold' and `gc-cons-percentage'
47 ;; during startup to reduce garbage collection frequency. clearing
48 ;; `file-name-handler-alist' seems to help reduce startup time too.
49 (defvar b/gc-cons-threshold gc-cons-threshold)
50 (defvar b/gc-cons-percentage gc-cons-percentage)
51 (defvar b/file-name-handler-alist file-name-handler-alist)
52 (setq gc-cons-threshold (* 400 1024 1024) ; 400 MiB
53 gc-cons-percentage 0.6
54 file-name-handler-alist nil
55 ;; sidesteps a bug when profiling with esup
56 esup-child-profile-require-level 0)
57
58 ;; set them back to their defaults once we're done initializing
59 (defun b/post-init ()
60 (setq gc-cons-threshold b/gc-cons-threshold
61 gc-cons-percentage b/gc-cons-percentage
62 file-name-handler-alist b/file-name-handler-alist))
63 (add-hook 'after-init-hook #'b/post-init)
64
65 ;; increase number of lines kept in *Messages* log
66 (setq message-log-max 20000)
67
68 ;; optionally, uncomment to supress some byte-compiler warnings
69 ;; (see C-h v byte-compile-warnings RET for more info)
70 ;; (setq byte-compile-warnings
71 ;; '(not free-vars unresolved noruntime lexical make-local))
72
73 \f
74 ;;; whoami
75
76 (setq user-full-name "Amin Bandali"
77 user-mail-address "bandali@gnu.org")
78
79 \f
80 ;;; comment macro
81
82 ;; useful for commenting out multiple sexps at a time
83 (defmacro comment (&rest _)
84 "Comment out one or more s-expressions."
85 (declare (indent defun))
86 nil)
87
88 \f
89 ;;; Package management
90
91 ;; No package.el (for emacs 26 and before, uncomment the following)
92 ;; Not necessary when using straight.el
93 ;; (C-h v straight-package-neutering-mode RET)
94
95 (when (and
96 (not (featurep 'straight))
97 (version< emacs-version "27"))
98 (setq package-enable-at-startup nil)
99 ;; (package-initialize)
100 )
101
102 ;; for emacs 27 and later, we use early-init.el. see
103 ;; https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=24acb31c04b4048b85311d794e600ecd7ce60d3b
104
105 ;; straight.el
106
107 ;; Main engine start...
108
109 (setq straight-repository-branch "develop"
110 straight-check-for-modifications '(check-on-save find-when-checking))
111
112 (defun b/bootstrap-straight ()
113 (defvar bootstrap-version)
114 (let ((bootstrap-file
115 (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
116 (bootstrap-version 5))
117 (unless (file-exists-p bootstrap-file)
118 (with-current-buffer
119 (url-retrieve-synchronously
120 "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
121 'silent 'inhibit-cookies)
122 (goto-char (point-max))
123 (eval-print-last-sexp)))
124 (load bootstrap-file nil 'nomessage)))
125
126 ;; Solid rocket booster ignition...
127
128 (b/bootstrap-straight)
129
130 ;; We have lift off!
131
132 (setq straight-use-package-by-default t)
133
134 (defmacro use-feature (name &rest args)
135 "Like `use-package', but with `straight-use-package-by-default' disabled."
136 (declare (indent 1))
137 `(use-package ,name
138 :straight nil
139 ,@args))
140
141 (with-eval-after-load 'use-package-core
142 (let ((upflk (car use-package-font-lock-keywords)))
143 (font-lock-add-keywords
144 'emacs-lisp-mode
145 `((,(replace-regexp-in-string
146 "use-package" "use-feature"
147 (car upflk))
148 ,@(cdr upflk))))))
149
150 (with-eval-after-load 'recentf
151 (add-to-list 'recentf-exclude
152 (expand-file-name "~/.emacs.d/straight/build/")))
153
154 (defun b/reload-init ()
155 "Reload init.el."
156 (interactive)
157 (setq b/file-name-handler-alist file-name-handler-alist)
158 (load user-init-file nil 'nomessage)
159 (b/post-init))
160
161 ;; use-package
162 (straight-use-package 'use-package)
163
164 (if nil ; set to t when need to debug init
165 (progn
166 (setq use-package-verbose t
167 use-package-expand-minimally nil
168 use-package-compute-statistics t
169 debug-on-error t)
170 (require 'use-package))
171 (setq use-package-verbose nil
172 use-package-expand-minimally t))
173
174 (setq use-package-always-defer t)
175 (require 'bind-key)
176
177 (use-package delight)
178
179 \f
180 ;;; Initial setup
181
182 ;; keep ~/.emacs.d clean
183 (defvar b/etc-dir
184 (expand-file-name
185 (convert-standard-filename "etc/") user-emacs-directory)
186 "The directory where packages place their configuration files.")
187
188 (defvar b/var-dir
189 (expand-file-name
190 (convert-standard-filename "var/") user-emacs-directory)
191 "The directory where packages place their persistent data files.")
192
193 (defun b/etc (file)
194 "Expand filename FILE relative to `b/etc-dir'."
195 (expand-file-name (convert-standard-filename file) b/etc-dir))
196
197 (defun b/var (file)
198 "Expand filename FILE relative to `b/var-dir'."
199 (expand-file-name (convert-standard-filename file) b/var-dir))
200
201 (setq
202 auto-save-list-file-prefix (b/var "auto-save/sessions/")
203 nsm-settings-file (b/var "nsm-settings.el"))
204
205 ;; separate custom file (don't want it mixing with init.el)
206 (use-feature custom
207 :no-require t
208 :config
209 (setq custom-file (b/etc "custom.el"))
210 (when (file-exists-p custom-file)
211 (load custom-file))
212 ;; while at it, treat themes as safe
213 (setf custom-safe-themes t))
214
215 ;; load the secrets file if it exists, otherwise show a warning
216 (comment
217 (with-demoted-errors
218 (load (b/etc "secrets"))))
219
220 ;; better $PATH (and other environment variable) handling
221 (use-package exec-path-from-shell
222 :defer 0.4
223 :init
224 (setq exec-path-from-shell-arguments nil
225 exec-path-from-shell-check-startup-files nil)
226 :config
227 (exec-path-from-shell-initialize)
228 ;; while we're at it, let's fix access to our running ssh-agent
229 (exec-path-from-shell-copy-env "SSH_AGENT_PID")
230 (exec-path-from-shell-copy-env "SSH_AUTH_SOCK"))
231
232 ;; only one custom theme at a time
233 (comment
234 (defadvice load-theme (before clear-previous-themes activate)
235 "Clear existing theme settings instead of layering them"
236 (mapc #'disable-theme custom-enabled-themes)))
237
238 ;; start up emacs server. see
239 ;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Server.html#Emacs-Server
240 (use-feature server
241 :defer 0.4
242 :config (or (server-running-p) (server-mode)))
243
244 ;; unicode support
245 (comment
246 (dolist (ft (fontset-list))
247 (set-fontset-font
248 ft
249 'unicode
250 (font-spec :name "Source Code Pro" :size 14))
251 (set-fontset-font
252 ft
253 'unicode
254 (font-spec :name "DejaVu Sans Mono")
255 nil
256 'append)
257 ;; (set-fontset-font
258 ;; ft
259 ;; 'unicode
260 ;; (font-spec
261 ;; :name "Symbola monospacified for DejaVu Sans Mono")
262 ;; nil
263 ;; 'append)
264 ;; (set-fontset-font
265 ;; ft
266 ;; #x2115 ; ℕ
267 ;; (font-spec :name "DejaVu Sans Mono")
268 ;; nil
269 ;; 'append)
270 (set-fontset-font
271 ft
272 (cons ?Α ?ω)
273 (font-spec :name "DejaVu Sans Mono" :size 14)
274 nil
275 'prepend)))
276
277 ;; gentler font resizing
278 (setq text-scale-mode-step 1.05)
279
280 ;; focus follows mouse
281 (setq mouse-autoselect-window t)
282
283 (defun b/no-mouse-autoselect-window ()
284 "Conveniently disable `focus-follows-mouse'.
285 For disabling the behaviour for certain buffers and/or modes."
286 (make-local-variable 'mouse-autoselect-window)
287 (setq mouse-autoselect-window nil))
288
289 ;; better scrolling
290 (setq ;; scroll-margin 1
291 ;; scroll-conservatively 10000
292 scroll-step 1
293 scroll-conservatively 10
294 scroll-preserve-screen-position 1)
295
296 (use-feature mwheel
297 :defer 0.4
298 :config
299 (setq mouse-wheel-scroll-amount '(1 ((shift) . 1)) ; one line at a time
300 mouse-wheel-progressive-speed nil ; don't accelerate scrolling
301 mouse-wheel-follow-mouse t)) ; scroll window under mouse
302
303 (use-feature pixel-scroll
304 :defer 0.4
305 :config (pixel-scroll-mode 1))
306
307 ;; ask for GPG passphrase in minibuffer
308 (use-feature epa
309 :custom
310 ; this will fail if gpg>=2.1 is not available
311 (epa-pinentry-mode 'loopback))
312
313 (use-feature epg-config
314 :defer 0.4
315 :custom
316 ((epg-gpg-program (executable-find "gpg"))
317 (epg-pinentry-mode 'loopback)))
318
319 (use-feature epg
320 :after epg-config)
321
322 (use-package pinentry
323 :demand
324 :after (epa epg server)
325 :config
326 (setq pinentry--socket-dir server-socket-dir)
327 (pinentry-start))
328
329 ;; useful libraries
330 (require 'cl-lib)
331 (require 'subr-x)
332
333 \f
334 ;;; Useful utilities
335
336 (defmacro b/setq-every (value &rest vars)
337 "Set all the variables from VARS to value VALUE."
338 (declare (indent defun) (debug t))
339 `(progn ,@(mapcar (lambda (x) (list 'setq x value)) vars)))
340
341 (defun b/start-process (program &rest args)
342 "Same as `start-process', but doesn't bother about name and buffer."
343 (let ((process-name (concat program "_process"))
344 (buffer-name (generate-new-buffer-name
345 (concat program "_output"))))
346 (apply #'start-process
347 process-name buffer-name program args)))
348
349 (defun b/dired-start-process (program &optional args)
350 "Open current file with a PROGRAM."
351 ;; Shell command looks like this: "program [ARGS]... FILE" (ARGS can
352 ;; be nil, so remove it).
353 (apply #'b/start-process
354 program
355 (remove nil (list args (dired-get-file-for-visit)))))
356
357 (defun b/add-elisp-section ()
358 (interactive)
359 (insert "\n")
360 (previous-line)
361 (insert "\n\f\n;;; "))
362
363 \f
364 ;;; Defaults
365
366 ;; time and battery in mode-line
367 (comment
368 (use-package time
369 :init
370 (setq display-time-default-load-average nil)
371 :config
372 (display-time-mode))
373
374 (use-package battery
375 :config
376 (display-battery-mode)))
377
378 ;; smaller fringe
379 ;; (fringe-mode '(3 . 1))
380 (fringe-mode nil)
381
382 ;; disable disabled commands
383 (setq disabled-command-function nil)
384
385 ;; Save what I copy into clipboard from other applications into Emacs'
386 ;; kill-ring, which would allow me to still be able to easily access
387 ;; it in case I kill (cut or copy) something else inside Emacs before
388 ;; yanking (pasting) what I'd originally intended to.
389 (setq save-interprogram-paste-before-kill t)
390
391 ;; minibuffer
392 (setq enable-recursive-minibuffers t
393 resize-mini-windows t)
394
395 ;; lazy-person-friendly yes/no prompts
396 (defalias 'yes-or-no-p #'y-or-n-p)
397
398 ;; i want *scratch* as my startup buffer
399 (setq initial-buffer-choice t)
400
401 ;; i don't need the default hint
402 (setq initial-scratch-message nil)
403
404 ;; use customizable text-mode as major mode for *scratch*
405 (setq initial-major-mode 'text-mode)
406
407 ;; inhibit buffer list when more than 2 files are loaded
408 (setq inhibit-startup-buffer-menu t)
409
410 ;; don't need to see the startup screen or the echo area message
411 (advice-add #'display-startup-echo-area-message :override #'ignore)
412 (setq inhibit-startup-screen t
413 inhibit-startup-echo-area-message user-login-name)
414
415 ;; more useful frame titles
416 (setq frame-title-format
417 '("" invocation-name " - "
418 (:eval (if (buffer-file-name)
419 (abbreviate-file-name (buffer-file-name))
420 "%b"))))
421
422 ;; backups (C-h v make-backup-files RET)
423 (setq backup-by-copying t
424 backup-directory-alist (list (cons "." (b/var "backup/")))
425 version-control t
426 delete-old-versions t)
427
428 ;; enable automatic reloading of changed buffers and files
429 (global-auto-revert-mode 1)
430 (setq auto-revert-verbose nil
431 global-auto-revert-non-file-buffers nil)
432
433 ;; always use space for indentation
434 (setq-default
435 indent-tabs-mode nil
436 require-final-newline t
437 tab-width 4)
438
439 ;; enable winner-mode (C-h f winner-mode RET)
440 (winner-mode 1)
441
442 ;; don't display *compilation* buffer on success. based on
443 ;; https://stackoverflow.com/a/17788551, with changes to use `cl-letf'
444 ;; instead of the now obsolete `flet'.
445 (with-eval-after-load 'compile
446 (defun b/compilation-finish-function (buffer outstr)
447 (unless (string-match "finished" outstr)
448 (switch-to-buffer-other-window buffer))
449 t)
450
451 (setq compilation-finish-functions #'b/compilation-finish-function)
452
453 (require 'cl-macs)
454
455 (defadvice compilation-start
456 (around inhibit-display
457 (command &optional mode name-function highlight-regexp))
458 (if (not (string-match "^\\(find\\|grep\\)" command))
459 (cl-letf (((symbol-function 'display-buffer) #'ignore))
460 (save-window-excursion ad-do-it))
461 ad-do-it))
462 (ad-activate 'compilation-start))
463
464 ;; search for non-ASCII characters: i’d like non-ASCII characters such
465 ;; as ‘’“”«»‹›áⓐ𝒶 to be selected when i search for their ASCII
466 ;; counterpart. shoutout to
467 ;; http://endlessparentheses.com/new-in-emacs-25-1-easily-search-non-ascii-characters.html
468 (setq search-default-mode #'char-fold-to-regexp)
469 ;; uncomment to extend this behaviour to query-replace
470 ;; (setq replace-char-fold t)
471
472 ;; cursor shape
473 (setq-default cursor-type 'bar)
474
475 ;; allow scrolling in Isearch
476 (setq isearch-allow-scroll t)
477
478 ;; open read-only file buffers in view-mode
479 ;; (enables niceties like `q' for quit)
480 (setq view-read-only t)
481
482 (use-feature vc
483 :bind ("C-x v C-=" . vc-ediff))
484
485 (use-feature ediff
486 :config (add-hook 'ediff-after-quit-hook-internal 'winner-undo)
487 :custom ((ediff-window-setup-function 'ediff-setup-windows-plain)
488 (ediff-split-window-function 'split-window-horizontally)))
489
490 ;; i don't feel like jumping out of my chair every now and again; so
491 ;; don't BEEP! at me, emacs
492 (setq ring-bell-function 'ignore)
493
494 \f
495 ;;; General bindings
496
497 (bind-keys
498 ("C-c a i" . ielm)
499
500 ("C-c e b" . eval-buffer)
501 ("C-c e e" . eval-last-sexp)
502 ("C-c e r" . eval-region)
503
504 ("C-c e i" . emacs-init-time)
505 ("C-c e u" . emacs-uptime)
506 ("C-c e v" . emacs-version)
507
508 ("C-c F m" . make-frame-command)
509 ("C-c F d" . delete-frame)
510 ("C-c F D" . server-edit)
511
512 ("C-S-h C" . describe-char)
513 ("C-S-h F" . describe-face)
514
515 ("C-x k" . kill-this-buffer)
516 ("C-x K" . kill-buffer)
517 ("C-x s" . save-buffer)
518 ("C-x S" . save-some-buffers)
519
520 :map emacs-lisp-mode-map
521 ("<C-return>" . b/add-elisp-section))
522
523 (when (display-graphic-p)
524 (unbind-key "C-z" global-map))
525
526 (bind-keys
527 ;; for back and forward mouse keys
528 ("<mouse-8>" . previous-buffer)
529 ("<drag-mouse-8>" . previous-buffer)
530 ("<mouse-9>" . next-buffer)
531 ("<drag-mouse-9>" . next-buffer)
532 ("<drag-mouse-2>" . kill-this-buffer)
533 ("<drag-mouse-3>" . ivy-switch-buffer))
534
535 (bind-keys
536 :prefix-map mab/straight-prefix-map
537 :prefix "C-c p s"
538 ("u" . straight-use-package)
539 ("f" . straight-freeze-versions)
540 ("t" . straight-thaw-versions)
541 ("P" . straight-prune-build)
542 ("g" . straight-get-recipe)
543 ("r" . mab/reload-init)
544 ;; M-x ^straight-.*-all$
545 ("a c" . straight-check-all)
546 ("a f" . straight-fetch-all)
547 ("a m" . straight-merge-all)
548 ("a n" . straight-normalize-all)
549 ("a F" . straight-pull-all)
550 ("a P" . straight-push-all)
551 ("a r" . straight-rebuild-all)
552 ;; M-x ^straight-.*-package$
553 ("p c" . straight-check-package)
554 ("p f" . straight-fetch-package)
555 ("p m" . straight-merge-package)
556 ("p n" . straight-normalize-package)
557 ("p F" . straight-pull-package)
558 ("p P" . straight-push-package)
559 ("p r" . straight-rebuild-package))
560
561 \f
562 ;;; Essential packages
563
564 ;; use the org-plus-contrib package to get the whole deal
565 (use-package org-plus-contrib)
566
567 (use-feature org
568 :defer 0.5
569 :config
570 (setq org-src-tab-acts-natively t
571 org-src-preserve-indentation nil
572 org-edit-src-content-indentation 0
573 org-link-email-description-format "Email %c: %s" ; %.30s
574 org-highlight-latex-and-related '(entities)
575 org-use-speed-commands t
576 org-startup-folded 'content
577 org-catch-invisible-edits 'show-and-error
578 org-log-done 'time)
579 (when (version< org-version "9.3")
580 (setq org-email-link-description-format
581 org-link-email-description-format))
582 (add-to-list 'org-structure-template-alist '("L" . "src emacs-lisp") t)
583 (add-to-list 'org-modules 'org-habit)
584 :bind
585 (("C-c a o a" . org-agenda)
586 :map org-mode-map
587 ("M-L" . org-insert-last-stored-link)
588 ("M-O" . org-toggle-link-display))
589 :hook ((org-mode . org-indent-mode)
590 (org-mode . auto-fill-mode)
591 (org-mode . flyspell-mode))
592 :custom
593 (org-pretty-entities t)
594 (org-agenda-files '("~/usr/org/todos/personal.org"
595 "~/usr/org/todos/habits.org"
596 "~/src/git/masters-thesis/todo.org"))
597 (org-agenda-start-on-weekday 0)
598 (org-agenda-time-leading-zero t)
599 (org-habit-graph-column 44)
600 (org-latex-packages-alist '(("" "listings") ("" "color")))
601 :custom-face
602 '(org-block-begin-line ((t (:foreground "#5a5b5a" :background "#1d1f21"))))
603 '(org-block ((t (:background "#1d1f21"))))
604 '(org-latex-and-related ((t (:foreground "#b294bb")))))
605
606 (use-feature ox-latex
607 :after ox
608 :config
609 (setq org-latex-listings 'listings
610 ;; org-latex-prefer-user-labels t
611 )
612 (add-to-list 'org-latex-classes
613 '("IEEEtran" "\\documentclass[11pt]{IEEEtran}"
614 ("\\section{%s}" . "\\section*{%s}")
615 ("\\subsection{%s}" . "\\subsection*{%s}")
616 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
617 ("\\paragraph{%s}" . "\\paragraph*{%s}")
618 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
619 t)
620 (require 'ox-beamer))
621
622 (use-feature ox-extra
623 :config
624 (ox-extras-activate '(latex-header-blocks ignore-headlines)))
625
626 ;; asynchronous tangle, using emacs-async to asynchronously tangle an
627 ;; org file. closely inspired by
628 ;; https://github.com/dieggsy/dotfiles/tree/cc10edf7701958eff1cd94d4081da544d882a28c/emacs.d#dotfiles
629 (with-eval-after-load 'org
630 (defvar b/show-async-tangle-results nil
631 "Keep *emacs* async buffers around for later inspection.")
632
633 (defvar b/show-async-tangle-time nil
634 "Show the time spent tangling the file.")
635
636 (defun b/async-babel-tangle ()
637 "Tangle org file asynchronously."
638 (interactive)
639 (let* ((file-tangle-start-time (current-time))
640 (file (buffer-file-name))
641 (file-nodir (file-name-nondirectory file))
642 ;; (async-quiet-switch "-q")
643 (file-noext (file-name-sans-extension file)))
644 (async-start
645 `(lambda ()
646 (require 'org)
647 (org-babel-tangle-file ,file))
648 (unless b/show-async-tangle-results
649 `(lambda (result)
650 (if result
651 (message "Tangled %s%s"
652 ,file-nodir
653 (if b/show-async-tangle-time
654 (format " (%.3fs)"
655 (float-time (time-subtract (current-time)
656 ',file-tangle-start-time)))
657 ""))
658 (message "Tangling %s failed" ,file-nodir))))))))
659
660 (add-to-list
661 'safe-local-variable-values
662 '(eval add-hook 'after-save-hook #'b/async-babel-tangle 'append 'local))
663
664 ;; *the* right way to do git
665 (use-package magit
666 :defer 0.5
667 :bind (("C-x g" . magit-status)
668 ("C-c g g" . magit-status)
669 ("C-c g b" . magit-blame-addition)
670 ("C-c g l" . magit-log-buffer-file))
671 :config
672 (magit-add-section-hook 'magit-status-sections-hook
673 'magit-insert-modules
674 'magit-insert-stashes
675 'append)
676 ;; (magit-add-section-hook 'magit-status-sections-hook
677 ;; 'magit-insert-ignored-files
678 ;; 'magit-insert-untracked-files
679 ;; 'append)
680 (setq magit-repository-directories '(("~/" . 0)
681 ("~/src/git/" . 1)))
682 (nconc magit-section-initial-visibility-alist
683 '(([unpulled status] . show)
684 ([unpushed status] . show)))
685 (setq transient-history-file (b/var "transient/history.el")
686 transient-levels-file (b/etc "transient/levels.el")
687 transient-values-file (b/etc "transient/values.el"))
688 :custom (magit-display-buffer-function #'magit-display-buffer-fullframe-status-v1)
689 :custom-face (magit-diff-file-heading ((t (:weight normal)))))
690
691 ;; recently opened files
692 (use-feature recentf
693 :defer 0.2
694 ;; :config
695 ;; (add-to-list 'recentf-exclude "^/\\(?:ssh\\|su\\|sudo\\)?:")
696 :custom
697 (recentf-max-saved-items 2000)
698 (recentf-save-file (b/var "recentf-save.el")))
699
700 ;; smart M-x enhancement (needed by counsel for history)
701 (use-package smex
702 :config
703 (setq smex-save-file (b/var "smex-save.el")))
704
705 (use-package ivy
706 :defer 0.3
707 :delight ;; " 🙒"
708 :bind
709 (:map ivy-minibuffer-map
710 ([escape] . keyboard-escape-quit)
711 ([S-up] . ivy-previous-history-element)
712 ([S-down] . ivy-next-history-element)
713 ("DEL" . ivy-backward-delete-char))
714 :config
715 (setq ivy-wrap t
716 ivy-height 14
717 ivy-use-virtual-buffers t
718 ivy-virtual-abbreviate 'abbreviate
719 ivy-count-format "%d/%d ")
720
721 (defvar b/ivy-ignore-buffer-modes '(magit-mode erc-mode dired-mode))
722 (defun b/ivy-ignore-buffer-p (str)
723 "Return non-nil if str names a buffer with a major mode
724 derived from one of `b/ivy-ignore-buffer-modes'.
725
726 This function is intended for use with `ivy-ignore-buffers'."
727 (let* ((buf (get-buffer str))
728 (mode (and buf (buffer-local-value 'major-mode buf))))
729 (and mode
730 (apply #'provided-mode-derived-p mode b/ivy-ignore-buffer-modes))))
731 (add-to-list 'ivy-ignore-buffers 'b/ivy-ignore-buffer-p)
732
733 (ivy-mode 1)
734 ;; :custom-face
735 ;; (ivy-minibuffer-match-face-2 ((t (:background "#e99ce8" :weight semi-bold))))
736 ;; (ivy-minibuffer-match-face-3 ((t (:background "#bbbbff" :weight semi-bold))))
737 ;; (ivy-minibuffer-match-face-4 ((t (:background "#ffbbff" :weight semi-bold))))
738 )
739
740 (use-package swiper
741 :after ivy
742 :bind (("C-s" . swiper-isearch)
743 ("C-r" . swiper)
744 ("C-S-s" . isearch-forward)))
745
746 (use-package counsel
747 :after ivy
748 :delight
749 :bind (([remap execute-extended-command] . counsel-M-x)
750 ([remap find-file] . counsel-find-file)
751 ("C-c b b" . ivy-switch-buffer)
752 ("C-c f ." . counsel-find-file)
753 ("C-c f l" . counsel-find-library)
754 ("C-c f r" . counsel-recentf)
755 ("C-c x" . counsel-M-x)
756 :map minibuffer-local-map
757 ("C-r" . counsel-minibuffer-history))
758 :config
759 (counsel-mode 1)
760 (defalias 'locate #'counsel-locate))
761
762 (comment
763 (use-package helm
764 :commands (helm-M-x helm-mini helm-resume)
765 :bind (("M-x" . helm-M-x)
766 ("M-y" . helm-show-kill-ring)
767 ("C-x b" . helm-mini)
768 ("C-x C-b" . helm-buffers-list)
769 ("C-x C-f" . helm-find-files)
770 ("C-h r" . helm-info-emacs)
771 ("C-s-r" . helm-resume)
772 :map helm-map
773 ("<tab>" . helm-execute-persistent-action)
774 ("C-i" . helm-execute-persistent-action) ; Make TAB work in terminals
775 ("C-z" . helm-select-action)) ; List actions
776 :config (helm-mode 1)))
777
778 (use-feature eshell
779 :defer 0.5
780 :commands eshell
781 :bind ("C-c a s e" . eshell)
782 :config
783 (eval-when-compile (defvar eshell-prompt-regexp))
784 (defun b/eshell-quit-or-delete-char (arg)
785 (interactive "p")
786 (if (and (eolp) (looking-back eshell-prompt-regexp nil))
787 (eshell-life-is-too-much)
788 (delete-char arg)))
789
790 (defun b/eshell-clear ()
791 (interactive)
792 (let ((inhibit-read-only t))
793 (erase-buffer))
794 (eshell-send-input))
795
796 (defun b/eshell-setup ()
797 (make-local-variable 'company-idle-delay)
798 (defvar company-idle-delay)
799 (setq company-idle-delay nil)
800 (bind-keys :map eshell-mode-map
801 ("C-d" . b/eshell-quit-or-delete-char)
802 ("C-S-l" . b/eshell-clear)
803 ("M-r" . counsel-esh-history)
804 ([tab] . company-complete)))
805
806 :hook (eshell-mode . b/eshell-setup)
807 :custom
808 (eshell-directory-name (b/var "eshell/"))
809 (eshell-hist-ignoredups t)
810 (eshell-input-filter 'eshell-input-filter-initial-space))
811
812 (use-feature ibuffer
813 :bind
814 (("C-x C-b" . ibuffer)
815 :map ibuffer-mode-map
816 ("P" . ibuffer-backward-filter-group)
817 ("N" . ibuffer-forward-filter-group)
818 ("M-p" . ibuffer-do-print)
819 ("M-n" . ibuffer-do-shell-command-pipe-replace))
820 :config
821 ;; Use human readable Size column instead of original one
822 (define-ibuffer-column size-h
823 (:name "Size" :inline t)
824 (cond
825 ((> (buffer-size) 1000000) (format "%7.1fM" (/ (buffer-size) 1000000.0)))
826 ((> (buffer-size) 100000) (format "%7.0fk" (/ (buffer-size) 1000.0)))
827 ((> (buffer-size) 1000) (format "%7.1fk" (/ (buffer-size) 1000.0)))
828 (t (format "%8d" (buffer-size)))))
829 :custom
830 (ibuffer-saved-filter-groups
831 '(("default"
832 ("dired" (mode . dired-mode))
833 ("org" (mode . org-mode))
834 ("gnus"
835 (or
836 (mode . gnus-group-mode)
837 (mode . gnus-summary-mode)
838 (mode . gnus-article-mode)
839 ;; not really, but...
840 (mode . message-mode)))
841 ("web"
842 (or
843 (mode . web-mode)
844 (mode . css-mode)
845 (mode . scss-mode)
846 (mode . js2-mode)))
847 ("shell"
848 (or
849 (mode . eshell-mode)
850 (mode . shell-mode)
851 (mode . term-mode)))
852 ("programming"
853 (or
854 (mode . python-mode)
855 (mode . c-mode)
856 (mode . c++-mode)
857 (mode . java-mode)
858 (mode . emacs-lisp-mode)
859 (mode . scheme-mode)
860 (mode . haskell-mode)
861 (mode . lean-mode)
862 (mode . go-mode)
863 (mode . alloy-mode)))
864 ("tex"
865 (or
866 (mode . bibtex-mode)
867 (mode . latex-mode)))
868 ("emacs"
869 (or
870 (name . "^\\*scratch\\*$")
871 (name . "^\\*Messages\\*$")))
872 ("erc" (mode . erc-mode)))))
873 (ibuffer-formats
874 '((mark modified read-only locked " "
875 (name 18 18 :left :elide)
876 " "
877 (size-h 9 -1 :right)
878 " "
879 (mode 16 16 :left :elide)
880 " " filename-and-process)
881 (mark " "
882 (name 16 -1)
883 " " filename)))
884 :hook (ibuffer . (lambda () (ibuffer-switch-to-saved-filter-groups "default"))))
885
886 (use-feature outline
887 :disabled
888 :hook (prog-mode . outline-minor-mode)
889 :delight (outline-minor-mode " outl")
890 :bind
891 (:map
892 outline-minor-mode-map
893 ("<s-tab>" . outline-toggle-children)
894 ("M-p" . outline-previous-visible-heading)
895 ("M-n" . outline-next-visible-heading)
896 :prefix-map b/outline-prefix-map
897 :prefix "s-O"
898 ("TAB" . outline-toggle-children)
899 ("a" . outline-hide-body)
900 ("H" . outline-hide-body)
901 ("S" . outline-show-all)
902 ("h" . outline-hide-subtree)
903 ("s" . outline-show-subtree)))
904
905 (use-feature ls-lisp
906 :custom (ls-lisp-dirs-first t))
907
908 (use-feature dired
909 :config
910 (setq dired-listing-switches "-alh"
911 ls-lisp-use-insert-directory-program nil)
912
913 ;; easily diff 2 marked files
914 ;; https://oremacs.com/2017/03/18/dired-ediff/
915 (defun dired-ediff-files ()
916 (interactive)
917 (require 'dired-aux)
918 (defvar ediff-after-quit-hook-internal)
919 (let ((files (dired-get-marked-files))
920 (wnd (current-window-configuration)))
921 (if (<= (length files) 2)
922 (let ((file1 (car files))
923 (file2 (if (cdr files)
924 (cadr files)
925 (read-file-name
926 "file: "
927 (dired-dwim-target-directory)))))
928 (if (file-newer-than-file-p file1 file2)
929 (ediff-files file2 file1)
930 (ediff-files file1 file2))
931 (add-hook 'ediff-after-quit-hook-internal
932 (lambda ()
933 (setq ediff-after-quit-hook-internal nil)
934 (set-window-configuration wnd))))
935 (error "no more than 2 files should be marked"))))
936
937 (require 'dired-x)
938 (setq dired-guess-shell-alist-user
939 '(("\\.pdf\\'" "evince" "zathura" "okular")
940 ("\\.doc\\'" "libreoffice")
941 ("\\.docx\\'" "libreoffice")
942 ("\\.ppt\\'" "libreoffice")
943 ("\\.pptx\\'" "libreoffice")
944 ("\\.xls\\'" "libreoffice")
945 ("\\.xlsx\\'" "libreoffice")
946 ("\\.flac\\'" "mpv")))
947 :bind (:map dired-mode-map
948 ("b" . dired-up-directory)
949 ("e" . dired-ediff-files)
950 ("E" . dired-toggle-read-only)
951 ("\\" . dired-hide-details-mode)
952 ("z" . (lambda ()
953 (interactive)
954 (b/dired-start-process "zathura"))))
955 :hook (dired-mode . dired-hide-details-mode))
956
957 (use-feature help
958 :config
959 (temp-buffer-resize-mode)
960 (setq help-window-select t))
961
962 (use-feature tramp
963 :config
964 (add-to-list 'tramp-default-proxies-alist '(nil "\\`root\\'" "/ssh:%h:"))
965 (add-to-list 'tramp-default-proxies-alist '("localhost" nil nil))
966 (add-to-list 'tramp-default-proxies-alist
967 (list (regexp-quote (system-name)) nil nil)))
968
969 (use-package dash
970 :config (dash-enable-font-lock))
971
972 (use-feature doc-view
973 :bind (:map doc-view-mode-map
974 ("M-RET" . image-previous-line)))
975
976 \f
977 ;;; Editing
978
979 ;; highlight uncommitted changes in the left fringe
980 (use-package diff-hl
981 :defer 0.6
982 :config
983 (setq diff-hl-draw-borders nil)
984 (global-diff-hl-mode)
985 :hook (magit-post-refresh . diff-hl-magit-post-refresh))
986
987 ;; display Lisp objects at point in the echo area
988 (use-feature eldoc
989 :when (version< "25" emacs-version)
990 :delight " eldoc"
991 :config (global-eldoc-mode))
992
993 ;; highlight matching parens
994 (use-feature paren
995 :demand
996 :config (show-paren-mode))
997
998 (use-feature elec-pair
999 :demand
1000 :config (electric-pair-mode))
1001
1002 (use-feature simple
1003 :delight (auto-fill-function " fill")
1004 :config (column-number-mode))
1005
1006 ;; save minibuffer history
1007 (use-feature savehist
1008 :config
1009 (savehist-mode)
1010 :custom
1011 (savehist-file (b/var "savehist.el")))
1012
1013 ;; automatically save place in files
1014 (use-feature saveplace
1015 :when (version< "25" emacs-version)
1016 :config (save-place-mode)
1017 :custom
1018 (save-place-file (b/var "save-place.el")))
1019
1020 (use-feature prog-mode
1021 :config (global-prettify-symbols-mode)
1022 (defun indicate-buffer-boundaries-left ()
1023 (setq indicate-buffer-boundaries 'left))
1024 (add-hook 'prog-mode-hook #'indicate-buffer-boundaries-left))
1025
1026 (use-feature text-mode
1027 :hook (text-mode . indicate-buffer-boundaries-left))
1028
1029 (use-feature conf-mode
1030 :mode "\\.*rc$")
1031
1032 (use-feature sh-mode
1033 :mode "\\.bashrc$")
1034
1035 (use-package company
1036 :defer 0.6
1037 :delight " comp"
1038 :bind
1039 (:map company-active-map
1040 ([tab] . company-complete-common-or-cycle)
1041 ([escape] . company-abort))
1042 :custom
1043 (company-minimum-prefix-length 1)
1044 (company-selection-wrap-around t)
1045 (company-dabbrev-char-regexp "\\sw\\|\\s_\\|[-_]")
1046 (company-dabbrev-downcase nil)
1047 (company-dabbrev-ignore-case nil)
1048 :config
1049 (global-company-mode t))
1050
1051 (use-package flycheck
1052 :defer 0.6
1053 :hook (prog-mode . flycheck-mode)
1054 :bind
1055 (:map flycheck-mode-map
1056 ("M-P" . flycheck-previous-error)
1057 ("M-N" . flycheck-next-error))
1058 :config
1059 ;; Use the load-path from running Emacs when checking elisp files
1060 (setq flycheck-emacs-lisp-load-path 'inherit)
1061
1062 ;; Only flycheck when I actually save the buffer
1063 (setq flycheck-check-syntax-automatically '(mode-enabled save))
1064 :custom (flycheck-mode-line-prefix "flyc"))
1065
1066 (use-feature flyspell
1067 :delight " flysp")
1068
1069 ;; http://endlessparentheses.com/ispell-and-apostrophes.html
1070 (use-feature ispell
1071 :defer 0.6
1072 :config
1073 ;; ’ can be part of a word
1074 (setq ispell-local-dictionary-alist
1075 `((nil "[[:alpha:]]" "[^[:alpha:]]"
1076 "['\x2019]" nil ("-B") nil utf-8))
1077 ispell-program-name (executable-find "hunspell"))
1078 ;; don't send ’ to the subprocess
1079 (defun endless/replace-apostrophe (args)
1080 (cons (replace-regexp-in-string
1081 "’" "'" (car args))
1082 (cdr args)))
1083 (advice-add #'ispell-send-string :filter-args
1084 #'endless/replace-apostrophe)
1085
1086 ;; convert ' back to ’ from the subprocess
1087 (defun endless/replace-quote (args)
1088 (if (not (derived-mode-p 'org-mode))
1089 args
1090 (cons (replace-regexp-in-string
1091 "'" "’" (car args))
1092 (cdr args))))
1093 (advice-add #'ispell-parse-output :filter-args
1094 #'endless/replace-quote))
1095
1096 (use-feature abbrev
1097 :delight " abbr"
1098 :hook (text-mode . abbrev-mode)
1099 :custom
1100 (abbrev-file-name (b/var "abbrev.el")))
1101
1102 \f
1103 ;;; Programming modes
1104
1105 (use-feature lisp-mode
1106 :config
1107 (defun indent-spaces-mode ()
1108 (setq indent-tabs-mode nil))
1109 (add-hook 'lisp-interaction-mode-hook #'indent-spaces-mode))
1110
1111 (use-feature reveal
1112 :delight (reveal-mode " reveal")
1113 :hook (emacs-lisp-mode . reveal-mode))
1114
1115 (use-feature elisp-mode
1116 :delight (emacs-lisp-mode "Elisp" :major))
1117
1118
1119 (use-package alloy-mode
1120 :straight (:host github :repo "dwwmmn/alloy-mode")
1121 :mode "\\.als\\'"
1122 :config (setq alloy-basic-offset 2))
1123
1124 (eval-when-compile (defvar lean-mode-map))
1125 (use-package lean-mode
1126 :straight (:host github :repo "leanprover/lean-mode"
1127 :fork (:repo "notbandali/lean-mode" :branch "remove-cl"))
1128 :defer 0.4
1129 :bind (:map lean-mode-map
1130 ("S-SPC" . company-complete))
1131 :config
1132 (require 'lean-input)
1133 (setq default-input-method "Lean"
1134 lean-input-tweak-all '(lean-input-compose
1135 (lean-input-prepend "/")
1136 (lean-input-nonempty))
1137 lean-input-user-translations '(("/" "/")))
1138 (lean-input-setup))
1139
1140 (comment
1141 (use-package proof-site ; for Coq
1142 :straight proof-general)
1143
1144 (use-package haskell-mode
1145 :config
1146 (setq haskell-indentation-layout-offset 4
1147 haskell-indentation-left-offset 4
1148 flycheck-checker 'haskell-hlint
1149 flycheck-disabled-checkers '(haskell-stack-ghc haskell-ghc)))
1150
1151 (use-package dante
1152 :after haskell-mode
1153 :commands dante-mode
1154 :hook (haskell-mode . dante-mode))
1155
1156 (use-package hlint-refactor
1157 :after haskell-mode
1158 :bind (:map hlint-refactor-mode-map
1159 ("C-c l b" . hlint-refactor-refactor-buffer)
1160 ("C-c l r" . hlint-refactor-refactor-at-point))
1161 :hook (haskell-mode . hlint-refactor-mode))
1162
1163 (use-package flycheck-haskell
1164 :after haskell-mode)
1165 ;; alternative: hs-lint https://github.com/ndmitchell/hlint/blob/20e116a043f2073c57b17b24ae6364b5e433ba7e/data/hs-lint.el
1166 )
1167
1168 (use-feature sgml-mode
1169 :config
1170 (setq sgml-basic-offset 2))
1171
1172 (use-feature css-mode
1173 :config
1174 (setq css-indent-offset 2))
1175
1176 (use-package web-mode
1177 :mode "\\.html\\'"
1178 :config
1179 (b/setq-every 2
1180 web-mode-code-indent-offset
1181 web-mode-css-indent-offset
1182 web-mode-markup-indent-offset))
1183
1184 (use-package emmet-mode
1185 :after (:any web-mode css-mode sgml-mode)
1186 :bind* (("C-)" . emmet-next-edit-point)
1187 ("C-(" . emmet-prev-edit-point))
1188 :config
1189 (unbind-key "C-j" emmet-mode-keymap)
1190 (setq emmet-move-cursor-between-quotes t)
1191 :hook (web-mode css-mode html-mode sgml-mode))
1192
1193 (comment
1194 (use-package meghanada
1195 :bind
1196 (:map meghanada-mode-map
1197 (("C-M-o" . meghanada-optimize-import)
1198 ("C-M-t" . meghanada-import-all)))
1199 :hook (java-mode . meghanada-mode)))
1200
1201 (comment
1202 (use-package treemacs
1203 :config (setq treemacs-never-persist t))
1204
1205 (use-package yasnippet
1206 :config
1207 ;; (yas-global-mode)
1208 )
1209
1210 (use-package lsp-mode
1211 :init (setq lsp-eldoc-render-all nil
1212 lsp-highlight-symbol-at-point nil)
1213 )
1214
1215 (use-package hydra)
1216
1217 (use-package company-lsp
1218 :after company
1219 :config
1220 (setq company-lsp-cache-candidates t
1221 company-lsp-async t))
1222
1223 (use-package lsp-ui
1224 :config
1225 (setq lsp-ui-sideline-update-mode 'point))
1226
1227 (use-package lsp-java
1228 :config
1229 (add-hook 'java-mode-hook
1230 (lambda ()
1231 (setq-local company-backends (list 'company-lsp))))
1232
1233 (add-hook 'java-mode-hook 'lsp-java-enable)
1234 (add-hook 'java-mode-hook 'flycheck-mode)
1235 (add-hook 'java-mode-hook 'company-mode)
1236 (add-hook 'java-mode-hook 'lsp-ui-mode))
1237
1238 (use-package dap-mode
1239 :after lsp-mode
1240 :config
1241 (dap-mode t)
1242 (dap-ui-mode t))
1243
1244 (use-package dap-java
1245 :after (lsp-java))
1246
1247 (use-package lsp-java-treemacs
1248 :after (treemacs)))
1249
1250 (comment
1251 (use-package eclim
1252 :bind (:map eclim-mode-map ("S-SPC" . company-complete))
1253 :hook ((java-mode . eclim-mode)
1254 (eclim-mode . (lambda ()
1255 (make-local-variable 'company-idle-delay)
1256 (defvar company-idle-delay)
1257 ;; (setq company-idle-delay 0.7)
1258 (setq company-idle-delay nil))))
1259 :custom
1260 (eclim-auto-save nil)
1261 ;; (eclimd-default-workspace "~/src/eclipse-workspace-exp")
1262 (eclim-executable "~/.p2/pool/plugins/org.eclim_2.8.0/bin/eclim")
1263 (eclim-eclipse-dirs '("~/usr/eclipse/dsl-2018-09/eclipse"))))
1264
1265 (use-package geiser
1266 :config
1267 (make-directory (b/var "geiser/") t)
1268 (setq geiser-repl-history-filename (b/var "geiser/repl-history")))
1269
1270 (use-feature geiser-guile
1271 :config
1272 (setq geiser-guile-load-path "~/src/git/guix"))
1273
1274 (use-package guix)
1275
1276 (comment
1277 (use-package auctex
1278 :custom
1279 (font-latex-fontify-sectioning 'color)))
1280
1281 (use-package go-mode)
1282
1283 (use-package po-mode
1284 :hook
1285 (po-mode . (lambda () (run-with-timer 0.1 nil 'View-exit))))
1286
1287 (use-feature tex-mode
1288 :config
1289 (cl-delete-if
1290 (lambda (p) (string-match "^---?" (car p)))
1291 tex--prettify-symbols-alist)
1292 :hook ((tex-mode . auto-fill-mode)
1293 (tex-mode . flyspell-mode)
1294 (tex-mode . (lambda () (electric-indent-local-mode -1)))))
1295
1296 \f
1297 ;;; Theme
1298
1299 (add-to-list 'custom-theme-load-path
1300 (expand-file-name
1301 (convert-standard-filename "lisp") user-emacs-directory))
1302 (load-theme 'tangomod t)
1303
1304 (use-package smart-mode-line
1305 :commands (sml/apply-theme)
1306 :demand
1307 :config
1308 (sml/setup)
1309 (smart-mode-line-enable))
1310
1311 (use-package doom-themes)
1312
1313 (defvar b/org-mode-font-lock-keywords
1314 '(("[ \t]*\\(#\\+\\(BEGIN\\|END\\|begin\\|end\\)_\\(\\S-+\\)\\)[ \t]*\\([^\n:]*\\)"
1315 (1 '(:foreground "#5a5b5a" :background "#292b2b") t) ; directive
1316 (3 '(:foreground "#81a2be" :background "#292b2b") t) ; kind
1317 (4 '(:foreground "#c5c8c6") t)))) ; title
1318
1319 (defun b/lights-on ()
1320 "Enable my favourite light theme."
1321 (interactive)
1322 (mapc #'disable-theme custom-enabled-themes)
1323 (load-theme 'tangomod t)
1324 (sml/apply-theme 'automatic)
1325 (font-lock-remove-keywords
1326 'org-mode b/org-mode-font-lock-keywords))
1327
1328 (defun b/lights-off ()
1329 "Go dark."
1330 (interactive)
1331 (mapc #'disable-theme custom-enabled-themes)
1332 ;; (load-theme 'doom-tomorrow-night t)
1333 (sml/apply-theme 'automatic)
1334 (font-lock-add-keywords
1335 'org-mode b/org-mode-font-lock-keywords t))
1336
1337 (bind-keys
1338 ("C-c t d" . b/lights-off)
1339 ("C-c t l" . b/lights-on))
1340
1341 \f
1342 ;;; Emacs enhancements & auxiliary packages
1343
1344 (use-package man
1345 :config (setq Man-width 80))
1346
1347 (use-package which-key
1348 :defer 0.4
1349 :delight
1350 :config
1351 (which-key-add-key-based-replacements
1352 ;; prefixes for global prefixes and minor modes
1353 "C-c @" "outline"
1354 "C-c !" "flycheck"
1355 "C-c 8" "typo"
1356 "C-c 8 -" "typo/dashes"
1357 "C-c 8 <" "typo/left-brackets"
1358 "C-c 8 >" "typo/right-brackets"
1359 "C-x 8" "unicode"
1360 "C-x a" "abbrev/expand"
1361 "C-x r" "rectangle/register/bookmark"
1362 "C-x v" "version control"
1363 ;; prefixes for my personal bindings
1364 "C-c a" "applications"
1365 "C-c a e" "erc"
1366 "C-c a o" "org"
1367 "C-c a s" "shells"
1368 "C-c b" "buffers"
1369 "C-c c" "compile-and-comments"
1370 "C-c e" "eval"
1371 "C-c f" "files"
1372 "C-c F" "frames"
1373 "C-c g" "magit"
1374 "C-S-h" "help(ful)"
1375 "C-c m" "multiple-cursors"
1376 "C-c P" "projectile"
1377 "C-c P s" "projectile/search"
1378 "C-c P x" "projectile/execute"
1379 "C-c P 4" "projectile/other-window"
1380 "C-c q" "boxquote"
1381 "C-c t" "themes"
1382 ;; "s-O" "outline"
1383 )
1384
1385 ;; prefixes for major modes
1386 (which-key-add-major-mode-key-based-replacements 'message-mode
1387 "C-c f" "footnote")
1388 (which-key-add-major-mode-key-based-replacements 'org-mode
1389 "C-c C-v" "org-babel")
1390 (which-key-add-major-mode-key-based-replacements 'web-mode
1391 "C-c C-a" "web/attributes"
1392 "C-c C-b" "web/blocks"
1393 "C-c C-d" "web/dom"
1394 "C-c C-e" "web/element"
1395 "C-c C-t" "web/tags")
1396
1397 (which-key-mode)
1398 :custom
1399 (which-key-add-column-padding 5)
1400 (which-key-max-description-length 32))
1401
1402 (use-package crux ; results in Waiting for git... [2 times]
1403 :defer 0.4
1404 :bind (("C-c d" . crux-duplicate-current-line-or-region)
1405 ("C-c D" . crux-duplicate-and-comment-current-line-or-region)
1406 ("C-c f c" . crux-copy-file-preserve-attributes)
1407 ("C-c f d" . crux-delete-file-and-buffer)
1408 ("C-c f r" . crux-rename-file-and-buffer)
1409 ("C-c j" . crux-top-join-line)
1410 ("C-S-j" . crux-top-join-line)))
1411
1412 (use-package mwim
1413 :bind (("C-a" . mwim-beginning-of-code-or-line)
1414 ("C-e" . mwim-end-of-code-or-line)
1415 ("<home>" . mwim-beginning-of-line-or-code)
1416 ("<end>" . mwim-end-of-line-or-code)))
1417
1418 (use-package projectile
1419 :defer 0.5
1420 :bind-keymap ("C-c P" . projectile-command-map)
1421 :config
1422 (make-directory (b/var "projectile/") t)
1423 (projectile-mode)
1424
1425 (defun b/projectile-mode-line-fun ()
1426 "Report project name and type in the modeline."
1427 (let ((project-name (projectile-project-name))
1428 (project-type (projectile-project-type)))
1429 (format "%s%s"
1430 projectile-mode-line-prefix
1431 (if project-type
1432 (format ":%s" project-type)
1433 ""))))
1434 (setq projectile-mode-line-function 'b/projectile-mode-line-fun)
1435
1436 (defun my-projectile-invalidate-cache (&rest _args)
1437 ;; ignore the args to `magit-checkout'
1438 (projectile-invalidate-cache nil))
1439
1440 (eval-after-load 'magit-branch
1441 '(progn
1442 (advice-add 'magit-checkout
1443 :after #'my-projectile-invalidate-cache)
1444 (advice-add 'magit-branch-and-checkout
1445 :after #'my-projectile-invalidate-cache)))
1446 :custom
1447 (projectile-cache-file (b/var "projectile/cache.el"))
1448 (projectile-completion-system 'ivy)
1449 (projectile-known-projects-file (b/var "projectile/known-projects.el"))
1450 (projectile-mode-line-prefix " proj"))
1451
1452 (use-package helpful
1453 :defer 0.6
1454 :bind
1455 (("C-S-h c" . helpful-command)
1456 ("C-S-h f" . helpful-callable) ; helpful-function
1457 ("C-S-h v" . helpful-variable)
1458 ("C-S-h k" . helpful-key)
1459 ("C-S-h p" . helpful-at-point)))
1460
1461 (use-package unkillable-scratch
1462 :defer 0.6
1463 :config
1464 (unkillable-scratch 1)
1465 :custom
1466 (unkillable-buffers '("^\\*scratch\\*$" "^\\*Messages\\*$")))
1467
1468 ;; ,----
1469 ;; | make pretty boxed quotes like this
1470 ;; `----
1471 (use-package boxquote
1472 :defer 0.6
1473 :bind
1474 (:prefix-map b/boxquote-prefix-map
1475 :prefix "C-c q"
1476 ("b" . boxquote-buffer)
1477 ("B" . boxquote-insert-buffer)
1478 ("d" . boxquote-defun)
1479 ("F" . boxquote-insert-file)
1480 ("hf" . boxquote-describe-function)
1481 ("hk" . boxquote-describe-key)
1482 ("hv" . boxquote-describe-variable)
1483 ("hw" . boxquote-where-is)
1484 ("k" . boxquote-kill)
1485 ("p" . boxquote-paragraph)
1486 ("q" . boxquote-boxquote)
1487 ("r" . boxquote-region)
1488 ("s" . boxquote-shell-command)
1489 ("t" . boxquote-text)
1490 ("T" . boxquote-title)
1491 ("u" . boxquote-unbox)
1492 ("U" . boxquote-unbox-region)
1493 ("y" . boxquote-yank)
1494 ("M-q" . boxquote-fill-paragraph)
1495 ("M-w" . boxquote-kill-ring-save)))
1496
1497 (use-package orgalist
1498 ;; http://lists.gnu.org/archive/html/emacs-orgmode/2019-04/msg00007.html
1499 :disabled t
1500 :after message
1501 :hook (message-mode . orgalist-mode))
1502
1503 ;; easily type pretty quotes & other typography, like ‘’“”-–—«»‹›
1504 (use-package typo
1505 :defer 0.5
1506 :delight " typo"
1507 :config
1508 (typo-global-mode 1)
1509 :hook (((text-mode erc-mode) . typo-mode)
1510 (tex-mode . (lambda ()(typo-mode -1)))))
1511
1512 ;; highlight TODOs in buffers
1513 (use-package hl-todo
1514 :defer 0.5
1515 :config
1516 (global-hl-todo-mode))
1517
1518 (use-package shrink-path
1519 :defer 0.5
1520 :after eshell
1521 :config
1522 (defvar user-@-host (concat (user-login-name) "@" (system-name) " "))
1523 (defun +eshell/prompt ()
1524 (let ((base/dir (shrink-path-prompt default-directory)))
1525 (concat (propertize user-@-host 'face 'default)
1526 (propertize (car base/dir)
1527 'face 'font-lock-comment-face)
1528 (propertize (cdr base/dir)
1529 'face 'font-lock-constant-face)
1530 (propertize "> " 'face 'default))))
1531 (setq eshell-prompt-regexp (concat user-@-host ".*> ")
1532 eshell-prompt-function #'+eshell/prompt))
1533
1534 (use-package eshell-up
1535 :after eshell
1536 :commands eshell-up)
1537
1538 (use-package multi-term
1539 :defer 0.6
1540 :bind (("C-c a s m m" . multi-term)
1541 ("C-c a s m d" . multi-term-dedicated-toggle)
1542 ("C-c a s m p" . multi-term-prev)
1543 ("C-c a s m n" . multi-term-next)
1544 :map term-mode-map
1545 ("C-c C-j" . term-char-mode))
1546 :config
1547 (setq multi-term-program "screen"
1548 multi-term-program-switches (concat "-c"
1549 (getenv "XDG_CONFIG_HOME")
1550 "/screen/screenrc")
1551 ;; TODO: add separate bindings for connecting to existing
1552 ;; session vs. always creating a new one
1553 multi-term-dedicated-select-after-open-p t
1554 multi-term-dedicated-window-height 20
1555 multi-term-dedicated-max-window-height 30
1556 term-bind-key-alist
1557 '(("C-c C-c" . term-interrupt-subjob)
1558 ("C-c C-e" . term-send-esc)
1559 ("C-c C-j" . term-line-mode)
1560 ("C-k" . kill-line)
1561 ;; ("C-y" . term-paste)
1562 ("C-y" . term-send-raw)
1563 ("M-f" . term-send-forward-word)
1564 ("M-b" . term-send-backward-word)
1565 ("M-p" . term-send-up)
1566 ("M-n" . term-send-down)
1567 ("M-j" . term-send-raw-meta)
1568 ("M-y" . term-send-raw-meta)
1569 ("M-/" . term-send-raw-meta)
1570 ("M-0" . term-send-raw-meta)
1571 ("M-1" . term-send-raw-meta)
1572 ("M-2" . term-send-raw-meta)
1573 ("M-3" . term-send-raw-meta)
1574 ("M-4" . term-send-raw-meta)
1575 ("M-5" . term-send-raw-meta)
1576 ("M-6" . term-send-raw-meta)
1577 ("M-7" . term-send-raw-meta)
1578 ("M-8" . term-send-raw-meta)
1579 ("M-9" . term-send-raw-meta)
1580 ("<C-backspace>" . term-send-backward-kill-word)
1581 ("<M-DEL>" . term-send-backward-kill-word)
1582 ("M-d" . term-send-delete-word)
1583 ("M-," . term-send-raw)
1584 ("M-." . comint-dynamic-complete))
1585 term-unbind-key-alist
1586 '("C-z" "C-x" "C-c" "C-h"
1587 ;; "C-y"
1588 "<ESC>")))
1589
1590 (use-package page-break-lines
1591 :defer 0.5
1592 :delight " pgln"
1593 :custom
1594 (page-break-lines-max-width fill-column)
1595 :config
1596 (global-page-break-lines-mode))
1597
1598 (use-package expand-region
1599 :bind ("C-=" . er/expand-region))
1600
1601 (use-package multiple-cursors
1602 :bind
1603 (("C-S-<mouse-1>" . mc/add-cursor-on-click)
1604 (:prefix-map b/mc-prefix-map
1605 :prefix "C-c m"
1606 ("c" . mc/edit-lines)
1607 ("n" . mc/mark-next-like-this)
1608 ("p" . mc/mark-previous-like-this)
1609 ("a" . mc/mark-all-like-this)))
1610 :config
1611 (setq mc/list-file (b/var "mc-list.el")))
1612
1613 (comment
1614 ;; TODO
1615 (use-package forge
1616 :after magit
1617 :demand))
1618
1619 (use-package yasnippet
1620 :defer 0.6
1621 :config
1622 (defconst yas-verbosity-cur yas-verbosity)
1623 (setq yas-verbosity 2)
1624 (setq yas-snippet-dirs (list (b/etc "yasnippet/snippets/")))
1625 (add-to-list 'yas-snippet-dirs "~/src/git/guix/etc/snippets" t)
1626 (yas-reload-all)
1627 (setq yas-verbosity yas-verbosity-cur)
1628
1629 (defun b/yas--maybe-expand-key-filter (cmd)
1630 (when (and (yas--maybe-expand-key-filter cmd)
1631 (not (bound-and-true-p git-commit-mode)))
1632 cmd))
1633 (defconst b/yas-maybe-expand
1634 '(menu-item "" yas-expand :filter b/yas--maybe-expand-key-filter))
1635 (define-key yas-minor-mode-map
1636 (kbd "SPC") b/yas-maybe-expand)
1637
1638 (yas-global-mode))
1639
1640 (use-package debbugs
1641 :straight (debbugs
1642 :host github
1643 :repo "emacs-straight/debbugs"
1644 :files (:defaults "Debbugs.wsdl")))
1645
1646 (use-package org-ref
1647 :init
1648 (b/setq-every '("~/usr/org/references.bib")
1649 reftex-default-bibliography
1650 org-ref-default-bibliography)
1651 (setq
1652 org-ref-bibliography-notes "~/usr/org/notes.org"
1653 org-ref-pdf-directory "~/usr/org/bibtex-pdfs/"))
1654
1655 (use-package alert
1656 :commands (alert)
1657 :init (setq alert-default-style 'notifications))
1658
1659 ;; (use-package fill-column-indicator)
1660
1661 (use-package emojify
1662 :config
1663 (make-directory (b/var "emojify/") t)
1664 (setq emojify-emojis-dir (b/var "emojify/"))
1665 :hook (erc-mode . emojify-mode))
1666
1667 (use-feature window
1668 :bind
1669 (("C-c w <right>" . split-window-right)
1670 ("C-c w <down>" . split-window-below)
1671 ("C-c w s l" . split-window-right)
1672 ("C-c w s j" . split-window-below)
1673 ("C-c w q" . quit-window))
1674 :custom
1675 (split-width-threshold 150))
1676
1677 (use-feature windmove
1678 :defer 0.6
1679 :bind
1680 (("C-c w h" . windmove-left)
1681 ("C-c w j" . windmove-down)
1682 ("C-c w k" . windmove-up)
1683 ("C-c w l" . windmove-right)
1684 ("C-c w H" . windmove-swap-states-left)
1685 ("C-c w J" . windmove-swap-states-down)
1686 ("C-c w K" . windmove-swap-states-up)
1687 ("C-c w L" . windmove-swap-states-right)))
1688
1689 (use-package pass
1690 :commands pass
1691 :bind ("C-c a p" . pass)
1692 :hook (pass-mode . View-exit))
1693
1694 (use-package pdf-tools
1695 :defer 0.5
1696 :bind (:map pdf-view-mode-map
1697 ("<XF86Back>" . pdf-history-backward)
1698 ("<XF86Forward>" . pdf-history-forward)
1699 ("M-RET" . image-previous-line))
1700 :config (pdf-tools-install nil t)
1701 :custom (pdf-view-resize-factor 1.05))
1702
1703 (use-package biblio)
1704
1705 (use-feature reftex
1706 :hook (latex-mode . reftex-mode))
1707
1708 (use-feature reftex-cite
1709 :after reftex
1710 :disabled ; enable to disable
1711 ; reftex-cite's default choice
1712 ; of previous word
1713 :config
1714 (defun reftex-get-bibkey-default ()
1715 "If the cursor is in a citation macro, return the word before the macro."
1716 (let* ((macro (reftex-what-macro 1)))
1717 (save-excursion
1718 (when (and macro (string-match "cite" (car macro)))
1719 (goto-char (cdr macro)))
1720 (reftex-this-word)))))
1721
1722 \f
1723 ;;; Email (with Gnus)
1724
1725 (defvar b/maildir (expand-file-name "~/mail/"))
1726 (with-eval-after-load 'recentf
1727 (add-to-list 'recentf-exclude b/maildir))
1728
1729 (setq
1730 b/gnus-init-file (b/etc "gnus")
1731 mail-user-agent 'gnus-user-agent
1732 read-mail-command 'gnus)
1733
1734 (use-feature gnus
1735 :bind (("s-m" . gnus)
1736 ("s-M" . gnus-unplugged)
1737 ("C-c a m" . gnus)
1738 ("C-c a M" . gnus-unplugged))
1739 :init
1740 (setq
1741 gnus-select-method '(nnnil "")
1742 gnus-secondary-select-methods
1743 '((nnimap "shemshak"
1744 (nnimap-stream plain)
1745 (nnimap-address "127.0.0.1")
1746 (nnimap-server-port 143)
1747 (nnimap-authenticator plain)
1748 (nnimap-user "amin@shemshak.local"))
1749 (nnimap "gnu"
1750 (nnimap-stream plain)
1751 (nnimap-address "127.0.0.1")
1752 (nnimap-server-port 143)
1753 (nnimap-authenticator plain)
1754 (nnimap-user "bandali@gnu.local")
1755 (nnimap-inbox "INBOX")
1756 (nnimap-split-methods 'nnimap-split-fancy)
1757 (nnimap-split-fancy (|
1758 ;; (: gnus-registry-split-fancy-with-parent)
1759 ;; (: gnus-group-split-fancy "INBOX" t "INBOX")
1760 ;; gnu
1761 (list ".*<\\(.*\\)\\.\\(non\\)?gnu\\.org>.*" "l.\\1")
1762 ;; *@lists.sr.ht, omitting one dot if present
1763 ;; add more \\.?\\([^.@]*\\) if needed
1764 (list ".*<~\\(.*\\)/\\([^.@]*\\)\\.?\\([^.@]*\\)@lists.sr.ht>.*" "l.~\\1.\\2\\3")
1765 ;; webmasters
1766 (from "webmasters\\(-comment\\)?@gnu\\.org" "webmasters")
1767 ;; other
1768 (list ".*atreus.freelists.org" "l.atreus")
1769 (list ".*deepspec.lists.cs.princeton.edu" "l.deepspec")
1770 ;; (list ".*haskell-art.we.lurk.org" "l.haskell.art") ;d
1771 (list ".*haskell-cafe.haskell.org" "l.haskell-cafe")
1772 ;; (list ".*notmuch.notmuchmail.org" "l.notmuch") ;u
1773 ;; (list ".*dev.lists.parabola.nu" "l.parabola-dev") ;u
1774 ;; ----------------------------------
1775 ;; legend: (u)nsubscribed | (d)ead
1776 ;; ----------------------------------
1777 ;; otherwise, leave mail in INBOX
1778 "INBOX")))
1779 (nnimap "uw"
1780 (nnimap-stream plain)
1781 (nnimap-address "127.0.0.1")
1782 (nnimap-server-port 143)
1783 (nnimap-authenticator plain)
1784 (nnimap-user "abandali@uw.local")
1785 (nnimap-inbox "INBOX")
1786 (nnimap-split-methods 'nnimap-split-fancy)
1787 (nnimap-split-fancy (|
1788 ;; (: gnus-registry-split-fancy-with-parent)
1789 ;; se212-f19
1790 ("subject" "SE\\s-?212" "course.se212-f19")
1791 (from "SE\\s-?212" "course.se212-f19")
1792 ;; catch-all
1793 "INBOX")))
1794 (nnimap "csc"
1795 (nnimap-stream plain)
1796 (nnimap-address "127.0.0.1")
1797 (nnimap-server-port 143)
1798 (nnimap-authenticator plain)
1799 (nnimap-user "abandali@csc.uw.local")))
1800 gnus-message-archive-group "nnimap+shemshak:Sent"
1801 gnus-parameters
1802 '(("l\\.atreus"
1803 (to-address . "atreus@freelists.org")
1804 (to-list . "atreus@freelists.org"))
1805 ("l\\.deepspec"
1806 (to-address . "deepspec@lists.cs.princeton.edu")
1807 (to-list . "deepspec@lists.cs.princeton.edu")
1808 (list-identifier . "\\[deepspec\\]"))
1809 ("l\\.emacs-devel"
1810 (to-address . "emacs-devel@gnu.org")
1811 (to-list . "emacs-devel@gnu.org"))
1812 ("l\\.help-gnu-emacs"
1813 (to-address . "help-gnu-emacs@gnu.org")
1814 (to-list . "help-gnu-emacs@gnu.org"))
1815 ("l\\.info-gnu-emacs"
1816 (to-address . "info-gnu-emacs@gnu.org")
1817 (to-list . "info-gnu-emacs@gnu.org"))
1818 ("l\\.emacs-orgmode"
1819 (to-address . "emacs-orgmode@gnu.org")
1820 (to-list . "emacs-orgmode@gnu.org")
1821 (list-identifier . "\\[O\\]"))
1822 ("l\\.emacs-tangents"
1823 (to-address . "emacs-tangents@gnu.org")
1824 (to-list . "emacs-tangents@gnu.org"))
1825 ("l\\.emacsconf-discuss"
1826 (to-address . "emacsconf-discuss@gnu.org")
1827 (to-list . "emacsconf-discuss@gnu.org"))
1828 ("l\\.emacsconf-register"
1829 (to-address . "emacsconf-register@gnu.org")
1830 (to-list . "emacsconf-register@gnu.org"))
1831 ("l\\.emacsconf-submit"
1832 (to-address . "emacsconf-submit@gnu.org")
1833 (to-list . "emacsconf-submit@gnu.org"))
1834 ("l\\.fencepost-users"
1835 (to-address . "fencepost-users@gnu.org")
1836 (to-list . "fencepost-users@gnu.org")
1837 (list-identifier . "\\[Fencepost-users\\]"))
1838 ("l\\.gnewsense-art"
1839 (to-address . "gnewsense-art@nongnu.org")
1840 (to-list . "gnewsense-art@nongnu.org")
1841 (list-identifier . "\\[gNewSense-art\\]"))
1842 ("l\\.gnewsense-dev"
1843 (to-address . "gnewsense-dev@nongnu.org")
1844 (to-list . "gnewsense-dev@nongnu.org")
1845 (list-identifier . "\\[Gnewsense-dev\\]"))
1846 ("l\\.gnewsense-users"
1847 (to-address . "gnewsense-users@nongnu.org")
1848 (to-list . "gnewsense-users@nongnu.org")
1849 (list-identifier . "\\[gNewSense-users\\]"))
1850 ("l\\.gnunet-developers"
1851 (to-address . "gnunet-developers@gnu.org")
1852 (to-list . "gnunet-developers@gnu.org")
1853 (list-identifier . "\\[GNUnet-developers\\]"))
1854 ("l\\.help-gnunet"
1855 (to-address . "help-gnunet@gnu.org")
1856 (to-list . "help-gnunet@gnu.org")
1857 (list-identifier . "\\[Help-gnunet\\]"))
1858 ("l\\.bug-gnuzilla"
1859 (to-address . "bug-gnuzilla@gnu.org")
1860 (to-list . "bug-gnuzilla@gnu.org")
1861 (list-identifier . "\\[Bug-gnuzilla\\]"))
1862 ("l\\.gnuzilla-dev"
1863 (to-address . "gnuzilla-dev@gnu.org")
1864 (to-list . "gnuzilla-dev@gnu.org")
1865 (list-identifier . "\\[Gnuzilla-dev\\]"))
1866 ("l\\.guile-devel"
1867 (to-address . "guile-devel@gnu.org")
1868 (to-list . "guile-devel@gnu.org"))
1869 ("l\\.guile-user"
1870 (to-address . "guile-user@gnu.org")
1871 (to-list . "guile-user@gnu.org"))
1872 ("l\\.guix-devel"
1873 (to-address . "guix-devel@gnu.org")
1874 (to-list . "guix-devel@gnu.org"))
1875 ("l\\.help-guix"
1876 (to-address . "help-guix@gnu.org")
1877 (to-list . "help-guix@gnu.org"))
1878 ("l\\.info-guix"
1879 (to-address . "info-guix@gnu.org")
1880 (to-list . "info-guix@gnu.org"))
1881 ("l\\.savannah-hackers-public"
1882 (to-address . "savannah-hackers-public@gnu.org")
1883 (to-list . "savannah-hackers-public@gnu.org"))
1884 ("l\\.savannah-users"
1885 (to-address . "savannah-users@gnu.org")
1886 (to-list . "savannah-users@gnu.org"))
1887 ("l\\.www-commits"
1888 (to-address . "www-commits@gnu.org")
1889 (to-list . "www-commits@gnu.org"))
1890 ("l\\.www-discuss"
1891 (to-address . "www-discuss@gnu.org")
1892 (to-list . "www-discuss@gnu.org"))
1893 ("l\\.haskell-art"
1894 (to-address . "haskell-art@we.lurk.org")
1895 (to-list . "haskell-art@we.lurk.org")
1896 (list-identifier . "\\[haskell-art\\]"))
1897 ("l\\.haskell-cafe"
1898 (to-address . "haskell-cafe@haskell.org")
1899 (to-list . "haskell-cafe@haskell.org")
1900 (list-identifier . "\\[Haskell-cafe\\]"))
1901 ("l\\.notmuch"
1902 (to-address . "notmuch@notmuchmail.org")
1903 (to-list . "notmuch@notmuchmail.org"))
1904 ("l\\.parabola-dev"
1905 (to-address . "dev@lists.parabola.nu")
1906 (to-list . "dev@lists.parabola.nu")
1907 (list-identifier . "\\[Dev\\]"))
1908 ("l\\.~bandali\\.public-inbox"
1909 (to-address . "~bandali/public-inbox@lists.sr.ht")
1910 (to-list . "~bandali/public-inbox@lists.sr.ht"))
1911 ("l\\.~sircmpwn\\.free-writers-club"
1912 (to-address . "~sircmpwn/free-writers-club@lists.sr.ht")
1913 (to-list . "~sircmpwn/free-writers-club@lists.sr.ht"))
1914 ("l\\.~sircmpwn\\.srht-admins"
1915 (to-address . "~sircmpwn/sr.ht-admins@lists.sr.ht")
1916 (to-list . "~sircmpwn/sr.ht-admins@lists.sr.ht"))
1917 ("l\\.~sircmpwn\\.srht-announce"
1918 (to-address . "~sircmpwn/sr.ht-announce@lists.sr.ht")
1919 (to-list . "~sircmpwn/sr.ht-announce@lists.sr.ht"))
1920 ("l\\.~sircmpwn\\.srht-dev"
1921 (to-address . "~sircmpwn/sr.ht-dev@lists.sr.ht")
1922 (to-list . "~sircmpwn/sr.ht-dev@lists.sr.ht"))
1923 ("l\\.~sircmpwn\\.srht-discuss"
1924 (to-address . "~sircmpwn/sr.ht-discuss@lists.sr.ht")
1925 (to-list . "~sircmpwn/sr.ht-discuss@lists.sr.ht"))
1926 ("webmasters"
1927 (to-address . "webmasters@gnu.org")
1928 (to-list . "webmasters@gnu.org"))
1929 ("gnu.*"
1930 (gcc-self . t))
1931 ("gnu\\."
1932 (subscribed . t))
1933 ("nnimap\\+uw:.*"
1934 (gcc-self . t)))
1935 gnus-large-newsgroup 50
1936 gnus-home-directory (b/var "gnus/")
1937 gnus-directory (concat gnus-home-directory "news/")
1938 message-directory (concat gnus-home-directory "mail/")
1939 nndraft-directory (concat gnus-home-directory "drafts/")
1940 gnus-save-newsrc-file nil
1941 gnus-read-newsrc-file nil
1942 gnus-interactive-exit nil
1943 gnus-gcc-mark-as-read t)
1944 :config
1945 (require 'ebdb)
1946 (require 'ebdb-mua)
1947 (require 'ebdb-gnus)
1948
1949 (when (version< emacs-version "27")
1950 (add-to-list
1951 'nnmail-split-abbrev-alist
1952 '(list . "list-id\\|list-post\\|x-mailing-list\\|x-beenthere\\|x-loop")
1953 t))
1954
1955 ;; (gnus-registry-initialize)
1956
1957 (with-eval-after-load 'recentf
1958 (add-to-list 'recentf-exclude gnus-home-directory)))
1959
1960 (use-feature gnus-art
1961 :config
1962 (setq
1963 gnus-buttonized-mime-types '("multipart/\\(signed\\|encrypted\\)")
1964 gnus-visible-headers
1965 (concat gnus-visible-headers "\\|^List-Id:\\|^X-RT-Originator:\\|^User-Agent:")
1966 gnus-sorted-header-list
1967 '("^From:" "^Subject:" "^Summary:" "^Keywords:"
1968 "^Followup-To:" "^To:" "^Cc:" "X-RT-Originator"
1969 "^Newsgroups:" "List-Id:" "^Organization:"
1970 "^User-Agent:" "^Date:")
1971 ;; local-lapsed article dates
1972 ;; from https://www.emacswiki.org/emacs/GnusFormatting#toc11
1973 gnus-article-date-headers '(user-defined)
1974 gnus-article-time-format
1975 (lambda (time)
1976 (let* ((date (format-time-string "%a, %d %b %Y %T %z" time))
1977 (local (article-make-date-line date 'local))
1978 (combined-lapsed (article-make-date-line date
1979 'combined-lapsed))
1980 (lapsed (progn
1981 (string-match " (.+" combined-lapsed)
1982 (match-string 0 combined-lapsed))))
1983 (concat local lapsed))))
1984 (bind-keys
1985 :map gnus-article-mode-map
1986 ("M-L" . org-store-link)))
1987
1988 (use-feature gnus-sum
1989 :bind (:map gnus-summary-mode-map
1990 :prefix-map b/gnus-summary-prefix-map
1991 :prefix "v"
1992 ("r" . gnus-summary-reply)
1993 ("w" . gnus-summary-wide-reply)
1994 ("v" . gnus-summary-show-raw-article))
1995 :config
1996 (bind-keys
1997 :map gnus-summary-mode-map
1998 ("M-L" . org-store-link))
1999 :hook (gnus-summary-mode . b/no-mouse-autoselect-window))
2000
2001 (use-feature gnus-msg
2002 :config
2003 (defvar b/signature "Amin Bandali
2004 Free Software Activist | GNU Webmaster & Volunteer
2005 GPG: BE62 7373 8E61 6D6D 1B3A 08E8 A21A 0202 4881 6103
2006 https://shemshak.org/~amin")
2007 (defvar b/gnu-signature "Amin Bandali
2008 Free Software Activist | GNU Webmaster & Volunteer
2009 GPG: BE62 7373 8E61 6D6D 1B3A 08E8 A21A 0202 4881 6103
2010 https://bandali.eu.org")
2011 (defvar b/uw-signature "Amin Bandali, MMath Student
2012 Cheriton School of Computer Science
2013 University of Waterloo
2014 https://bandali.eu.org")
2015 (defvar b/csc-signature "Amin Bandali
2016 Systems Committee
2017 Computer Science Club, University of Waterloo
2018 https://csclub.uwaterloo.ca/~abandali")
2019 (setq gnus-posting-styles
2020 '((".*"
2021 (address "amin@shemshak.org")
2022 (body "\nBest,\n")
2023 (signature b/signature)
2024 (eval (setq b/message-cite-say-hi t)))
2025 ("nnimap\\+gnu:.*"
2026 (address "bandali@gnu.org")
2027 (signature b/gnu-signature)
2028 (eval (set (make-local-variable 'message-user-fqdn) "fencepost.gnu.org")))
2029 ((header "subject" "ThankCRM")
2030 (to "webmasters-comment@gnu.org")
2031 (body "")
2032 (eval (setq b/message-cite-say-hi nil)))
2033 ("nnimap\\+uw:.*"
2034 (address "abandali@uwaterloo.ca")
2035 (signature b/uw-signature))
2036 ("nnimap\\+uw:INBOX"
2037 (gcc "\"nnimap+uw:Sent Items\""))
2038 ("nnimap\\+csc:.*"
2039 (address "abandali@csclub.uwaterloo.ca")
2040 (signature b/csc-signature)
2041 (gcc "nnimap+csc:Sent")))))
2042
2043 (use-feature gnus-topic
2044 :hook (gnus-group-mode . gnus-topic-mode)
2045 :config (setq gnus-topic-line-format "%i[ %A: %(%{%n%}%) ]%v\n"))
2046
2047 (use-feature gnus-agent
2048 :config
2049 (setq gnus-agent-synchronize-flags 'ask)
2050 :hook (gnus-group-mode . gnus-agent-mode))
2051
2052 (use-feature gnus-group
2053 :config
2054 (setq gnus-permanently-visible-groups "\\(:INBOX$\\|:gnu$\\)"))
2055
2056 (comment
2057 ;; problematic with ebdb's popup, *EBDB-Gnus*
2058 (use-feature gnus-win
2059 :config
2060 (setq gnus-use-full-window nil)))
2061
2062 (use-feature gnus-dired
2063 :commands gnus-dired-mode
2064 :init
2065 (add-hook 'dired-mode-hook 'gnus-dired-mode))
2066
2067 (use-feature mm-decode
2068 :config
2069 (setq mm-discouraged-alternatives '("text/html" "text/richtext")
2070 mm-decrypt-option 'known
2071 mm-verify-option 'known))
2072
2073 (use-feature sendmail
2074 :config
2075 (setq sendmail-program (executable-find "msmtp")
2076 ;; message-sendmail-extra-arguments '("-v" "-d")
2077 mail-specify-envelope-from t
2078 mail-envelope-from 'header))
2079
2080 (use-feature message
2081 :config
2082 ;; redefine for a simplified In-Reply-To header
2083 ;; (see https://todo.sr.ht/~sircmpwn/lists.sr.ht/67)
2084 (defun message-make-in-reply-to ()
2085 "Return the In-Reply-To header for this message."
2086 (when message-reply-headers
2087 (let ((from (mail-header-from message-reply-headers))
2088 (msg-id (mail-header-id message-reply-headers)))
2089 (when from
2090 msg-id))))
2091
2092 (defconst b/message-cite-style-format "On %Y-%m-%d %l:%M %p, %N wrote:")
2093 (defconst message-cite-style-bandali
2094 '((message-cite-function 'message-cite-original)
2095 (message-citation-line-function 'message-insert-formatted-citation-line)
2096 (message-cite-reply-position 'traditional)
2097 (message-yank-prefix "> ")
2098 (message-yank-cited-prefix ">")
2099 (message-yank-empty-prefix ">")
2100 (message-citation-line-format
2101 (if b/message-cite-say-hi
2102 (concat "Hi %F,\n\n" b/message-cite-style-format)
2103 b/message-cite-style-format)))
2104 "Citation style based on Mozilla Thunderbird's. Use with message-cite-style.")
2105 (setq ;; message-cite-style 'message-cite-style-bandali
2106 message-kill-buffer-on-exit t
2107 message-send-mail-function 'message-send-mail-with-sendmail
2108 message-sendmail-envelope-from 'header
2109 message-subscribed-address-functions
2110 '(gnus-find-subscribed-addresses)
2111 message-dont-reply-to-names
2112 "\\(\\(\\(amin\\|mab\\)@shemshak\\.org\\)\\|\\(amin@bndl\\.org\\)\\|\\(.*@aminb\\.org\\)\\|\\(\\(bandali\\|mab\\|aminb?\\)@gnu\\.org\\)\\|\\(a\\(min\\.\\)?bandali@uwaterloo\\.ca\\)\\|\\(abandali@csclub\\.uwaterloo\\.ca\\)\\)")
2113 (require 'company-ebdb)
2114 :hook (;; (message-setup . mml-secure-message-sign-pgpmime)
2115 (message-mode . flyspell-mode)
2116 (message-mode . (lambda ()
2117 ;; (setq fill-column 65
2118 ;; message-fill-column 65)
2119 (make-local-variable 'company-idle-delay)
2120 (setq company-idle-delay 0.2))))
2121 ;; :custom-face
2122 ;; (message-header-subject ((t (:foreground "#111" :weight semi-bold))))
2123 ;; (message-header-to ((t (:foreground "#111" :weight normal))))
2124 ;; (message-header-cc ((t (:foreground "#333" :weight normal))))
2125 )
2126
2127 (use-feature mml
2128 :delight " mml")
2129
2130 (use-feature mml-sec
2131 :custom
2132 (mml-secure-openpgp-encrypt-to-self t)
2133 (mml-secure-openpgp-sign-with-sender t))
2134
2135 (use-feature footnote
2136 :after message
2137 ;; :config
2138 ;; (setq footnote-start-tag ""
2139 ;; footnote-end-tag ""
2140 ;; footnote-style 'unicode)
2141 :bind
2142 (:map message-mode-map
2143 :prefix-map b/footnote-prefix-map
2144 :prefix "C-c f"
2145 ("a" . footnote-add-footnote)
2146 ("b" . footnote-back-to-message)
2147 ("c" . footnote-cycle-style)
2148 ("d" . footnote-delete-footnote)
2149 ("g" . footnote-goto-footnote)
2150 ("r" . footnote-renumber-footnotes)
2151 ("s" . footnote-set-style)))
2152
2153 (use-package ebdb
2154 :after gnus
2155 :bind (:map gnus-group-mode-map ("e" . ebdb))
2156 :config
2157 (setq ebdb-sources (b/var "ebdb"))
2158 (with-eval-after-load 'swiper
2159 (add-to-list 'swiper-font-lock-exclude 'ebdb-mode t)))
2160
2161 (use-feature ebdb-com
2162 :after ebdb)
2163
2164 ;; (use-package ebdb-complete
2165 ;; :after ebdb
2166 ;; :config
2167 ;; (ebdb-complete-enable))
2168
2169 (use-package company-ebdb
2170 :config
2171 (defun company-ebdb--post-complete (_) nil))
2172
2173 (use-feature ebdb-gnus
2174 :after ebdb
2175 :custom
2176 (ebdb-gnus-window-configuration
2177 '(article
2178 (vertical 1.0
2179 (summary 0.25 point)
2180 (horizontal 1.0
2181 (article 1.0)
2182 (ebdb-gnus 0.3))))))
2183
2184 (use-feature ebdb-mua
2185 :after ebdb
2186 ;; :custom (ebdb-mua-pop-up nil)
2187 )
2188
2189 ;; (use-package ebdb-message
2190 ;; :after ebdb)
2191
2192 ;; (use-package ebdb-vcard
2193 ;; :after ebdb)
2194
2195 (use-package message-x)
2196
2197 (comment
2198 (use-package message-x
2199 :custom
2200 (message-x-completion-alist
2201 (quote
2202 (("\\([rR]esent-\\|[rR]eply-\\)?[tT]o:\\|[bB]?[cC][cC]:" . gnus-harvest-find-address)
2203 ((if
2204 (boundp
2205 (quote message-newgroups-header-regexp))
2206 message-newgroups-header-regexp message-newsgroups-header-regexp)
2207 . message-expand-group))))))
2208
2209 (comment
2210 (use-package gnus-harvest
2211 :commands gnus-harvest-install
2212 :demand t
2213 :config
2214 (if (featurep 'message-x)
2215 (gnus-harvest-install 'message-x)
2216 (gnus-harvest-install))))
2217
2218 \f
2219 ;;; IRC (with ERC and ZNC)
2220
2221 (use-feature erc
2222 :bind (("C-c b e" . erc-switch-to-buffer)
2223 :map erc-mode-map
2224 ("M-a" . erc-track-switch-buffer))
2225 :custom
2226 (erc-join-buffer 'bury)
2227 (erc-lurker-hide-list '("JOIN" "PART" "QUIT"))
2228 (erc-nick "bandali")
2229 (erc-prompt "erc>")
2230 (erc-rename-buffers t)
2231 (erc-server-reconnect-attempts 5)
2232 (erc-server-reconnect-timeout 3)
2233 :config
2234 (defun erc-cmd-OPME ()
2235 "Request chanserv to op me."
2236 (erc-message "PRIVMSG"
2237 (format "chanserv op %s %s"
2238 (erc-default-target)
2239 (erc-current-nick)) nil))
2240 (defun erc-cmd-DEOPME ()
2241 "Deop myself from current channel."
2242 (erc-cmd-DEOP (format "%s" (erc-current-nick))))
2243 (add-to-list 'erc-modules 'keep-place)
2244 (add-to-list 'erc-modules 'notifications)
2245 (add-to-list 'erc-modules 'spelling)
2246 (add-to-list 'erc-modules 'scrolltoplace)
2247 (erc-update-modules)
2248
2249 (when (and (version<= "24.4" emacs-version)
2250 (version< emacs-version "27"))
2251 ;; fix erc-lurker bug
2252 ;; patch submitted: https://bugs.gnu.org/36843#10
2253 ;; TODO: remove when patch is merged and emacs 27 is released
2254 (defvar erc-message-parsed)
2255 (defun erc-display-message (parsed type buffer msg &rest args)
2256 "Display MSG in BUFFER.
2257
2258 ARGS, PARSED, and TYPE are used to format MSG sensibly.
2259
2260 See also `erc-format-message' and `erc-display-line'."
2261 (let ((string (if (symbolp msg)
2262 (apply #'erc-format-message msg args)
2263 msg))
2264 (erc-message-parsed parsed))
2265 (setq string
2266 (cond
2267 ((null type)
2268 string)
2269 ((listp type)
2270 (mapc (lambda (type)
2271 (setq string
2272 (erc-display-message-highlight type string)))
2273 type)
2274 string)
2275 ((symbolp type)
2276 (erc-display-message-highlight type string))))
2277
2278 (if (not (erc-response-p parsed))
2279 (erc-display-line string buffer)
2280 (unless (erc-hide-current-message-p parsed)
2281 (erc-put-text-property 0 (length string) 'erc-parsed parsed string)
2282 (erc-put-text-property 0 (length string) 'rear-sticky t string)
2283 (when (erc-response.tags parsed)
2284 (erc-put-text-property 0 (length string) 'tags (erc-response.tags parsed)
2285 string))
2286 (erc-display-line string buffer)))))
2287
2288 (defun erc-lurker-update-status (_message)
2289 "Update `erc-lurker-state' if necessary.
2290
2291 This function is called from `erc-insert-pre-hook'. If the
2292 current message is a PRIVMSG, update `erc-lurker-state' to
2293 reflect the fact that its sender has issued a PRIVMSG at the
2294 current time. Otherwise, take no action.
2295
2296 This function depends on the fact that `erc-display-message'
2297 lexically binds `erc-message-parsed', which is used to check if
2298 the current message is a PRIVMSG and to determine its sender.
2299 See also `erc-lurker-trim-nicks' and `erc-lurker-ignore-chars'.
2300
2301 In order to limit memory consumption, this function also calls
2302 `erc-lurker-cleanup' once every `erc-lurker-cleanup-interval'
2303 updates of `erc-lurker-state'."
2304 (when (and (boundp 'erc-message-parsed)
2305 (erc-response-p erc-message-parsed))
2306 (let* ((command (erc-response.command erc-message-parsed))
2307 (sender
2308 (erc-lurker-maybe-trim
2309 (car (erc-parse-user (erc-response.sender erc-message-parsed)))))
2310 (server
2311 (erc-canonicalize-server-name erc-server-announced-name)))
2312 (when (equal command "PRIVMSG")
2313 (when (>= (cl-incf erc-lurker-cleanup-count)
2314 erc-lurker-cleanup-interval)
2315 (setq erc-lurker-cleanup-count 0)
2316 (erc-lurker-cleanup))
2317 (unless (gethash server erc-lurker-state)
2318 (puthash server (make-hash-table :test 'equal) erc-lurker-state))
2319 (puthash sender (current-time)
2320 (gethash server erc-lurker-state))))))))
2321
2322 (use-feature erc-fill
2323 :after erc
2324 :custom
2325 (erc-fill-column 77)
2326 (erc-fill-function 'erc-fill-static)
2327 (erc-fill-static-center 18))
2328
2329 (use-feature erc-pcomplete
2330 :after erc
2331 :custom
2332 (erc-pcomplete-nick-postfix ","))
2333
2334 (use-feature erc-track
2335 :after erc
2336 :bind (("C-c a e t d" . erc-track-disable)
2337 ("C-c a e t e" . erc-track-enable))
2338 :custom
2339 (erc-track-enable-keybindings nil)
2340 (erc-track-exclude-types '("JOIN" "MODE" "NICK" "PART" "QUIT"
2341 "324" "329" "332" "333" "353" "477"))
2342 (erc-track-priority-faces-only 'all)
2343 (erc-track-shorten-function nil))
2344
2345 (use-package erc-hl-nicks
2346 :after erc)
2347
2348 (use-package erc-scrolltoplace
2349 :after erc)
2350
2351 (use-package znc
2352 :straight (:host nil :repo "https://git.shemshak.org/amin/znc.el")
2353 :bind (("C-c a e e" . znc-erc)
2354 ("C-c a e a" . znc-all))
2355 :config
2356 (let ((pwd (let ((auth (auth-source-search :host "znca")))
2357 (cond
2358 ((null auth) (error "Couldn't find znca's authinfo"))
2359 (t (funcall (plist-get (car auth) :secret)))))))
2360 (setq znc-servers
2361 `(("znc.shemshak.org" 1337 t
2362 ((freenode "amin/freenode" ,pwd)))
2363 ("znc.shemshak.org" 1337 t
2364 ((moznet "amin/moznet" ,pwd)))
2365 ("znc.shemshak.org" 1337 t
2366 ((oftc "amin/oftc" ,pwd)))))))
2367
2368 \f
2369 ;;; Post initialization
2370
2371 (message "Loading %s...done (%.3fs)" user-init-file
2372 (float-time (time-subtract (current-time)
2373 b/before-user-init-time)))
2374
2375 ;;; init.el ends here