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