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