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