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