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