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