c7eac7ee9923e1b49573e8c887792053e1999889
[~bandali/configs] / .emacs.d / init.el
1 ;;; init.el --- Amin Bandali's Emacs config -*- 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 advocate.
22
23 ;; THIS FILE IS AUTO-GENERATED FROM `init.org'.
24
25 ;;; Code:
26
27 (defvar a/before-user-init-time (current-time)
28 "Value of `current-time' when Emacs begins loading `user-init-file'.")
29 (message "Loading Emacs...done (%.3fs)"
30 (float-time (time-subtract a/before-user-init-time
31 before-init-time)))
32
33 (defvar a/gc-cons-threshold gc-cons-threshold)
34 (defvar a/gc-cons-percentage gc-cons-percentage)
35 (defvar a/file-name-handler-alist file-name-handler-alist)
36 (setq gc-cons-threshold (* 400 1024 1024) ; 400 MiB
37 gc-cons-percentage 0.6
38 file-name-handler-alist nil
39 ;; sidesteps a bug when profiling with esup
40 esup-child-profile-require-level 0)
41
42 (add-hook
43 'after-init-hook
44 (lambda ()
45 (setq gc-cons-threshold a/gc-cons-threshold
46 gc-cons-percentage a/gc-cons-percentage
47 file-name-handler-alist a/file-name-handler-alist)))
48
49 (setq message-log-max 20000)
50
51 ;; (setq byte-compile-warnings
52 ;; '(not free-vars unresolved noruntime lexical make-local))
53
54 (setq user-full-name "Amin Bandali"
55 user-mail-address "amin@bndl.org")
56
57 ;; Main engine start...
58
59 (setq straight-repository-branch "develop"
60 straight-check-for-modifications '(check-on-save find-when-checking))
61
62 (defun a/bootstrap-straight ()
63 (defvar bootstrap-version)
64 (let ((bootstrap-file
65 (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
66 (bootstrap-version 5))
67 (unless (file-exists-p bootstrap-file)
68 (with-current-buffer
69 (url-retrieve-synchronously
70 "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
71 'silent 'inhibit-cookies)
72 (goto-char (point-max))
73 (eval-print-last-sexp)))
74 (load bootstrap-file nil 'nomessage)))
75
76 ;; Solid rocket booster ignition...
77
78 (a/bootstrap-straight)
79
80 ;; We have lift off!
81
82 (setq straight-use-package-by-default t)
83
84 (defmacro use-feature (name &rest args)
85 "Like `use-package', but with `straight-use-package-by-default' disabled."
86 (declare (indent defun))
87 `(use-package ,name
88 :straight nil
89 ,@args))
90
91 (with-eval-after-load 'recentf
92 (add-to-list 'recentf-exclude
93 (expand-file-name "~/.emacs.d/straight/build/")))
94
95 (defun a/reload-init ()
96 "Reload init.el."
97 (interactive)
98 (straight-transaction
99 (straight-mark-transaction-as-init)
100 (load user-init-file)))
101
102 (straight-use-package 'use-package)
103 (if nil ; set to t when need to debug init
104 (progn
105 (setq use-package-verbose t
106 use-package-expand-minimally nil
107 use-package-compute-statistics t
108 debug-on-error t)
109 (require 'use-package))
110 (setq use-package-verbose nil
111 use-package-expand-minimally t))
112
113 (setq use-package-always-defer t)
114 (require 'bind-key)
115
116 ;; comment macro, useful for commenting out multiple sexps at a time
117 (defmacro comment (&rest _)
118 "Comment out one or more s-expressions."
119 (declare (indent defun))
120 nil)
121
122 (use-package no-littering
123 :demand t
124 :config
125 (savehist-mode 1)
126 (add-to-list 'savehist-additional-variables 'kill-ring)
127 (save-place-mode 1)
128 (setq auto-save-file-name-transforms
129 `((".*" ,(no-littering-expand-var-file-name "auto-save/") t))))
130
131 (use-feature custom
132 :no-require t
133 :config
134 (setq custom-file (no-littering-expand-etc-file-name "custom.el"))
135 (when (file-exists-p custom-file)
136 (load custom-file))
137 (setf custom-safe-themes t))
138
139 (with-demoted-errors
140 (load (no-littering-expand-etc-file-name "secrets")))
141
142 (use-package exec-path-from-shell
143 :defer 0.4
144 :init
145 (setq exec-path-from-shell-arguments nil
146 exec-path-from-shell-check-startup-files nil)
147 :config
148 (exec-path-from-shell-initialize)
149 ;; while we're at it, let's fix access to our running ssh-agent
150 (exec-path-from-shell-copy-env "SSH_AGENT_PID")
151 (exec-path-from-shell-copy-env "SSH_AUTH_SOCK"))
152
153 (use-feature server
154 :defer 0.4
155 :config (or (server-running-p) (server-mode)))
156
157 (setq text-scale-mode-step 1.05)
158
159 (setq mouse-autoselect-window t)
160
161 (defun a/no-mouse-autoselect-window ()
162 (make-local-variable 'mouse-autoselect-window)
163 (setq mouse-autoselect-window nil))
164
165 (setq ;; scroll-margin 1
166 ;; scroll-conservatively 10000
167 scroll-step 1
168 scroll-conservatively 10
169 scroll-preserve-screen-position 1)
170
171 (use-feature mwheel
172 :defer 0.4
173 :config
174 (setq mouse-wheel-scroll-amount '(1 ((shift) . 1)) ; one line at a time
175 mouse-wheel-progressive-speed nil ; don't accelerate scrolling
176 mouse-wheel-follow-mouse t)) ; scroll window under mouse
177
178 (use-feature pixel-scroll
179 :defer 0.4
180 :config (pixel-scroll-mode 1))
181
182 (setq epg-pinentry-mode 'loopback)
183
184 (require 'cl-lib)
185 (require 'subr-x)
186
187 (defmacro a/setq-every (value &rest vars)
188 "Set all the variables from VARS to value VALUE."
189 (declare (indent defun) (debug t))
190 `(progn ,@(mapcar (lambda (x) (list 'setq x value)) vars)))
191
192 (defun a/start-process (program &rest args)
193 "Same as `start-process', but doesn't bother about name and buffer."
194 (let ((process-name (concat program "_process"))
195 (buffer-name (generate-new-buffer-name
196 (concat program "_output"))))
197 (apply #'start-process
198 process-name buffer-name program args)))
199
200 (defun a/dired-start-process (program &optional args)
201 "Open current file with a PROGRAM."
202 ;; Shell command looks like this: "program [ARGS]... FILE" (ARGS can
203 ;; be nil, so remove it).
204 (apply #'a/start-process
205 program
206 (remove nil (list args (dired-get-file-for-visit)))))
207
208 ;; (fringe-mode '(3 . 1))
209 (fringe-mode nil)
210
211 (setq disabled-command-function nil)
212
213 (setq save-interprogram-paste-before-kill t)
214
215 (setq enable-recursive-minibuffers t
216 resize-mini-windows t)
217
218 (defalias 'yes-or-no-p #'y-or-n-p)
219
220 (setq initial-buffer-choice t)
221
222 (setq initial-scratch-message nil)
223
224 (setq initial-major-mode 'text-mode)
225
226 (setq inhibit-startup-buffer-menu t)
227
228 (advice-add #'display-startup-echo-area-message :override #'ignore)
229 (setq inhibit-startup-screen t
230 inhibit-startup-echo-area-message user-login-name)
231
232 (setq frame-title-format
233 '("" invocation-name " - "
234 (:eval (if (buffer-file-name)
235 (abbreviate-file-name (buffer-file-name))
236 "%b"))))
237
238 (setq backup-by-copying t
239 version-control t
240 delete-old-versions t)
241
242 (global-auto-revert-mode 1)
243 (setq auto-revert-verbose nil
244 global-auto-revert-non-file-buffers nil)
245
246 (setq-default
247 indent-tabs-mode nil
248 require-final-newline t
249 tab-width 4)
250
251 (winner-mode 1)
252
253 (with-eval-after-load 'compile
254 (defun a/compilation-finish-function (buffer outstr)
255 (unless (string-match "finished" outstr)
256 (switch-to-buffer-other-window buffer))
257 t)
258
259 (setq compilation-finish-functions #'a/compilation-finish-function)
260
261 (require 'cl-macs)
262
263 (defadvice compilation-start
264 (around inhibit-display
265 (command &optional mode name-function highlight-regexp))
266 (if (not (string-match "^\\(find\\|grep\\)" command))
267 (cl-letf (((symbol-function 'display-buffer) #'ignore))
268 (save-window-excursion ad-do-it))
269 ad-do-it))
270 (ad-activate 'compilation-start))
271
272 (setq search-default-mode #'char-fold-to-regexp)
273
274 ;; uncomment to extend this behaviour to query-replace
275 ;; (setq replace-char-fold t)
276
277 (setq-default cursor-type 'bar)
278
279 (setq isearch-allow-scroll t)
280
281 (bind-keys
282 ("C-c a i" . ielm)
283
284 ("C-c e b" . eval-buffer)
285 ("C-c e r" . eval-region)
286
287 ("C-c e i" . emacs-init-time)
288 ("C-c e u" . emacs-uptime)
289
290 ("C-c F m" . make-frame-command)
291 ("C-c F d" . delete-frame)
292 ("C-c F D" . delete-other-frames)
293
294 ("C-c o" . other-window)
295
296 ("C-S-h C" . describe-char)
297 ("C-S-h F" . describe-face)
298
299 ("C-x k" . kill-this-buffer)
300 ("C-x K" . kill-buffer)
301
302 ("s-p" . beginning-of-buffer)
303 ("s-n" . end-of-buffer))
304
305 (when (display-graphic-p)
306 (unbind-key "C-z" global-map))
307
308 (bind-keys
309 :prefix-map a/straight-prefix-map
310 :prefix "C-c p s"
311 ("u" . straight-use-package)
312 ("f" . straight-freeze-versions)
313 ("t" . straight-thaw-versions)
314 ("P" . straight-prune-build)
315 ("g" . straight-get-recipe)
316 ("r" . a/reload-init)
317 ;; M-x ^straight-.*-all$
318 ("a c" . straight-check-all)
319 ("a f" . straight-fetch-all)
320 ("a m" . straight-merge-all)
321 ("a n" . straight-normalize-all)
322 ("a F" . straight-pull-all)
323 ("a P" . straight-push-all)
324 ("a r" . straight-rebuild-all)
325 ;; M-x ^straight-.*-package$
326 ("p c" . straight-check-package)
327 ("p f" . straight-fetch-package)
328 ("p m" . straight-merge-package)
329 ("p n" . straight-normalize-package)
330 ("p F" . straight-pull-package)
331 ("p P" . straight-push-package)
332 ("p r" . straight-rebuild-package))
333
334 (use-package auto-compile
335 :demand t
336 :config
337 (auto-compile-on-load-mode)
338 (auto-compile-on-save-mode)
339 (setq auto-compile-display-buffer nil
340 auto-compile-mode-line-counter t
341 auto-compile-source-recreate-deletes-dest t
342 auto-compile-toggle-deletes-nonlib-dest t
343 auto-compile-update-autoloads t)
344 (add-hook 'auto-compile-inhibit-compile-hook
345 'auto-compile-inhibit-compile-detached-git-head))
346
347 (straight-use-package 'org-plus-contrib)
348
349 (use-feature org
350 :defer 0.5
351 :config
352 (setq org-src-tab-acts-natively t
353 org-src-preserve-indentation nil
354 org-edit-src-content-indentation 0
355 org-link-email-description-format "Email %c: %s" ; %.30s
356 org-highlight-latex-and-related '(entities)
357 org-use-speed-commands t
358 org-startup-folded 'content
359 org-catch-invisible-edits 'show-and-error
360 org-log-done 'time)
361 (add-to-list 'org-structure-template-alist '("L" . "src emacs-lisp") t)
362 :bind
363 (("C-c a o a" . org-agenda)
364 :map org-mode-map
365 ("M-L" . org-insert-last-stored-link)
366 ("s-T" . org-todo))
367 :hook ((org-mode . org-indent-mode)
368 (org-mode . auto-fill-mode)
369 (org-mode . flyspell-mode))
370 :custom
371 (org-agenda-files '("~/usr/org/todos/personal.org"
372 "~/usr/org/todos/masters.org"))
373 (org-agenda-start-on-weekday 0)
374 (org-latex-packages-alist '(("" "listings") ("" "color")))
375 :custom-face
376 '(org-block-begin-line ((t (:foreground "#5a5b5a" :background "#1d1f21"))))
377 '(org-block ((t (:background "#1d1f21"))))
378 '(org-latex-and-related ((t (:foreground "#b294bb")))))
379
380 (use-feature ox-latex
381 :after ox
382 :config
383 (setq org-latex-listings 'listings
384 ;; org-latex-prefer-user-labels t
385 )
386 (add-to-list 'org-latex-classes
387 '("IEEEtran" "\\documentclass[11pt]{IEEEtran}"
388 ("\\section{%s}" . "\\section*{%s}")
389 ("\\subsection{%s}" . "\\subsection*{%s}")
390 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
391 ("\\paragraph{%s}" . "\\paragraph*{%s}")
392 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
393 t)
394 (require 'ox-beamer))
395
396 (use-feature ox-extra
397 :config
398 (ox-extras-activate '(latex-header-blocks ignore-headlines)))
399
400 (with-eval-after-load 'org
401 (defvar a/show-async-tangle-results nil
402 "Keep *emacs* async buffers around for later inspection.")
403
404 (defvar a/show-async-tangle-time nil
405 "Show the time spent tangling the file.")
406
407 (defun a/async-babel-tangle ()
408 "Tangle org file asynchronously."
409 (interactive)
410 (let* ((file-tangle-start-time (current-time))
411 (file (buffer-file-name))
412 (file-nodir (file-name-nondirectory file))
413 ;; (async-quiet-switch "-q")
414 (file-noext (file-name-sans-extension file)))
415 (async-start
416 `(lambda ()
417 (require 'org)
418 (org-babel-tangle-file ,file))
419 (unless a/show-async-tangle-results
420 `(lambda (result)
421 (if result
422 (message "Tangled %s%s"
423 ,file-nodir
424 (if a/show-async-tangle-time
425 (format " (%.3fs)"
426 (float-time (time-subtract (current-time)
427 ',file-tangle-start-time)))
428 ""))
429 (message "Tangling %s failed" ,file-nodir))))))))
430
431 (add-to-list
432 'safe-local-variable-values
433 '(eval add-hook 'after-save-hook #'a/async-babel-tangle 'append 'local))
434
435 (use-package magit
436 :defer 0.5
437 :bind (("C-x g" . magit-status)
438 ("s-g s" . magit-status)
439 ("s-g l" . magit-log-buffer-file))
440 :config
441 (magit-add-section-hook 'magit-status-sections-hook
442 'magit-insert-modules
443 'magit-insert-stashes
444 'append)
445 (setq magit-repository-directories '(("~/" . 0)
446 ("~/src/git/" . 1)))
447 (nconc magit-section-initial-visibility-alist
448 '(([unpulled status] . show)
449 ([unpushed status] . show)))
450 :custom-face (magit-diff-file-heading ((t (:weight normal)))))
451
452 (use-feature recentf
453 :defer 0.2
454 :config
455 (add-to-list 'recentf-exclude "^/\\(?:ssh\\|su\\|sudo\\)?:")
456 (setq recentf-max-saved-items 40))
457
458 (use-package smex)
459
460 (use-package ivy
461 :defer 0.3
462 :bind
463 (:map ivy-minibuffer-map
464 ([escape] . keyboard-escape-quit)
465 ([S-up] . ivy-previous-history-element)
466 ([S-down] . ivy-next-history-element)
467 ("DEL" . ivy-backward-delete-char))
468 :config
469 (setq ivy-wrap t
470 ivy-height 14
471 ivy-use-virtual-buffers t
472 ivy-virtual-abbreviate 'abbreviate
473 ivy-count-format "%d/%d ")
474 (ivy-mode 1)
475 ;; :custom-face
476 ;; (ivy-minibuffer-match-face-2 ((t (:background "#e99ce8" :weight semi-bold))))
477 ;; (ivy-minibuffer-match-face-3 ((t (:background "#bbbbff" :weight semi-bold))))
478 ;; (ivy-minibuffer-match-face-4 ((t (:background "#ffbbff" :weight semi-bold))))
479 )
480
481 (use-package swiper
482 :after ivy
483 :bind (("C-s" . swiper-isearch)
484 ("C-r" . swiper)
485 ("C-S-s" . isearch-forward)))
486
487 (use-package counsel
488 :after ivy
489 :bind (([remap execute-extended-command] . counsel-M-x)
490 ([remap find-file] . counsel-find-file)
491 ("C-c x" . counsel-M-x)
492 ("C-c f ." . counsel-find-file)
493 ("C-c f l" . counsel-find-library)
494 :map minibuffer-local-map
495 ("C-r" . counsel-minibuffer-history))
496 :config
497 (counsel-mode 1)
498 (defalias 'locate #'counsel-locate))
499
500 (use-feature eshell
501 :defer 0.5
502 :commands eshell
503 :bind ("C-c a s e" . eshell)
504 :config
505 (eval-when-compile (defvar eshell-prompt-regexp))
506 (defun a/eshell-quit-or-delete-char (arg)
507 (interactive "p")
508 (if (and (eolp) (looking-back eshell-prompt-regexp nil))
509 (eshell-life-is-too-much)
510 (delete-char arg)))
511
512 (defun a/eshell-clear ()
513 (interactive)
514 (let ((inhibit-read-only t))
515 (erase-buffer))
516 (eshell-send-input))
517
518 (defun a/eshell-setup ()
519 (make-local-variable 'company-idle-delay)
520 (defvar company-idle-delay)
521 (setq company-idle-delay nil)
522 (bind-keys :map eshell-mode-map
523 ("C-d" . a/eshell-quit-or-delete-char)
524 ("C-S-l" . a/eshell-clear)
525 ("M-r" . counsel-esh-history)
526 ([tab] . company-complete)))
527
528 :hook (eshell-mode . a/eshell-setup)
529 :custom
530 (eshell-hist-ignoredups t)
531 (eshell-input-filter 'eshell-input-filter-initial-space))
532
533 (use-feature ibuffer
534 :bind
535 (("C-x C-b" . ibuffer-other-window)
536 :map ibuffer-mode-map
537 ("P" . ibuffer-backward-filter-group)
538 ("N" . ibuffer-forward-filter-group)
539 ("M-p" . ibuffer-do-print)
540 ("M-n" . ibuffer-do-shell-command-pipe-replace))
541 :config
542 ;; Use human readable Size column instead of original one
543 (define-ibuffer-column size-h
544 (:name "Size" :inline t)
545 (cond
546 ((> (buffer-size) 1000000) (format "%7.1fM" (/ (buffer-size) 1000000.0)))
547 ((> (buffer-size) 100000) (format "%7.0fk" (/ (buffer-size) 1000.0)))
548 ((> (buffer-size) 1000) (format "%7.1fk" (/ (buffer-size) 1000.0)))
549 (t (format "%8d" (buffer-size)))))
550 :custom
551 (ibuffer-saved-filter-groups
552 '(("default"
553 ("dired" (mode . dired-mode))
554 ("org" (mode . org-mode))
555 ("gnus"
556 (or
557 (mode . gnus-group-mode)
558 (mode . gnus-summary-mode)
559 (mode . gnus-article-mode)
560 ;; not really, but...
561 (mode . message-mode)))
562 ("web"
563 (or
564 (mode . web-mode)
565 (mode . css-mode)
566 (mode . scss-mode)
567 (mode . js2-mode)))
568 ("shell"
569 (or
570 (mode . eshell-mode)
571 (mode . shell-mode)
572 (mode . term-mode)))
573 ("programming"
574 (or
575 (mode . python-mode)
576 (mode . c-mode)
577 (mode . c++-mode)
578 (mode . java-mode)
579 (mode . emacs-lisp-mode)
580 (mode . scheme-mode)
581 (mode . haskell-mode)
582 (mode . lean-mode)
583 (mode . alloy-mode)))
584 ("tex"
585 (or
586 (mode . bibtex-mode)
587 (mode . latex-mode)))
588 ("emacs"
589 (or
590 (name . "^\\*scratch\\*$")
591 (name . "^\\*Messages\\*$")))
592 ("erc" (mode . erc-mode)))))
593 (ibuffer-formats
594 '((mark modified read-only locked " "
595 (name 18 18 :left :elide)
596 " "
597 (size-h 9 -1 :right)
598 " "
599 (mode 16 16 :left :elide)
600 " " filename-and-process)
601 (mark " "
602 (name 16 -1)
603 " " filename)))
604 :hook (ibuffer . (lambda () (ibuffer-switch-to-saved-filter-groups "default"))))
605
606 (use-feature outline
607 :hook (prog-mode . outline-minor-mode)
608 :bind
609 (:map
610 outline-minor-mode-map
611 ("<s-tab>" . outline-toggle-children)
612 ("M-p" . outline-previous-visible-heading)
613 ("M-n" . outline-next-visible-heading)
614 :prefix-map a/outline-prefix-map
615 :prefix "s-o"
616 ("TAB" . outline-toggle-children)
617 ("a" . outline-hide-body)
618 ("H" . outline-hide-body)
619 ("S" . outline-show-all)
620 ("h" . outline-hide-subtree)
621 ("s" . outline-show-subtree)))
622
623 (use-feature ls-lisp
624 :custom (ls-lisp-dirs-first t))
625
626 (use-feature dired
627 :config
628 (setq dired-listing-switches "-alh"
629 ls-lisp-use-insert-directory-program nil)
630
631 ;; easily diff 2 marked files
632 ;; https://oremacs.com/2017/03/18/dired-ediff/
633 (defun dired-ediff-files ()
634 (interactive)
635 (require 'dired-aux)
636 (defvar ediff-after-quit-hook-internal)
637 (let ((files (dired-get-marked-files))
638 (wnd (current-window-configuration)))
639 (if (<= (length files) 2)
640 (let ((file1 (car files))
641 (file2 (if (cdr files)
642 (cadr files)
643 (read-file-name
644 "file: "
645 (dired-dwim-target-directory)))))
646 (if (file-newer-than-file-p file1 file2)
647 (ediff-files file2 file1)
648 (ediff-files file1 file2))
649 (add-hook 'ediff-after-quit-hook-internal
650 (lambda ()
651 (setq ediff-after-quit-hook-internal nil)
652 (set-window-configuration wnd))))
653 (error "no more than 2 files should be marked"))))
654 :bind (:map dired-mode-map
655 ("b" . dired-up-directory)
656 ("e" . dired-ediff-files)
657 ("E" . dired-toggle-read-only)
658 ("\\" . dired-hide-details-mode)
659 ("z" . (lambda ()
660 (interactive)
661 (a/dired-start-process "zathura"))))
662 :hook (dired-mode . dired-hide-details-mode))
663
664 (use-feature help
665 :config
666 (temp-buffer-resize-mode)
667 (setq help-window-select t))
668
669 (use-feature tramp
670 :config
671 (add-to-list 'tramp-default-proxies-alist '(nil "\\`root\\'" "/ssh:%h:"))
672 (add-to-list 'tramp-default-proxies-alist '("localhost" nil nil))
673 (add-to-list 'tramp-default-proxies-alist
674 (list (regexp-quote (system-name)) nil nil)))
675
676 (use-package dash
677 :config (dash-enable-font-lock))
678
679 (use-package doc-view
680 :bind (:map doc-view-mode-map
681 ("M-RET" . image-previous-line)))
682
683 (use-package diff-hl
684 :config
685 (setq diff-hl-draw-borders nil)
686 (global-diff-hl-mode)
687 :hook (magit-post-refresh . diff-hl-magit-post-refresh))
688
689 (use-feature eldoc
690 :when (version< "25" emacs-version)
691 :config (global-eldoc-mode))
692
693 (use-feature paren
694 :demand
695 :config (show-paren-mode))
696
697 (use-feature simple
698 :config (column-number-mode))
699
700 (use-feature savehist
701 :config (savehist-mode))
702
703 (use-feature saveplace
704 :when (version< "25" emacs-version)
705 :config (save-place-mode))
706
707 (use-feature prog-mode
708 :config (global-prettify-symbols-mode)
709 (defun indicate-buffer-boundaries-left ()
710 (setq indicate-buffer-boundaries 'left))
711 (add-hook 'prog-mode-hook #'indicate-buffer-boundaries-left))
712
713 (use-feature text-mode
714 :hook ((text-mode . indicate-buffer-boundaries-left)
715 (text-mode . abbrev-mode)))
716
717 (use-package company
718 :defer 0.6
719 :bind
720 (:map company-active-map
721 ([tab] . company-complete-common-or-cycle)
722 ([escape] . company-abort))
723 :custom
724 (company-minimum-prefix-length 1)
725 (company-selection-wrap-around t)
726 (company-dabbrev-char-regexp "\\sw\\|\\s_\\|[-_]")
727 (company-dabbrev-downcase nil)
728 (company-dabbrev-ignore-case nil)
729 :config
730 (global-company-mode t))
731
732 (use-package flycheck
733 :defer 0.6
734 :hook (prog-mode . flycheck-mode)
735 :bind
736 (:map flycheck-mode-map
737 ("M-P" . flycheck-previous-error)
738 ("M-N" . flycheck-next-error))
739 :config
740 ;; Use the load-path from running Emacs when checking elisp files
741 (setq flycheck-emacs-lisp-load-path 'inherit)
742
743 ;; Only flycheck when I actually save the buffer
744 (setq flycheck-check-syntax-automatically '(mode-enabled save)))
745
746 ;; http://endlessparentheses.com/ispell-and-apostrophes.html
747 (use-package ispell
748 :defer 0.6
749 :config
750 ;; ’ can be part of a word
751 (setq ispell-local-dictionary-alist
752 `((nil "[[:alpha:]]" "[^[:alpha:]]"
753 "['\x2019]" nil ("-B") nil utf-8)))
754 ;; don't send ’ to the subprocess
755 (defun endless/replace-apostrophe (args)
756 (cons (replace-regexp-in-string
757 "’" "'" (car args))
758 (cdr args)))
759 (advice-add #'ispell-send-string :filter-args
760 #'endless/replace-apostrophe)
761
762 ;; convert ' back to ’ from the subprocess
763 (defun endless/replace-quote (args)
764 (if (not (derived-mode-p 'org-mode))
765 args
766 (cons (replace-regexp-in-string
767 "'" "’" (car args))
768 (cdr args))))
769 (advice-add #'ispell-parse-output :filter-args
770 #'endless/replace-quote))
771
772 (use-feature lisp-mode
773 :config
774 (add-hook 'emacs-lisp-mode-hook 'outline-minor-mode)
775 (add-hook 'emacs-lisp-mode-hook 'reveal-mode)
776 (defun indent-spaces-mode ()
777 (setq indent-tabs-mode nil))
778 (add-hook 'lisp-interaction-mode-hook #'indent-spaces-mode))
779
780 (use-package alloy-mode
781 :straight (:host github :repo "dwwmmn/alloy-mode")
782 :mode "\\.als\\'"
783 :config (setq alloy-basic-offset 2))
784
785 (use-package proof-site ; Proof General
786 :straight proof-general)
787
788 (eval-when-compile (defvar lean-mode-map))
789 (use-package lean-mode
790 :defer 0.4
791 :bind (:map lean-mode-map
792 ("S-SPC" . company-complete))
793 :config
794 (require 'lean-input)
795 (setq default-input-method "Lean"
796 lean-input-tweak-all '(lean-input-compose
797 (lean-input-prepend "/")
798 (lean-input-nonempty))
799 lean-input-user-translations '(("/" "/")))
800 (lean-input-setup))
801
802 (use-package haskell-mode
803 :config
804 (setq haskell-indentation-layout-offset 4
805 haskell-indentation-left-offset 4
806 flycheck-checker 'haskell-hlint
807 flycheck-disabled-checkers '(haskell-stack-ghc haskell-ghc)))
808
809 (use-package dante
810 :after haskell-mode
811 :commands dante-mode
812 :hook (haskell-mode . dante-mode))
813
814 (use-package hlint-refactor
815 :after haskell-mode
816 :bind (:map hlint-refactor-mode-map
817 ("C-c l b" . hlint-refactor-refactor-buffer)
818 ("C-c l r" . hlint-refactor-refactor-at-point))
819 :hook (haskell-mode . hlint-refactor-mode))
820
821 (use-package flycheck-haskell
822 :after haskell-mode)
823
824 (use-package sgml-mode
825 :config
826 (setq sgml-basic-offset 2))
827
828 (use-package css-mode
829 :config
830 (setq css-indent-offset 2))
831
832 (use-package web-mode
833 :mode "\\.html\\'"
834 :config
835 (a/setq-every 2
836 web-mode-code-indent-offset
837 web-mode-css-indent-offset
838 web-mode-markup-indent-offset))
839
840 (use-package emmet-mode
841 :after (:any web-mode css-mode sgml-mode)
842 :bind* (("C-)" . emmet-next-edit-point)
843 ("C-(" . emmet-prev-edit-point))
844 :config
845 (unbind-key "C-j" emmet-mode-keymap)
846 (setq emmet-move-cursor-between-quotes t)
847 :hook (web-mode css-mode html-mode sgml-mode))
848
849 (use-package geiser)
850
851 (use-feature geiser-guile
852 :config
853 (setq geiser-guile-load-path "~/src/git/guix"))
854
855 (use-package guix)
856
857 (use-feature man
858 :config (setq Man-width 80))
859
860 (use-package which-key
861 :defer 0.4
862 :config
863 (which-key-add-key-based-replacements
864 ;; prefixes for global prefixes and minor modes
865 "C-c @" "outline"
866 "C-c !" "flycheck"
867 "C-c 8" "typo"
868 "C-c 8 -" "typo/dashes"
869 "C-c 8 <" "typo/left-brackets"
870 "C-c 8 >" "typo/right-brackets"
871 "C-x 8" "unicode"
872 "C-x a" "abbrev/expand"
873 "C-x r" "rectangle/register/bookmark"
874 "C-x v" "version control"
875 ;; prefixes for my personal bindings
876 "C-c a" "applications"
877 "C-c a e" "erc"
878 "C-c a o" "org"
879 "C-c a s" "shells"
880 "C-c p" "package-management"
881 ;; "C-c p e" "package-management/epkg"
882 "C-c p s" "straight.el"
883 "C-c psa" "all"
884 "C-c psp" "package"
885 "C-c c" "compile-and-comments"
886 "C-c e" "eval"
887 "C-c f" "files"
888 "C-c F" "frames"
889 "C-S-h" "help(ful)"
890 "C-c m" "multiple-cursors"
891 "C-c P" "projectile"
892 "C-c P s" "projectile/search"
893 "C-c P x" "projectile/execute"
894 "C-c P 4" "projectile/other-window"
895 "C-c q" "boxquote"
896 "s-g" "magit"
897 "s-o" "outline"
898 "s-t" "themes")
899
900 ;; prefixes for major modes
901 (which-key-add-major-mode-key-based-replacements 'message-mode
902 "C-c f" "footnote")
903 (which-key-add-major-mode-key-based-replacements 'org-mode
904 "C-c C-v" "org-babel")
905 (which-key-add-major-mode-key-based-replacements 'web-mode
906 "C-c C-a" "web/attributes"
907 "C-c C-b" "web/blocks"
908 "C-c C-d" "web/dom"
909 "C-c C-e" "web/element"
910 "C-c C-t" "web/tags")
911
912 (which-key-mode)
913 :custom
914 (which-key-add-column-padding 5)
915 (which-key-max-description-length 32))
916
917 (add-to-list 'custom-theme-load-path "~/.emacs.d/lisp")
918 (load-theme 'tangomod t)
919
920 (use-package smart-mode-line
921 :commands (sml/apply-theme)
922 :demand
923 :config
924 (sml/setup))
925
926 (use-package doom-themes)
927
928 (defvar a/org-mode-font-lock-keywords
929 '(("[ \t]*\\(#\\+\\(BEGIN\\|END\\|begin\\|end\\)_\\(\\S-+\\)\\)[ \t]*\\([^\n:]*\\)"
930 (1 '(:foreground "#5a5b5a" :background "#292b2b") t) ; directive
931 (3 '(:foreground "#81a2be" :background "#292b2b") t) ; kind
932 (4 '(:foreground "#c5c8c6") t)))) ; title
933
934 (defun a/lights-on ()
935 "Enable my favourite light theme."
936 (interactive)
937 (mapc #'disable-theme custom-enabled-themes)
938 (load-theme 'tangomod t)
939 (sml/apply-theme 'automatic)
940 (font-lock-remove-keywords
941 'org-mode a/org-mode-font-lock-keywords))
942
943 (defun a/lights-off ()
944 "Go dark."
945 (interactive)
946 (mapc #'disable-theme custom-enabled-themes)
947 (load-theme 'doom-tomorrow-night t)
948 (sml/apply-theme 'automatic)
949 (font-lock-add-keywords
950 'org-mode a/org-mode-font-lock-keywords t))
951
952 (bind-keys
953 ("s-t d" . a/lights-off)
954 ("s-t l" . a/lights-on))
955
956 (use-package crux ; results in Waiting for git... [2 times]
957 :defer 0.4
958 :bind (("C-c b k" . crux-kill-other-buffers)
959 ("C-c d" . crux-duplicate-current-line-or-region)
960 ("C-c D" . crux-duplicate-and-comment-current-line-or-region)
961 ("C-c f c" . crux-copy-file-preserve-attributes)
962 ("C-c f d" . crux-delete-file-and-buffer)
963 ("C-c f r" . crux-rename-file-and-buffer)
964 ("C-c j" . crux-top-join-line)
965 ("C-S-j" . crux-top-join-line)))
966
967 (use-package mwim
968 :bind (("C-a" . mwim-beginning-of-code-or-line)
969 ("C-e" . mwim-end-of-code-or-line)
970 ("<home>" . mwim-beginning-of-line-or-code)
971 ("<end>" . mwim-end-of-line-or-code)))
972
973 (use-package projectile
974 :bind-keymap ("C-c P" . projectile-command-map)
975 :config
976 (projectile-mode)
977
978 (defun my-projectile-invalidate-cache (&rest _args)
979 ;; ignore the args to `magit-checkout'
980 (projectile-invalidate-cache nil))
981
982 (eval-after-load 'magit-branch
983 '(progn
984 (advice-add 'magit-checkout
985 :after #'my-projectile-invalidate-cache)
986 (advice-add 'magit-branch-and-checkout
987 :after #'my-projectile-invalidate-cache)))
988 :custom (projectile-completion-system 'ivy))
989
990 (use-package helpful
991 :defer 0.6
992 :bind
993 (("C-S-h c" . helpful-command)
994 ("C-S-h f" . helpful-callable) ; helpful-function
995 ("C-S-h v" . helpful-variable)
996 ("C-S-h k" . helpful-key)
997 ("C-S-h p" . helpful-at-point)))
998
999 (use-package unkillable-scratch
1000 :defer 0.6
1001 :config
1002 (unkillable-scratch 1)
1003 :custom
1004 (unkillable-buffers '("^\\*scratch\\*$" "^\\*Messages\\*$")))
1005
1006 (use-package boxquote
1007 :defer 0.6
1008 :bind
1009 (:prefix-map a/boxquote-prefix-map
1010 :prefix "C-c q"
1011 ("b" . boxquote-buffer)
1012 ("B" . boxquote-insert-buffer)
1013 ("d" . boxquote-defun)
1014 ("F" . boxquote-insert-file)
1015 ("hf" . boxquote-describe-function)
1016 ("hk" . boxquote-describe-key)
1017 ("hv" . boxquote-describe-variable)
1018 ("hw" . boxquote-where-is)
1019 ("k" . boxquote-kill)
1020 ("p" . boxquote-paragraph)
1021 ("q" . boxquote-boxquote)
1022 ("r" . boxquote-region)
1023 ("s" . boxquote-shell-command)
1024 ("t" . boxquote-text)
1025 ("T" . boxquote-title)
1026 ("u" . boxquote-unbox)
1027 ("U" . boxquote-unbox-region)
1028 ("y" . boxquote-yank)
1029 ("M-q" . boxquote-fill-paragraph)
1030 ("M-w" . boxquote-kill-ring-save)))
1031
1032 (use-package orgalist
1033 :disabled t
1034 :after message
1035 :hook (message-mode . orgalist-mode))
1036
1037 (use-package typo
1038 :defer 0.5
1039 :config
1040 (typo-global-mode 1)
1041 :hook (text-mode . typo-mode))
1042
1043 (use-package hl-todo
1044 :defer 0.5
1045 :config
1046 (global-hl-todo-mode))
1047
1048 (use-package shrink-path
1049 :defer 0.5
1050 :after eshell
1051 :config
1052 (defvar user-@-host (concat (user-login-name) "@" (system-name) " "))
1053 (defun +eshell/prompt ()
1054 (let ((base/dir (shrink-path-prompt default-directory)))
1055 (concat (propertize user-@-host 'face 'default)
1056 (propertize (car base/dir)
1057 'face 'font-lock-comment-face)
1058 (propertize (cdr base/dir)
1059 'face 'font-lock-constant-face)
1060 (propertize "> " 'face 'default))))
1061 (setq eshell-prompt-regexp (concat user-@-host ".*> ")
1062 eshell-prompt-function #'+eshell/prompt))
1063
1064 (use-package eshell-up
1065 :after eshell
1066 :commands eshell-up)
1067
1068 (use-package multi-term
1069 :defer 0.6
1070 :bind (("C-c a s m" . multi-term-dedicated-toggle)
1071 :map term-mode-map
1072 ("C-c C-j" . term-char-mode)
1073 :map term-raw-map
1074 ("C-c C-j" . term-line-mode))
1075 :config
1076 (setq multi-term-program "/bin/screen"
1077 ;; TODO: add separate bindings for connecting to existing
1078 ;; session vs. always creating a new one
1079 multi-term-dedicated-select-after-open-p t
1080 multi-term-dedicated-window-height 20
1081 multi-term-dedicated-max-window-height 30
1082 term-bind-key-alist
1083 '(("C-c C-c" . term-interrupt-subjob)
1084 ("C-c C-e" . term-send-esc)
1085 ("C-k" . kill-line)
1086 ("C-y" . term-paste)
1087 ("M-f" . term-send-forward-word)
1088 ("M-b" . term-send-backward-word)
1089 ("M-p" . term-send-up)
1090 ("M-n" . term-send-down)
1091 ("<C-backspace>" . term-send-backward-kill-word)
1092 ("<M-DEL>" . term-send-backward-kill-word)
1093 ("M-d" . term-send-delete-word)
1094 ("M-," . term-send-raw)
1095 ("M-." . comint-dynamic-complete))
1096 term-unbind-key-alist
1097 '("C-z" "C-x" "C-c" "C-h" "C-y" "<ESC>")))
1098
1099 (use-package page-break-lines
1100 :config
1101 (global-page-break-lines-mode))
1102
1103 (use-package expand-region
1104 :bind ("C-=" . er/expand-region))
1105
1106 (use-package multiple-cursors
1107 :bind
1108 (("C-S-<mouse-1>" . mc/add-cursor-on-click)
1109 (:prefix-map a/mc-prefix-map
1110 :prefix "C-c m"
1111 ("c" . mc/edit-lines)
1112 ("n" . mc/mark-next-like-this)
1113 ("p" . mc/mark-previous-like-this)
1114 ("a" . mc/mark-all-like-this))))
1115
1116 (use-package forge
1117 :after magit
1118 :demand)
1119
1120 (use-package yasnippet
1121 :defer 0.6
1122 :config
1123 (defconst yas-verbosity-cur yas-verbosity)
1124 (setq yas-verbosity 2)
1125 (add-to-list 'yas-snippet-dirs "~/src/git/guix/etc/snippets")
1126 (yas-reload-all)
1127 (setq yas-verbosity yas-verbosity-cur)
1128 :hook
1129 (text-mode . yas-minor-mode))
1130
1131 (use-package debbugs
1132 :straight (debbugs
1133 :host github
1134 :repo "emacs-straight/debbugs"
1135 :files (:defaults "Debbugs.wsdl")))
1136
1137 (use-package org-ref
1138 :init
1139 (a/setq-every '("~/usr/org/references.bib")
1140 reftex-default-bibliography
1141 org-ref-default-bibliography)
1142 (setq
1143 org-ref-bibliography-notes "~/usr/org/notes.org"
1144 org-ref-pdf-directory "~/usr/org/bibtex-pdfs/"))
1145
1146 (use-package slack
1147 :commands (slack-start)
1148 :init
1149 (eval-when-compile ; silence the byte-compiler
1150 (defvar url-http-data nil)
1151 (defvar url-http-extra-headers nil)
1152 (defvar url-http-method nil)
1153 (defvar url-callback-function nil)
1154 (defvar url-callback-arguments nil)
1155 (defvar oauth--token-data nil))
1156 (setq slack-buffer-emojify t
1157 slack-prefer-current-team t)
1158 :config
1159 (slack-register-team
1160 :name "nday-students"
1161 :default t
1162 :token nday-students-token
1163 :subscribed-channels '(general)
1164 :full-and-display-names t)
1165 (add-to-list 'swiper-font-lock-exclude 'slack-message-buffer-mode t)
1166 (setq lui-time-stamp-format "[%Y-%m-%d %H:%M:%S]"
1167 lui-time-stamp-only-when-changed-p t
1168 lui-time-stamp-position 'right)
1169 :bind
1170 (("C-c s s" . slack-start)
1171 ("C-c s u" . slack-select-unread-rooms)
1172 ("C-c s b" . slack-select-rooms)
1173 ("C-c s t" . slack-change-current-team)
1174 ("C-c s c" . slack-ws-close)
1175 :map slack-mode-map
1176 ("M-p" . slack-buffer-goto-prev-message)
1177 ("M-n" . slack-buffer-goto-next-message)
1178 ("C-c e" . slack-message-edit)
1179 ("C-c k" . slack-message-delete)
1180 ("C-c C-k" . slack-channel-leave)
1181 ("C-c r a" . slack-message-add-reaction)
1182 ("C-c r r" . slack-message-remove-reaction)
1183 ("C-c r s" . slack-message-show-reaction-users)
1184 ("C-c p l" . slack-room-pins-list)
1185 ("C-c p a" . slack-message-pins-add)
1186 ("C-c p r" . slack-message-pins-remove)
1187 ("@" . slack-message-embed-mention)
1188 ("#" . slack-message-embed-channel)))
1189
1190 (use-package alert
1191 :commands (alert)
1192 :init
1193 (setq alert-default-style 'notifier))
1194
1195 (defvar a/maildir (expand-file-name "~/mail/"))
1196 (with-eval-after-load 'recentf
1197 (add-to-list 'recentf-exclude a/maildir))
1198
1199 (setq
1200 a/gnus-init-file (no-littering-expand-etc-file-name "gnus")
1201 mail-user-agent 'gnus-user-agent
1202 read-mail-command 'gnus)
1203
1204 (use-feature gnus
1205 :bind (("s-m" . gnus)
1206 ("s-M" . gnus-unplugged))
1207 :init
1208 (setq
1209 gnus-select-method '(nnnil "")
1210 gnus-secondary-select-methods
1211 '((nnimap "amin"
1212 (nnimap-stream plain)
1213 (nnimap-address "127.0.0.1")
1214 (nnimap-server-port 143)
1215 (nnimap-authenticator plain)
1216 (nnimap-user "amin@bndl.org"))
1217 (nnimap "uwaterloo"
1218 (nnimap-stream plain)
1219 (nnimap-address "127.0.0.1")
1220 (nnimap-server-port 143)
1221 (nnimap-authenticator plain)
1222 (nnimap-user "abandali@uwaterloo.ca"))
1223 (nnimap "csclub"
1224 (nnimap-stream plain)
1225 (nnimap-address "127.0.0.1")
1226 (nnimap-server-port 143)
1227 (nnimap-authenticator plain)
1228 (nnimap-user "abandali@csclub.uw")))
1229 gnus-message-archive-group "nnimap+amin:Sent"
1230 gnus-parameters
1231 '(("gnu\\.deepspec"
1232 (to-address . "deepspec@lists.cs.princeton.edu")
1233 (to-list . "deepspec@lists.cs.princeton.edu"))
1234 ("gnu\\.emacs-devel"
1235 (to-address . "emacs-devel@gnu.org")
1236 (to-list . "emacs-devel@gnu.org"))
1237 ("gnu\\.emacs-orgmode"
1238 (to-address . "emacs-orgmode@gnu.org")
1239 (to-list . "emacs-orgmode@gnu.org"))
1240 ("gnu\\.emacsconf-discuss"
1241 (to-address . "emacsconf-discuss@gnu.org")
1242 (to-list . "emacsconf-discuss@gnu.org"))
1243 ("gnu\\.fencepost-users"
1244 (to-address . "fencepost-users@gnu.org")
1245 (to-list . "fencepost-users@gnu.org"))
1246 ("gnu\\.gnunet-developers"
1247 (to-address . "gnunet-developers@gnu.org")
1248 (to-list . "gnunet-developers@gnu.org"))
1249 ("gnu\\.guile-devel"
1250 (to-address . "guile-devel@gnu.org")
1251 (to-list . "guile-devel@gnu.org"))
1252 ("gnu\\.guix-devel"
1253 (to-address . "guix-devel@gnu.org")
1254 (to-list . "guix-devel@gnu.org"))
1255 ("gnu\\.haskell-art"
1256 (to-address . "haskell-art@we.lurk.org")
1257 (to-list . "haskell-art@we.lurk.org"))
1258 ("gnu\\.haskell-cafe"
1259 (to-address . "haskell-cafe@haskell.org")
1260 (to-list . "haskell-cafe@haskell.org"))
1261 ("gnu\\.help-gnu-emacs"
1262 (to-address . "help-gnu-emacs@gnu.org")
1263 (to-list . "help-gnu-emacs@gnu.org"))
1264 ("gnu\\.info-gnu-emacs"
1265 (to-address . "info-gnu-emacs@gnu.org")
1266 (to-list . "info-gnu-emacs@gnu.org"))
1267 ("gnu\\.info-guix"
1268 (to-address . "info-guix@gnu.org")
1269 (to-list . "info-guix@gnu.org"))
1270 ("gnu\\.notmuch"
1271 (to-address . "notmuch@notmuchmail.org")
1272 (to-list . "notmuch@notmuchmail.org"))
1273 ("gnu\\.parabola-dev"
1274 (to-address . "dev@lists.parabola.nu")
1275 (to-list . "dev@lists.parabola.nu"))
1276 ("gnu\\.webmasters"
1277 (to-address . "webmasters@gnu.org")
1278 (to-list . "webmasters@gnu.org"))
1279 ("gnu\\.www-commits"
1280 (to-address . "www-commits@gnu.org")
1281 (to-list . "www-commits@gnu.org"))
1282 ("gnu\\.www-discuss"
1283 (to-address . "www-discuss@gnu.org")
1284 (to-list . "www-discuss@gnu.org"))
1285 ("gnu\\.~bandali\\.public-inbox"
1286 (to-address . "~bandali/public-inbox@lists.sr.ht")
1287 (to-list . "~bandali/public-inbox@lists.sr.ht"))
1288 ("gnu\\.~sircmpwn\\.srht-admins"
1289 (to-address . "~sircmpwn/sr.ht-admins@lists.sr.ht")
1290 (to-list . "~sircmpwn/sr.ht-admins@lists.sr.ht"))
1291 ("gnu\\.~sircmpwn\\.srht-announce"
1292 (to-address . "~sircmpwn/sr.ht-announce@lists.sr.ht")
1293 (to-list . "~sircmpwn/sr.ht-announce@lists.sr.ht"))
1294 ("gnu\\.~sircmpwn\\.srht-dev"
1295 (to-address . "~sircmpwn/sr.ht-dev@lists.sr.ht")
1296 (to-list . "~sircmpwn/sr.ht-dev@lists.sr.ht"))
1297 ("gnu\\.~sircmpwn\\.srht-discuss"
1298 (to-address . "~sircmpwn/sr.ht-discuss@lists.sr.ht")
1299 (to-list . "~sircmpwn/sr.ht-discuss@lists.sr.ht"))
1300 ("gnu.*"
1301 (gcc-self . t))
1302 ("gnu\\."
1303 (subscribed . t)))
1304 gnus-large-newsgroup 50
1305 gnus-home-directory (no-littering-expand-var-file-name "gnus/")
1306 gnus-directory (concat gnus-home-directory "news/")
1307 message-directory (concat gnus-home-directory "mail/")
1308 nndraft-directory (concat gnus-home-directory "drafts/")
1309 gnus-save-newsrc-file nil
1310 gnus-read-newsrc-file nil
1311 gnus-interactive-exit nil
1312 gnus-gcc-mark-as-read t)
1313 :config
1314 (require 'ebdb)
1315 (require 'ebdb-mua)
1316 (require 'ebdb-gnus)
1317
1318 (with-eval-after-load 'recentf
1319 (add-to-list 'recentf-exclude gnus-home-directory)))
1320
1321 (use-feature gnus-art
1322 :config
1323 (setq
1324 gnus-visible-headers
1325 (concat gnus-visible-headers "\\|^List-Id:\\|^X-RT-Originator:\\|^User-Agent:")
1326 gnus-sorted-header-list
1327 '("^From:" "^Subject:" "^Summary:" "^Keywords:"
1328 "^Followup-To:" "^To:" "^Cc:" "X-RT-Originator"
1329 "^Newsgroups:" "List-Id:" "^Organization:"
1330 "^User-Agent:" "^Date:")
1331 ;; local-lapsed article dates
1332 ;; from https://www.emacswiki.org/emacs/GnusFormatting#toc11
1333 gnus-article-date-headers '(user-defined)
1334 gnus-article-time-format
1335 (lambda (time)
1336 (let* ((date (format-time-string "%a, %d %b %Y %T %z" time))
1337 (local (article-make-date-line date 'local))
1338 (combined-lapsed (article-make-date-line date
1339 'combined-lapsed))
1340 (lapsed (progn
1341 (string-match " (.+" combined-lapsed)
1342 (match-string 0 combined-lapsed))))
1343 (concat local lapsed))))
1344 (bind-keys
1345 :map gnus-article-mode-map
1346 ("M-L" . org-store-link)))
1347
1348 (use-feature gnus-sum
1349 :bind (:map gnus-summary-mode-map
1350 :prefix-map a/gnus-summary-prefix-map
1351 :prefix "v"
1352 ("r" . gnus-summary-reply)
1353 ("w" . gnus-summary-wide-reply)
1354 ("v" . gnus-summary-show-raw-article))
1355 :config
1356 (bind-keys
1357 :map gnus-summary-mode-map
1358 ("M-L" . org-store-link))
1359 :hook (gnus-summary-mode . a/no-mouse-autoselect-window))
1360
1361 (use-feature gnus-msg
1362 :config
1363 (setq gnus-posting-styles
1364 '((".*"
1365 (address "amin@bndl.org")
1366 (body "\nBest,\n")
1367 (eval (setq a/message-cite-say-hi t)))
1368 ("gnu.*"
1369 (address "bandali@gnu.org")
1370 (eval (set (make-local-variable 'message-user-fqdn) "fencepost.gnu.org")))
1371 ((header "subject" "ThankCRM")
1372 (to "webmasters-comment@gnu.org")
1373 (body "Added to 2019supporters.html.\n\nMoving to campaigns.\n\n-amin\n")
1374 (eval (setq a/message-cite-say-hi nil)))
1375 ("nnimap\\+uwaterloo:.*"
1376 (address "abandali@uwaterloo.ca")
1377 (gcc "\"nnimap+uwaterloo:Sent Items\""))
1378 ("nnimap\\+csclub:.*"
1379 (address "abandali@csclub.uwaterloo.ca")
1380 (gcc "nnimap+csclub:Sent")))))
1381
1382 (use-feature gnus-topic
1383 :hook (gnus-group-mode . gnus-topic-mode)
1384 :config (setq gnus-topic-line-format "%i[ %A: %(%{%n%}%) ]%v\n"))
1385
1386 (use-feature gnus-agent
1387 :config
1388 (setq gnus-agent-synchronize-flags 'ask)
1389 :hook (gnus-group-mode . gnus-agent-mode))
1390
1391 (use-feature gnus-group
1392 :config
1393 (setq gnus-permanently-visible-groups "\\(:INBOX$\\|:gnu$\\)"))
1394
1395 (use-feature mm-decode
1396 :config
1397 (setq mm-discouraged-alternatives '("text/html" "text/richtext")))
1398
1399 (use-feature sendmail
1400 :config
1401 (setq sendmail-program "/usr/bin/msmtp"
1402 ;; message-sendmail-extra-arguments '("-v" "-d")
1403 mail-specify-envelope-from t
1404 mail-envelope-from 'header))
1405
1406 (use-feature message
1407 :config
1408 ;; redefine for a simplified In-Reply-To header
1409 ;; (see https://todo.sr.ht/~sircmpwn/lists.sr.ht/67)
1410 (defun message-make-in-reply-to ()
1411 "Return the In-Reply-To header for this message."
1412 (when message-reply-headers
1413 (let ((from (mail-header-from message-reply-headers))
1414 (msg-id (mail-header-id message-reply-headers)))
1415 (when from
1416 msg-id))))
1417
1418 (defconst a/message-cite-style-format "On %Y-%m-%d %l:%M %p, %N wrote:")
1419 (defconst message-cite-style-bandali
1420 '((message-cite-function 'message-cite-original)
1421 (message-citation-line-function 'message-insert-formatted-citation-line)
1422 (message-cite-reply-position 'traditional)
1423 (message-yank-prefix "> ")
1424 (message-yank-cited-prefix ">")
1425 (message-yank-empty-prefix ">")
1426 (message-citation-line-format
1427 (if a/message-cite-say-hi
1428 (concat "Hi %F,\n\n" a/message-cite-style-format)
1429 a/message-cite-style-format)))
1430 "Citation style based on Mozilla Thunderbird's. Use with message-cite-style.")
1431 (setq ;; message-cite-style 'message-cite-style-bandali
1432 message-kill-buffer-on-exit t
1433 message-send-mail-function 'message-send-mail-with-sendmail
1434 message-sendmail-envelope-from 'header
1435 message-subscribed-address-functions
1436 '(gnus-find-subscribed-addresses)
1437 message-dont-reply-to-names
1438 "\\(\\(amin@bndl\\.org\\)\\|\\(.*@\\(aminb\\|amin\\.bndl\\)\\.org\\)\\|\\(\\(bandali\\|aminb?\\|mab\\)@gnu\\.org\\)\\|\\(a\\(min\\.\\)?bandali@uwaterloo\\.ca\\)\\|\\(abandali@csclub\\.uwaterloo\\.ca\\)\\)")
1439 (require 'company-ebdb)
1440 :hook (;; (message-setup . mml-secure-message-sign-pgpmime)
1441 (message-mode . flyspell-mode)
1442 (message-mode . (lambda ()
1443 ;; (setq fill-column 65
1444 ;; message-fill-column 65)
1445 (make-local-variable 'company-idle-delay)
1446 (setq company-idle-delay 0.2))))
1447 ;; :custom-face
1448 ;; (message-header-subject ((t (:foreground "#111" :weight semi-bold))))
1449 ;; (message-header-to ((t (:foreground "#111" :weight normal))))
1450 ;; (message-header-cc ((t (:foreground "#333" :weight normal))))
1451 )
1452
1453 (with-eval-after-load 'mml-sec
1454 (setq mml-secure-openpgp-encrypt-to-self t
1455 mml-secure-openpgp-sign-with-sender t))
1456
1457 (use-feature footnote
1458 :after message
1459 ;; :config
1460 ;; (setq footnote-start-tag ""
1461 ;; footnote-end-tag ""
1462 ;; footnote-style 'unicode)
1463 :bind
1464 (:map message-mode-map
1465 :prefix-map a/footnote-prefix-map
1466 :prefix "C-c f"
1467 ("a" . footnote-add-footnote)
1468 ("b" . footnote-back-to-message)
1469 ("c" . footnote-cycle-style)
1470 ("d" . footnote-delete-footnote)
1471 ("g" . footnote-goto-footnote)
1472 ("r" . footnote-renumber-footnotes)
1473 ("s" . footnote-set-style)))
1474
1475 (use-package ebdb
1476 :straight (:host github :repo "girzel/ebdb")
1477 :after gnus
1478 :bind (:map gnus-group-mode-map ("e" . ebdb))
1479 :config
1480 (setq ebdb-sources (no-littering-expand-var-file-name "ebdb"))
1481 (with-eval-after-load 'swiper
1482 (add-to-list 'swiper-font-lock-exclude 'ebdb-mode t)))
1483
1484 (use-feature ebdb-com
1485 :after ebdb)
1486
1487 ;; (use-package ebdb-complete
1488 ;; :after ebdb
1489 ;; :config
1490 ;; (ebdb-complete-enable))
1491
1492 (use-package company-ebdb
1493 :config
1494 (defun company-ebdb--post-complete (_) nil))
1495
1496 (use-feature ebdb-gnus
1497 :after ebdb
1498 :custom
1499 (ebdb-gnus-window-configuration
1500 '(article
1501 (vertical 1.0
1502 (summary 0.25 point)
1503 (horizontal 1.0
1504 (article 1.0)
1505 (ebdb-gnus 0.3))))))
1506
1507 (use-feature ebdb-mua
1508 :after ebdb
1509 ;; :custom (ebdb-mua-pop-up nil)
1510 )
1511
1512 ;; (use-package ebdb-message
1513 ;; :after ebdb)
1514
1515
1516 ;; (use-package ebdb-vcard
1517 ;; :after ebdb)
1518
1519 (use-package message-x)
1520
1521 (use-package znc
1522 :straight (:host nil :repo "https://git.bndl.org/amin/znc.el")
1523 :bind (("C-c a e e" . znc-erc)
1524 ("C-c a e a" . znc-all))
1525 :config
1526 (let ((pwd (let ((auth (auth-source-search :host "znca")))
1527 (cond
1528 ((null auth) (error "Couldn't find znca's authinfo"))
1529 (t (funcall (plist-get (car auth) :secret)))))))
1530 (setq znc-servers
1531 `(("znc.bndl.org" 1337 t
1532 ((freenode "amin/freenode" ,pwd)))
1533 ("znc.bndl.org" 1337 t
1534 ((moznet "amin/moznet" ,pwd)))))))
1535
1536 (message "Loading %s...done (%.3fs)" user-init-file
1537 (float-time (time-subtract (current-time)
1538 a/before-user-init-time)))
1539
1540 ;;; init.el ends here