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