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