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