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