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