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