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