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