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