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