41c9ec5bdf835fd4dba0e37a6df4fad223576776
[~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. Uses straight.el for
22 ;; purely functional and fully reproducible package management.
23
24 ;; Over the years, I've taken inspiration from configurations of many
25 ;; great people. Some that I can remember off the top of my head are:
26 ;;
27 ;; - https://github.com/dieggsy/dotfiles
28 ;; - https://github.com/dakra/dmacs
29 ;; - http://pages.sachachua.com/.emacs.d/Sacha.html
30 ;; - https://github.com/dakrone/eos
31 ;; - http://doc.rix.si/cce/cce.html
32 ;; - https://github.com/jwiegley/dot-emacs
33 ;; - https://github.com/wasamasa/dotemacs
34 ;; - https://github.com/hlissner/doom-emacs
35
36 ;;; Code:
37
38 ;;; Emacs initialization
39
40 (defvar a/before-user-init-time (current-time)
41 "Value of `current-time' when Emacs begins loading `user-init-file'.")
42 (message "Loading Emacs...done (%.3fs)"
43 (float-time (time-subtract a/before-user-init-time
44 before-init-time)))
45
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.
49 (defvar a/gc-cons-threshold gc-cons-threshold)
50 (defvar a/gc-cons-percentage gc-cons-percentage)
51 (defvar a/file-name-handler-alist file-name-handler-alist)
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
58 ;; set them back to their defaults once we're done initializing
59 (add-hook
60 'after-init-hook
61 (lambda ()
62 (setq gc-cons-threshold a/gc-cons-threshold
63 gc-cons-percentage a/gc-cons-percentage
64 file-name-handler-alist a/file-name-handler-alist)))
65
66 ;; increase number of lines kept in *Messages* log
67 (setq message-log-max 20000)
68
69 ;; optionally, uncomment to supress some byte-compiler warnings
70 ;; (see C-h v byte-compile-warnings RET for more info)
71 ;; (setq byte-compile-warnings
72 ;; '(not free-vars unresolved noruntime lexical make-local))
73
74 \f
75 ;;; whoami
76
77 (setq user-full-name "Amin Bandali"
78 user-mail-address "amin@bndl.org")
79
80 \f
81 ;;; comment macro
82
83 ;; useful for commenting out multiple sexps at a time
84 (defmacro comment (&rest _)
85 "Comment out one or more s-expressions."
86 (declare (indent defun))
87 nil)
88
89 \f
90 ;;; Package management
91
92 ;; No package.el (for emacs 26 and before, uncomment the following)
93 ;; Not necessary when using straight.el
94 ;; (C-h v straight-package-neutering-mode RET)
95
96 (when (and
97 (not (featurep 'straight))
98 (version< emacs-version "27"))
99 (setq package-enable-at-startup nil)
100 ;; (package-initialize)
101 )
102
103 ;; for emacs 27 and later, we use early-init.el. see
104 ;; https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=24acb31c04b4048b85311d794e600ecd7ce60d3b
105
106 ;; straight.el
107
108 ;; Main engine start...
109
110 (setq straight-repository-branch "develop"
111 straight-check-for-modifications '(check-on-save find-when-checking))
112
113 (defun a/bootstrap-straight ()
114 (defvar bootstrap-version)
115 (let ((bootstrap-file
116 (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
117 (bootstrap-version 5))
118 (unless (file-exists-p bootstrap-file)
119 (with-current-buffer
120 (url-retrieve-synchronously
121 "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
122 'silent 'inhibit-cookies)
123 (goto-char (point-max))
124 (eval-print-last-sexp)))
125 (load bootstrap-file nil 'nomessage)))
126
127 ;; Solid rocket booster ignition...
128
129 (a/bootstrap-straight)
130
131 ;; We have lift off!
132
133 (setq straight-use-package-by-default t)
134
135 (defmacro use-feature (name &rest args)
136 "Like `use-package', but with `straight-use-package-by-default' disabled."
137 (declare (indent defun))
138 `(use-package ,name
139 :straight nil
140 ,@args))
141
142 (with-eval-after-load 'recentf
143 (add-to-list 'recentf-exclude
144 (expand-file-name "~/.emacs.d/straight/build/")))
145
146 (defun a/reload-init ()
147 "Reload init.el."
148 (interactive)
149 (straight-transaction
150 (straight-mark-transaction-as-init)
151 (load user-init-file)))
152
153 ;; use-package
154 (straight-use-package 'use-package)
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
168 ;; for browsing the Emacsmirror package database
169 (comment
170 (use-package epkg
171 :commands (epkg-list-packages epkg-describe-package)
172 :bind
173 (("C-c p e d" . epkg-describe-package)
174 ("C-c p e p" . epkg-list-packages))
175 :config
176 (setq epkg-repository "~/.emacs.d/straight/repos/epkgs/")
177 (eval-when-compile (defvar ivy-initial-inputs-alist))
178 (with-eval-after-load 'ivy
179 (add-to-list
180 'ivy-initial-inputs-alist '(epkg-describe-package . "^") t))))
181
182 \f
183 ;;; Initial setup
184
185 ;; keep ~/.emacs.d clean
186 (use-package no-littering
187 :demand t
188 :config
189 (savehist-mode 1)
190 (add-to-list 'savehist-additional-variables 'kill-ring)
191 (save-place-mode 1)
192 (setq auto-save-file-name-transforms
193 `((".*" ,(no-littering-expand-var-file-name "auto-save/") t))))
194
195 ;; separate custom file (don't want it mixing with init.el)
196 (use-feature custom
197 :no-require t
198 :config
199 (setq custom-file (no-littering-expand-etc-file-name "custom.el"))
200 (when (file-exists-p custom-file)
201 (load custom-file))
202 ;; while at it, treat themes as safe
203 (setf custom-safe-themes t))
204
205 ;; load the secrets file if it exists, otherwise show a warning
206 (with-demoted-errors
207 (load (no-littering-expand-etc-file-name "secrets")))
208
209 ;; better $PATH (and other environment variable) handling
210 (use-package exec-path-from-shell
211 :defer 0.4
212 :init
213 (setq exec-path-from-shell-arguments nil
214 exec-path-from-shell-check-startup-files nil)
215 :config
216 (exec-path-from-shell-initialize)
217 ;; while we're at it, let's fix access to our running ssh-agent
218 (exec-path-from-shell-copy-env "SSH_AGENT_PID")
219 (exec-path-from-shell-copy-env "SSH_AUTH_SOCK"))
220
221 ;; only one custom theme at a time
222 (comment
223 (defadvice load-theme (before clear-previous-themes activate)
224 "Clear existing theme settings instead of layering them"
225 (mapc #'disable-theme custom-enabled-themes)))
226
227 ;; start up emacs server. see
228 ;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Server.html#Emacs-Server
229 (use-feature server
230 :defer 0.4
231 :config (or (server-running-p) (server-mode)))
232
233 ;; unicode support
234 (comment
235 (dolist (ft (fontset-list))
236 (set-fontset-font
237 ft
238 'unicode
239 (font-spec :name "Source Code Pro" :size 14))
240 (set-fontset-font
241 ft
242 'unicode
243 (font-spec :name "DejaVu Sans Mono")
244 nil
245 'append)
246 ;; (set-fontset-font
247 ;; ft
248 ;; 'unicode
249 ;; (font-spec
250 ;; :name "Symbola monospacified for DejaVu Sans Mono")
251 ;; nil
252 ;; 'append)
253 ;; (set-fontset-font
254 ;; ft
255 ;; #x2115 ; ℕ
256 ;; (font-spec :name "DejaVu Sans Mono")
257 ;; nil
258 ;; 'append)
259 (set-fontset-font
260 ft
261 (cons ?Α ?ω)
262 (font-spec :name "DejaVu Sans Mono" :size 14)
263 nil
264 'prepend)))
265
266 ;; gentler font resizing
267 (setq text-scale-mode-step 1.05)
268
269 ;; focus follows mouse
270 (setq mouse-autoselect-window t)
271
272 (defun a/no-mouse-autoselect-window ()
273 "Conveniently disable `focus-follows-mouse'.
274 For disabling the behaviour for certain buffers and/or modes."
275 (make-local-variable 'mouse-autoselect-window)
276 (setq mouse-autoselect-window nil))
277
278 ;; better scrolling
279 (setq ;; scroll-margin 1
280 ;; scroll-conservatively 10000
281 scroll-step 1
282 scroll-conservatively 10
283 scroll-preserve-screen-position 1)
284
285 (use-feature mwheel
286 :defer 0.4
287 :config
288 (setq mouse-wheel-scroll-amount '(1 ((shift) . 1)) ; one line at a time
289 mouse-wheel-progressive-speed nil ; don't accelerate scrolling
290 mouse-wheel-follow-mouse t)) ; scroll window under mouse
291
292 (use-feature pixel-scroll
293 :defer 0.4
294 :config (pixel-scroll-mode 1))
295
296 ;; ask for GPG passphrase in minibuffer
297 (setq epg-pinentry-mode 'loopback)
298
299 ;; useful libraries
300 (require 'cl-lib)
301 (require 'subr-x)
302
303 \f
304 ;;; Useful utilities
305
306 (defmacro a/setq-every (value &rest vars)
307 "Set all the variables from VARS to value VALUE."
308 (declare (indent defun) (debug t))
309 `(progn ,@(mapcar (lambda (x) (list 'setq x value)) vars)))
310
311 (defun a/start-process (program &rest args)
312 "Same as `start-process', but doesn't bother about name and buffer."
313 (let ((process-name (concat program "_process"))
314 (buffer-name (generate-new-buffer-name
315 (concat program "_output"))))
316 (apply #'start-process
317 process-name buffer-name program args)))
318
319 (defun a/dired-start-process (program &optional args)
320 "Open current file with a PROGRAM."
321 ;; Shell command looks like this: "program [ARGS]... FILE" (ARGS can
322 ;; be nil, so remove it).
323 (apply #'a/start-process
324 program
325 (remove nil (list args (dired-get-file-for-visit)))))
326
327 (defun a/add-elisp-section ()
328 (interactive)
329 (insert "\n")
330 (previous-line)
331 (insert "\n\f\n;;; "))
332
333 \f
334 ;;; Defaults
335
336 ;; time and battery in mode-line
337 (comment
338 (use-package time
339 :init
340 (setq display-time-default-load-average nil)
341 :config
342 (display-time-mode))
343
344 (use-package battery
345 :config
346 (display-battery-mode)))
347
348 ;; smaller fringe
349 ;; (fringe-mode '(3 . 1))
350 (fringe-mode nil)
351
352 ;; disable disabled commands
353 (setq disabled-command-function nil)
354
355 ;; Save what I copy into clipboard from other applications into Emacs'
356 ;; kill-ring, which would allow me to still be able to easily access
357 ;; it in case I kill (cut or copy) something else inside Emacs before
358 ;; yanking (pasting) what I'd originally intended to.
359 (setq save-interprogram-paste-before-kill t)
360
361 ;; minibuffer
362 (setq enable-recursive-minibuffers t
363 resize-mini-windows t)
364
365 ;; lazy-person-friendly yes/no prompts
366 (defalias 'yes-or-no-p #'y-or-n-p)
367
368 ;; i want *scratch* as my startup buffer
369 (setq initial-buffer-choice t)
370
371 ;; i don't need the default hint
372 (setq initial-scratch-message nil)
373
374 ;; use customizable text-mode as major mode for *scratch*
375 (setq initial-major-mode 'text-mode)
376
377 ;; inhibit buffer list when more than 2 files are loaded
378 (setq inhibit-startup-buffer-menu t)
379
380 ;; don't need to see the startup screen or the echo area message
381 (advice-add #'display-startup-echo-area-message :override #'ignore)
382 (setq inhibit-startup-screen t
383 inhibit-startup-echo-area-message user-login-name)
384
385 ;; more useful frame titles
386 (setq frame-title-format
387 '("" invocation-name " - "
388 (:eval (if (buffer-file-name)
389 (abbreviate-file-name (buffer-file-name))
390 "%b"))))
391
392 ;; backups (C-h v make-backup-files RET)
393 (setq backup-by-copying t
394 version-control t
395 delete-old-versions t)
396
397 ;; enable automatic reloading of changed buffers and files
398 (global-auto-revert-mode 1)
399 (setq auto-revert-verbose nil
400 global-auto-revert-non-file-buffers nil)
401
402 ;; always use space for indentation
403 (setq-default
404 indent-tabs-mode nil
405 require-final-newline t
406 tab-width 4)
407
408 ;; enable winner-mode (C-h f winner-mode RET)
409 (winner-mode 1)
410
411 ;; don't display *compilation* buffer on success. based on
412 ;; https://stackoverflow.com/a/17788551, with changes to use `cl-letf'
413 ;; instead of the now obsolete `flet'.
414 (with-eval-after-load 'compile
415 (defun a/compilation-finish-function (buffer outstr)
416 (unless (string-match "finished" outstr)
417 (switch-to-buffer-other-window buffer))
418 t)
419
420 (setq compilation-finish-functions #'a/compilation-finish-function)
421
422 (require 'cl-macs)
423
424 (defadvice compilation-start
425 (around inhibit-display
426 (command &optional mode name-function highlight-regexp))
427 (if (not (string-match "^\\(find\\|grep\\)" command))
428 (cl-letf (((symbol-function 'display-buffer) #'ignore))
429 (save-window-excursion ad-do-it))
430 ad-do-it))
431 (ad-activate 'compilation-start))
432
433 ;; search for non-ASCII characters: i’d like non-ASCII characters such
434 ;; as ‘’“”«»‹›áⓐ𝒶 to be selected when i search for their ASCII
435 ;; counterpart. shoutout to
436 ;; http://endlessparentheses.com/new-in-emacs-25-1-easily-search-non-ascii-characters.html
437 (setq search-default-mode #'char-fold-to-regexp)
438 ;; uncomment to extend this behaviour to query-replace
439 ;; (setq replace-char-fold t)
440
441 ;; cursor shape
442 (setq-default cursor-type 'bar)
443
444 ;; allow scrolling in Isearch
445 (setq isearch-allow-scroll t)
446
447 \f
448 ;;; General bindings
449
450 (bind-keys
451 ("C-c a i" . ielm)
452
453 ("C-c e b" . eval-buffer)
454 ("C-c e r" . eval-region)
455
456 ("C-c e i" . emacs-init-time)
457 ("C-c e u" . emacs-uptime)
458
459 ("C-c F m" . make-frame-command)
460 ("C-c F d" . delete-frame)
461 ("C-c F D" . delete-other-frames)
462
463 ("C-c o" . other-window)
464
465 ("C-S-h C" . describe-char)
466 ("C-S-h F" . describe-face)
467
468 ("C-x k" . kill-this-buffer)
469 ("C-x K" . kill-buffer)
470
471 ("s-p" . beginning-of-buffer)
472 ("s-n" . end-of-buffer)
473
474 :map emacs-lisp-mode-map
475 ("<C-return>" . a/add-elisp-section))
476
477 (when (display-graphic-p)
478 (unbind-key "C-z" global-map))
479
480 (bind-keys
481 :prefix-map a/straight-prefix-map
482 :prefix "C-c p s"
483 ("u" . straight-use-package)
484 ("f" . straight-freeze-versions)
485 ("t" . straight-thaw-versions)
486 ("P" . straight-prune-build)
487 ("g" . straight-get-recipe)
488 ("r" . a/reload-init)
489 ;; M-x ^straight-.*-all$
490 ("a c" . straight-check-all)
491 ("a f" . straight-fetch-all)
492 ("a m" . straight-merge-all)
493 ("a n" . straight-normalize-all)
494 ("a F" . straight-pull-all)
495 ("a P" . straight-push-all)
496 ("a r" . straight-rebuild-all)
497 ;; M-x ^straight-.*-package$
498 ("p c" . straight-check-package)
499 ("p f" . straight-fetch-package)
500 ("p m" . straight-merge-package)
501 ("p n" . straight-normalize-package)
502 ("p F" . straight-pull-package)
503 ("p P" . straight-push-package)
504 ("p r" . straight-rebuild-package))
505
506 \f
507 ;;; Essential packages
508
509 (use-package auto-compile
510 :demand t
511 :config
512 (auto-compile-on-load-mode)
513 (auto-compile-on-save-mode)
514 (setq auto-compile-display-buffer nil
515 auto-compile-mode-line-counter t
516 auto-compile-source-recreate-deletes-dest t
517 auto-compile-toggle-deletes-nonlib-dest t
518 auto-compile-update-autoloads t)
519 (add-hook 'auto-compile-inhibit-compile-hook
520 'auto-compile-inhibit-compile-detached-git-head))
521
522 ;; use the org-plus-contrib package to get the whole deal
523 (straight-use-package 'org-plus-contrib)
524
525 (use-feature org
526 :defer 0.5
527 :config
528 (setq org-src-tab-acts-natively t
529 org-src-preserve-indentation nil
530 org-edit-src-content-indentation 0
531 org-link-email-description-format "Email %c: %s" ; %.30s
532 org-highlight-latex-and-related '(entities)
533 org-use-speed-commands t
534 org-startup-folded 'content
535 org-catch-invisible-edits 'show-and-error
536 org-log-done 'time)
537 (add-to-list 'org-structure-template-alist '("L" . "src emacs-lisp") t)
538 :bind
539 (("C-c a o a" . org-agenda)
540 :map org-mode-map
541 ("M-L" . org-insert-last-stored-link)
542 ("s-T" . org-todo))
543 :hook ((org-mode . org-indent-mode)
544 (org-mode . auto-fill-mode)
545 (org-mode . flyspell-mode))
546 :custom
547 (org-agenda-files '("~/usr/org/todos/personal.org"
548 "~/usr/org/todos/masters.org"))
549 (org-agenda-start-on-weekday 0)
550 (org-latex-packages-alist '(("" "listings") ("" "color")))
551 :custom-face
552 '(org-block-begin-line ((t (:foreground "#5a5b5a" :background "#1d1f21"))))
553 '(org-block ((t (:background "#1d1f21"))))
554 '(org-latex-and-related ((t (:foreground "#b294bb")))))
555
556 (use-feature ox-latex
557 :after ox
558 :config
559 (setq org-latex-listings 'listings
560 ;; org-latex-prefer-user-labels t
561 )
562 (add-to-list 'org-latex-classes
563 '("IEEEtran" "\\documentclass[11pt]{IEEEtran}"
564 ("\\section{%s}" . "\\section*{%s}")
565 ("\\subsection{%s}" . "\\subsection*{%s}")
566 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
567 ("\\paragraph{%s}" . "\\paragraph*{%s}")
568 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
569 t)
570 (require 'ox-beamer))
571
572 (use-feature ox-extra
573 :config
574 (ox-extras-activate '(latex-header-blocks ignore-headlines)))
575
576 ;; asynchronous tangle, using emacs-async to asynchronously tangle an
577 ;; org file. closely inspired by
578 ;; https://github.com/dieggsy/dotfiles/tree/cc10edf7701958eff1cd94d4081da544d882a28c/emacs.d#dotfiles
579 (with-eval-after-load 'org
580 (defvar a/show-async-tangle-results nil
581 "Keep *emacs* async buffers around for later inspection.")
582
583 (defvar a/show-async-tangle-time nil
584 "Show the time spent tangling the file.")
585
586 (defun a/async-babel-tangle ()
587 "Tangle org file asynchronously."
588 (interactive)
589 (let* ((file-tangle-start-time (current-time))
590 (file (buffer-file-name))
591 (file-nodir (file-name-nondirectory file))
592 ;; (async-quiet-switch "-q")
593 (file-noext (file-name-sans-extension file)))
594 (async-start
595 `(lambda ()
596 (require 'org)
597 (org-babel-tangle-file ,file))
598 (unless a/show-async-tangle-results
599 `(lambda (result)
600 (if result
601 (message "Tangled %s%s"
602 ,file-nodir
603 (if a/show-async-tangle-time
604 (format " (%.3fs)"
605 (float-time (time-subtract (current-time)
606 ',file-tangle-start-time)))
607 ""))
608 (message "Tangling %s failed" ,file-nodir))))))))
609
610 (add-to-list
611 'safe-local-variable-values
612 '(eval add-hook 'after-save-hook #'a/async-babel-tangle 'append 'local))
613
614 ;; *the* right way to do git
615 (use-package magit
616 :defer 0.5
617 :bind (("C-x g" . magit-status)
618 ("s-g s" . magit-status)
619 ("s-g l" . magit-log-buffer-file))
620 :config
621 (magit-add-section-hook 'magit-status-sections-hook
622 'magit-insert-modules
623 'magit-insert-stashes
624 'append)
625 (setq magit-repository-directories '(("~/" . 0)
626 ("~/src/git/" . 1)))
627 (nconc magit-section-initial-visibility-alist
628 '(([unpulled status] . show)
629 ([unpushed status] . show)))
630 :custom (magit-display-buffer-function #'magit-display-buffer-fullframe-status-v1)
631 :custom-face (magit-diff-file-heading ((t (:weight normal)))))
632
633 ;; recently opened files
634 (use-feature recentf
635 :defer 0.2
636 :config
637 (add-to-list 'recentf-exclude "^/\\(?:ssh\\|su\\|sudo\\)?:")
638 (setq recentf-max-saved-items 40))
639
640 ;; smart M-x enhancement (needed by counsel for history)
641 (use-package smex)
642
643 (use-package ivy
644 :defer 0.3
645 :bind
646 (:map ivy-minibuffer-map
647 ([escape] . keyboard-escape-quit)
648 ([S-up] . ivy-previous-history-element)
649 ([S-down] . ivy-next-history-element)
650 ("DEL" . ivy-backward-delete-char))
651 :config
652 (setq ivy-wrap t
653 ivy-height 14
654 ivy-use-virtual-buffers t
655 ivy-virtual-abbreviate 'abbreviate
656 ivy-count-format "%d/%d ")
657 (ivy-mode 1)
658 ;; :custom-face
659 ;; (ivy-minibuffer-match-face-2 ((t (:background "#e99ce8" :weight semi-bold))))
660 ;; (ivy-minibuffer-match-face-3 ((t (:background "#bbbbff" :weight semi-bold))))
661 ;; (ivy-minibuffer-match-face-4 ((t (:background "#ffbbff" :weight semi-bold))))
662 )
663
664 (use-package swiper
665 :after ivy
666 :bind (("C-s" . swiper-isearch)
667 ("C-r" . swiper)
668 ("C-S-s" . isearch-forward)))
669
670 (use-package counsel
671 :after ivy
672 :bind (([remap execute-extended-command] . counsel-M-x)
673 ([remap find-file] . counsel-find-file)
674 ("C-c x" . counsel-M-x)
675 ("C-c f ." . counsel-find-file)
676 ("C-c f l" . counsel-find-library)
677 ("C-c f r" . counsel-recentf)
678 ("s-." . counsel-find-file)
679 ("s-r" . ivy-switch-buffer)
680 :map minibuffer-local-map
681 ("C-r" . counsel-minibuffer-history))
682 :config
683 (counsel-mode 1)
684 (defalias 'locate #'counsel-locate))
685
686 (comment
687 (use-package helm
688 :commands (helm-M-x helm-mini helm-resume)
689 :bind (("M-x" . helm-M-x)
690 ("M-y" . helm-show-kill-ring)
691 ("C-x b" . helm-mini)
692 ("C-x C-b" . helm-buffers-list)
693 ("C-x C-f" . helm-find-files)
694 ("C-h r" . helm-info-emacs)
695 ("s-r" . helm-recentf)
696 ("C-s-r" . helm-resume)
697 :map helm-map
698 ("<tab>" . helm-execute-persistent-action)
699 ("C-i" . helm-execute-persistent-action) ; Make TAB work in terminals
700 ("C-z" . helm-select-action)) ; List actions
701 :config (helm-mode 1)))
702
703 (use-feature eshell
704 :defer 0.5
705 :commands eshell
706 :bind ("C-c a s e" . eshell)
707 :config
708 (eval-when-compile (defvar eshell-prompt-regexp))
709 (defun a/eshell-quit-or-delete-char (arg)
710 (interactive "p")
711 (if (and (eolp) (looking-back eshell-prompt-regexp nil))
712 (eshell-life-is-too-much)
713 (delete-char arg)))
714
715 (defun a/eshell-clear ()
716 (interactive)
717 (let ((inhibit-read-only t))
718 (erase-buffer))
719 (eshell-send-input))
720
721 (defun a/eshell-setup ()
722 (make-local-variable 'company-idle-delay)
723 (defvar company-idle-delay)
724 (setq company-idle-delay nil)
725 (bind-keys :map eshell-mode-map
726 ("C-d" . a/eshell-quit-or-delete-char)
727 ("C-S-l" . a/eshell-clear)
728 ("M-r" . counsel-esh-history)
729 ([tab] . company-complete)))
730
731 :hook (eshell-mode . a/eshell-setup)
732 :custom
733 (eshell-hist-ignoredups t)
734 (eshell-input-filter 'eshell-input-filter-initial-space))
735
736 (use-feature ibuffer
737 :bind
738 (("C-x C-b" . ibuffer-other-window)
739 :map ibuffer-mode-map
740 ("P" . ibuffer-backward-filter-group)
741 ("N" . ibuffer-forward-filter-group)
742 ("M-p" . ibuffer-do-print)
743 ("M-n" . ibuffer-do-shell-command-pipe-replace))
744 :config
745 ;; Use human readable Size column instead of original one
746 (define-ibuffer-column size-h
747 (:name "Size" :inline t)
748 (cond
749 ((> (buffer-size) 1000000) (format "%7.1fM" (/ (buffer-size) 1000000.0)))
750 ((> (buffer-size) 100000) (format "%7.0fk" (/ (buffer-size) 1000.0)))
751 ((> (buffer-size) 1000) (format "%7.1fk" (/ (buffer-size) 1000.0)))
752 (t (format "%8d" (buffer-size)))))
753 :custom
754 (ibuffer-saved-filter-groups
755 '(("default"
756 ("dired" (mode . dired-mode))
757 ("org" (mode . org-mode))
758 ("gnus"
759 (or
760 (mode . gnus-group-mode)
761 (mode . gnus-summary-mode)
762 (mode . gnus-article-mode)
763 ;; not really, but...
764 (mode . message-mode)))
765 ("web"
766 (or
767 (mode . web-mode)
768 (mode . css-mode)
769 (mode . scss-mode)
770 (mode . js2-mode)))
771 ("shell"
772 (or
773 (mode . eshell-mode)
774 (mode . shell-mode)
775 (mode . term-mode)))
776 ("programming"
777 (or
778 (mode . python-mode)
779 (mode . c-mode)
780 (mode . c++-mode)
781 (mode . java-mode)
782 (mode . emacs-lisp-mode)
783 (mode . scheme-mode)
784 (mode . haskell-mode)
785 (mode . lean-mode)
786 (mode . alloy-mode)))
787 ("tex"
788 (or
789 (mode . bibtex-mode)
790 (mode . latex-mode)))
791 ("emacs"
792 (or
793 (name . "^\\*scratch\\*$")
794 (name . "^\\*Messages\\*$")))
795 ("erc" (mode . erc-mode)))))
796 (ibuffer-formats
797 '((mark modified read-only locked " "
798 (name 18 18 :left :elide)
799 " "
800 (size-h 9 -1 :right)
801 " "
802 (mode 16 16 :left :elide)
803 " " filename-and-process)
804 (mark " "
805 (name 16 -1)
806 " " filename)))
807 :hook (ibuffer . (lambda () (ibuffer-switch-to-saved-filter-groups "default"))))
808
809 (use-feature outline
810 :hook (prog-mode . outline-minor-mode)
811 :bind
812 (:map
813 outline-minor-mode-map
814 ("<s-tab>" . outline-toggle-children)
815 ("M-p" . outline-previous-visible-heading)
816 ("M-n" . outline-next-visible-heading)
817 :prefix-map a/outline-prefix-map
818 :prefix "s-o"
819 ("TAB" . outline-toggle-children)
820 ("a" . outline-hide-body)
821 ("H" . outline-hide-body)
822 ("S" . outline-show-all)
823 ("h" . outline-hide-subtree)
824 ("s" . outline-show-subtree)))
825
826 (use-feature ls-lisp
827 :custom (ls-lisp-dirs-first t))
828
829 (use-feature dired
830 :config
831 (setq dired-listing-switches "-alh"
832 ls-lisp-use-insert-directory-program nil)
833
834 ;; easily diff 2 marked files
835 ;; https://oremacs.com/2017/03/18/dired-ediff/
836 (defun dired-ediff-files ()
837 (interactive)
838 (require 'dired-aux)
839 (defvar ediff-after-quit-hook-internal)
840 (let ((files (dired-get-marked-files))
841 (wnd (current-window-configuration)))
842 (if (<= (length files) 2)
843 (let ((file1 (car files))
844 (file2 (if (cdr files)
845 (cadr files)
846 (read-file-name
847 "file: "
848 (dired-dwim-target-directory)))))
849 (if (file-newer-than-file-p file1 file2)
850 (ediff-files file2 file1)
851 (ediff-files file1 file2))
852 (add-hook 'ediff-after-quit-hook-internal
853 (lambda ()
854 (setq ediff-after-quit-hook-internal nil)
855 (set-window-configuration wnd))))
856 (error "no more than 2 files should be marked"))))
857 :bind (:map dired-mode-map
858 ("b" . dired-up-directory)
859 ("e" . dired-ediff-files)
860 ("E" . dired-toggle-read-only)
861 ("\\" . dired-hide-details-mode)
862 ("z" . (lambda ()
863 (interactive)
864 (a/dired-start-process "zathura"))))
865 :hook (dired-mode . dired-hide-details-mode))
866
867 (use-feature help
868 :config
869 (temp-buffer-resize-mode)
870 (setq help-window-select t))
871
872 (use-feature tramp
873 :config
874 (add-to-list 'tramp-default-proxies-alist '(nil "\\`root\\'" "/ssh:%h:"))
875 (add-to-list 'tramp-default-proxies-alist '("localhost" nil nil))
876 (add-to-list 'tramp-default-proxies-alist
877 (list (regexp-quote (system-name)) nil nil)))
878
879 (use-package dash
880 :config (dash-enable-font-lock))
881
882 (use-package doc-view
883 :bind (:map doc-view-mode-map
884 ("M-RET" . image-previous-line)))
885
886 \f
887 ;;; Editing
888
889 ;; highlight uncommitted changes in the left fringe
890 (use-package diff-hl
891 :defer 0.6
892 :config
893 (setq diff-hl-draw-borders nil)
894 (global-diff-hl-mode)
895 :hook (magit-post-refresh . diff-hl-magit-post-refresh))
896
897 ;; display Lisp objects at point in the echo area
898 (use-feature eldoc
899 :when (version< "25" emacs-version)
900 :config (global-eldoc-mode))
901
902 ;; highlight matching parens
903 (use-feature paren
904 :demand
905 :config (show-paren-mode))
906
907 (use-feature simple
908 :config (column-number-mode))
909
910 ;; save minibuffer history
911 (use-feature savehist
912 :config (savehist-mode))
913
914 ;; automatically save place in files
915 (use-feature saveplace
916 :when (version< "25" emacs-version)
917 :config (save-place-mode))
918
919 (use-feature prog-mode
920 :config (global-prettify-symbols-mode)
921 (defun indicate-buffer-boundaries-left ()
922 (setq indicate-buffer-boundaries 'left))
923 (add-hook 'prog-mode-hook #'indicate-buffer-boundaries-left))
924
925 (use-feature text-mode
926 :hook ((text-mode . indicate-buffer-boundaries-left)
927 (text-mode . abbrev-mode)))
928
929 (use-package company
930 :defer 0.6
931 :bind
932 (:map company-active-map
933 ([tab] . company-complete-common-or-cycle)
934 ([escape] . company-abort))
935 :custom
936 (company-minimum-prefix-length 1)
937 (company-selection-wrap-around t)
938 (company-dabbrev-char-regexp "\\sw\\|\\s_\\|[-_]")
939 (company-dabbrev-downcase nil)
940 (company-dabbrev-ignore-case nil)
941 :config
942 (global-company-mode t))
943
944 (use-package flycheck
945 :defer 0.6
946 :hook (prog-mode . flycheck-mode)
947 :bind
948 (:map flycheck-mode-map
949 ("M-P" . flycheck-previous-error)
950 ("M-N" . flycheck-next-error))
951 :config
952 ;; Use the load-path from running Emacs when checking elisp files
953 (setq flycheck-emacs-lisp-load-path 'inherit)
954
955 ;; Only flycheck when I actually save the buffer
956 (setq flycheck-check-syntax-automatically '(mode-enabled save)))
957
958 ;; http://endlessparentheses.com/ispell-and-apostrophes.html
959 (use-package ispell
960 :defer 0.6
961 :config
962 ;; ’ can be part of a word
963 (setq ispell-local-dictionary-alist
964 `((nil "[[:alpha:]]" "[^[:alpha:]]"
965 "['\x2019]" nil ("-B") nil utf-8)))
966 ;; don't send ’ to the subprocess
967 (defun endless/replace-apostrophe (args)
968 (cons (replace-regexp-in-string
969 "’" "'" (car args))
970 (cdr args)))
971 (advice-add #'ispell-send-string :filter-args
972 #'endless/replace-apostrophe)
973
974 ;; convert ' back to ’ from the subprocess
975 (defun endless/replace-quote (args)
976 (if (not (derived-mode-p 'org-mode))
977 args
978 (cons (replace-regexp-in-string
979 "'" "’" (car args))
980 (cdr args))))
981 (advice-add #'ispell-parse-output :filter-args
982 #'endless/replace-quote))
983
984 \f
985 ;;; Programming modes
986
987 (use-feature lisp-mode
988 :config
989 (add-hook 'emacs-lisp-mode-hook 'outline-minor-mode)
990 (add-hook 'emacs-lisp-mode-hook 'reveal-mode)
991 (defun indent-spaces-mode ()
992 (setq indent-tabs-mode nil))
993 (add-hook 'lisp-interaction-mode-hook #'indent-spaces-mode))
994
995 (use-package alloy-mode
996 :straight (:host github :repo "dwwmmn/alloy-mode")
997 :mode "\\.als\\'"
998 :config (setq alloy-basic-offset 2))
999
1000 (use-package proof-site ; for Coq
1001 :straight proof-general)
1002
1003 (eval-when-compile (defvar lean-mode-map))
1004 (use-package lean-mode
1005 :defer 0.4
1006 :bind (:map lean-mode-map
1007 ("S-SPC" . company-complete))
1008 :config
1009 (require 'lean-input)
1010 (setq default-input-method "Lean"
1011 lean-input-tweak-all '(lean-input-compose
1012 (lean-input-prepend "/")
1013 (lean-input-nonempty))
1014 lean-input-user-translations '(("/" "/")))
1015 (lean-input-setup))
1016
1017 (use-package haskell-mode
1018 :config
1019 (setq haskell-indentation-layout-offset 4
1020 haskell-indentation-left-offset 4
1021 flycheck-checker 'haskell-hlint
1022 flycheck-disabled-checkers '(haskell-stack-ghc haskell-ghc)))
1023
1024 (use-package dante
1025 :after haskell-mode
1026 :commands dante-mode
1027 :hook (haskell-mode . dante-mode))
1028
1029 (use-package hlint-refactor
1030 :after haskell-mode
1031 :bind (:map hlint-refactor-mode-map
1032 ("C-c l b" . hlint-refactor-refactor-buffer)
1033 ("C-c l r" . hlint-refactor-refactor-at-point))
1034 :hook (haskell-mode . hlint-refactor-mode))
1035
1036 (use-package flycheck-haskell
1037 :after haskell-mode)
1038 ;; alternative: hs-lint https://github.com/ndmitchell/hlint/blob/20e116a043f2073c57b17b24ae6364b5e433ba7e/data/hs-lint.el
1039
1040 (use-package sgml-mode
1041 :config
1042 (setq sgml-basic-offset 2))
1043
1044 (use-package css-mode
1045 :config
1046 (setq css-indent-offset 2))
1047
1048 (use-package web-mode
1049 :mode "\\.html\\'"
1050 :config
1051 (a/setq-every 2
1052 web-mode-code-indent-offset
1053 web-mode-css-indent-offset
1054 web-mode-markup-indent-offset))
1055
1056 (use-package emmet-mode
1057 :after (:any web-mode css-mode sgml-mode)
1058 :bind* (("C-)" . emmet-next-edit-point)
1059 ("C-(" . emmet-prev-edit-point))
1060 :config
1061 (unbind-key "C-j" emmet-mode-keymap)
1062 (setq emmet-move-cursor-between-quotes t)
1063 :hook (web-mode css-mode html-mode sgml-mode))
1064
1065 (comment
1066 (use-package meghanada
1067 :bind
1068 (:map meghanada-mode-map
1069 (("C-M-o" . meghanada-optimize-import)
1070 ("C-M-t" . meghanada-import-all)))
1071 :hook (java-mode . meghanada-mode)))
1072
1073 (comment
1074 (use-package treemacs
1075 :config (setq treemacs-never-persist t))
1076
1077 (use-package yasnippet
1078 :config
1079 ;; (yas-global-mode)
1080 )
1081
1082 (use-package lsp-mode
1083 :init (setq lsp-eldoc-render-all nil
1084 lsp-highlight-symbol-at-point nil)
1085 )
1086
1087 (use-package hydra)
1088
1089 (use-package company-lsp
1090 :after company
1091 :config
1092 (setq company-lsp-cache-candidates t
1093 company-lsp-async t))
1094
1095 (use-package lsp-ui
1096 :config
1097 (setq lsp-ui-sideline-update-mode 'point))
1098
1099 (use-package lsp-java
1100 :config
1101 (add-hook 'java-mode-hook
1102 (lambda ()
1103 (setq-local company-backends (list 'company-lsp))))
1104
1105 (add-hook 'java-mode-hook 'lsp-java-enable)
1106 (add-hook 'java-mode-hook 'flycheck-mode)
1107 (add-hook 'java-mode-hook 'company-mode)
1108 (add-hook 'java-mode-hook 'lsp-ui-mode))
1109
1110 (use-package dap-mode
1111 :after lsp-mode
1112 :config
1113 (dap-mode t)
1114 (dap-ui-mode t))
1115
1116 (use-package dap-java
1117 :after (lsp-java))
1118
1119 (use-package lsp-java-treemacs
1120 :after (treemacs)))
1121
1122 (comment
1123 (use-package eclim
1124 :bind (:map eclim-mode-map ("S-SPC" . company-complete))
1125 :hook ((java-mode . eclim-mode)
1126 (eclim-mode . (lambda ()
1127 (make-local-variable 'company-idle-delay)
1128 (defvar company-idle-delay)
1129 ;; (setq company-idle-delay 0.7)
1130 (setq company-idle-delay nil))))
1131 :custom
1132 (eclim-auto-save nil)
1133 ;; (eclimd-default-workspace "~/src/eclipse-workspace-exp")
1134 (eclim-executable "~/.p2/pool/plugins/org.eclim_2.8.0/bin/eclim")
1135 (eclim-eclipse-dirs '("~/usr/eclipse/dsl-2018-09/eclipse"))))
1136
1137 (use-package geiser)
1138
1139 (use-feature geiser-guile
1140 :config
1141 (setq geiser-guile-load-path "~/src/git/guix"))
1142
1143 (use-package guix)
1144
1145 (comment
1146 (use-package auctex
1147 :custom
1148 (font-latex-fontify-sectioning 'color)))
1149
1150 \f
1151 ;;; Theme
1152
1153 (add-to-list 'custom-theme-load-path "~/.emacs.d/lisp")
1154 (load-theme 'tangomod t)
1155
1156 (use-package smart-mode-line
1157 :commands (sml/apply-theme)
1158 :demand
1159 :config
1160 (sml/setup))
1161
1162 (use-package doom-themes)
1163
1164 (defvar a/org-mode-font-lock-keywords
1165 '(("[ \t]*\\(#\\+\\(BEGIN\\|END\\|begin\\|end\\)_\\(\\S-+\\)\\)[ \t]*\\([^\n:]*\\)"
1166 (1 '(:foreground "#5a5b5a" :background "#292b2b") t) ; directive
1167 (3 '(:foreground "#81a2be" :background "#292b2b") t) ; kind
1168 (4 '(:foreground "#c5c8c6") t)))) ; title
1169
1170 (defun a/lights-on ()
1171 "Enable my favourite light theme."
1172 (interactive)
1173 (mapc #'disable-theme custom-enabled-themes)
1174 (load-theme 'tangomod t)
1175 (sml/apply-theme 'automatic)
1176 (font-lock-remove-keywords
1177 'org-mode a/org-mode-font-lock-keywords))
1178
1179 (defun a/lights-off ()
1180 "Go dark."
1181 (interactive)
1182 (mapc #'disable-theme custom-enabled-themes)
1183 (load-theme 'doom-tomorrow-night t)
1184 (sml/apply-theme 'automatic)
1185 (font-lock-add-keywords
1186 'org-mode a/org-mode-font-lock-keywords t))
1187
1188 (bind-keys
1189 ("s-t d" . a/lights-off)
1190 ("s-t l" . a/lights-on))
1191
1192 \f
1193 ;;; Emacs enhancements & auxiliary packages
1194
1195 (use-feature man
1196 :config (setq Man-width 80))
1197
1198 (use-package which-key
1199 :defer 0.4
1200 :config
1201 (which-key-add-key-based-replacements
1202 ;; prefixes for global prefixes and minor modes
1203 "C-c @" "outline"
1204 "C-c !" "flycheck"
1205 "C-c 8" "typo"
1206 "C-c 8 -" "typo/dashes"
1207 "C-c 8 <" "typo/left-brackets"
1208 "C-c 8 >" "typo/right-brackets"
1209 "C-x 8" "unicode"
1210 "C-x a" "abbrev/expand"
1211 "C-x r" "rectangle/register/bookmark"
1212 "C-x v" "version control"
1213 ;; prefixes for my personal bindings
1214 "C-c a" "applications"
1215 "C-c a e" "erc"
1216 "C-c a o" "org"
1217 "C-c a s" "shells"
1218 "C-c p" "package-management"
1219 ;; "C-c p e" "package-management/epkg"
1220 "C-c p s" "straight.el"
1221 "C-c psa" "all"
1222 "C-c psp" "package"
1223 "C-c c" "compile-and-comments"
1224 "C-c e" "eval"
1225 "C-c f" "files"
1226 "C-c F" "frames"
1227 "C-S-h" "help(ful)"
1228 "C-c m" "multiple-cursors"
1229 "C-c P" "projectile"
1230 "C-c P s" "projectile/search"
1231 "C-c P x" "projectile/execute"
1232 "C-c P 4" "projectile/other-window"
1233 "C-c q" "boxquote"
1234 "s-g" "magit"
1235 "s-o" "outline"
1236 "s-t" "themes")
1237
1238 ;; prefixes for major modes
1239 (which-key-add-major-mode-key-based-replacements 'message-mode
1240 "C-c f" "footnote")
1241 (which-key-add-major-mode-key-based-replacements 'org-mode
1242 "C-c C-v" "org-babel")
1243 (which-key-add-major-mode-key-based-replacements 'web-mode
1244 "C-c C-a" "web/attributes"
1245 "C-c C-b" "web/blocks"
1246 "C-c C-d" "web/dom"
1247 "C-c C-e" "web/element"
1248 "C-c C-t" "web/tags")
1249
1250 (which-key-mode)
1251 :custom
1252 (which-key-add-column-padding 5)
1253 (which-key-max-description-length 32))
1254
1255 (use-package crux ; results in Waiting for git... [2 times]
1256 :defer 0.4
1257 :bind (("C-c b k" . crux-kill-other-buffers)
1258 ("C-c d" . crux-duplicate-current-line-or-region)
1259 ("C-c D" . crux-duplicate-and-comment-current-line-or-region)
1260 ("C-c f c" . crux-copy-file-preserve-attributes)
1261 ("C-c f d" . crux-delete-file-and-buffer)
1262 ("C-c f r" . crux-rename-file-and-buffer)
1263 ("C-c j" . crux-top-join-line)
1264 ("C-S-j" . crux-top-join-line)))
1265
1266 (use-package mwim
1267 :bind (("C-a" . mwim-beginning-of-code-or-line)
1268 ("C-e" . mwim-end-of-code-or-line)
1269 ("<home>" . mwim-beginning-of-line-or-code)
1270 ("<end>" . mwim-end-of-line-or-code)))
1271
1272 (use-package projectile
1273 :bind-keymap ("C-c P" . projectile-command-map)
1274 :config
1275 (projectile-mode)
1276
1277 (defun my-projectile-invalidate-cache (&rest _args)
1278 ;; ignore the args to `magit-checkout'
1279 (projectile-invalidate-cache nil))
1280
1281 (eval-after-load 'magit-branch
1282 '(progn
1283 (advice-add 'magit-checkout
1284 :after #'my-projectile-invalidate-cache)
1285 (advice-add 'magit-branch-and-checkout
1286 :after #'my-projectile-invalidate-cache)))
1287 :custom (projectile-completion-system 'ivy))
1288
1289 (use-package helpful
1290 :defer 0.6
1291 :bind
1292 (("C-S-h c" . helpful-command)
1293 ("C-S-h f" . helpful-callable) ; helpful-function
1294 ("C-S-h v" . helpful-variable)
1295 ("C-S-h k" . helpful-key)
1296 ("C-S-h p" . helpful-at-point)))
1297
1298 (use-package unkillable-scratch
1299 :defer 0.6
1300 :config
1301 (unkillable-scratch 1)
1302 :custom
1303 (unkillable-buffers '("^\\*scratch\\*$" "^\\*Messages\\*$")))
1304
1305 ;; ,----
1306 ;; | make pretty boxed quotes like this
1307 ;; `----
1308 (use-package boxquote
1309 :defer 0.6
1310 :bind
1311 (:prefix-map a/boxquote-prefix-map
1312 :prefix "C-c q"
1313 ("b" . boxquote-buffer)
1314 ("B" . boxquote-insert-buffer)
1315 ("d" . boxquote-defun)
1316 ("F" . boxquote-insert-file)
1317 ("hf" . boxquote-describe-function)
1318 ("hk" . boxquote-describe-key)
1319 ("hv" . boxquote-describe-variable)
1320 ("hw" . boxquote-where-is)
1321 ("k" . boxquote-kill)
1322 ("p" . boxquote-paragraph)
1323 ("q" . boxquote-boxquote)
1324 ("r" . boxquote-region)
1325 ("s" . boxquote-shell-command)
1326 ("t" . boxquote-text)
1327 ("T" . boxquote-title)
1328 ("u" . boxquote-unbox)
1329 ("U" . boxquote-unbox-region)
1330 ("y" . boxquote-yank)
1331 ("M-q" . boxquote-fill-paragraph)
1332 ("M-w" . boxquote-kill-ring-save)))
1333
1334 (use-package orgalist
1335 ;; http://lists.gnu.org/archive/html/emacs-orgmode/2019-04/msg00007.html
1336 :disabled t
1337 :after message
1338 :hook (message-mode . orgalist-mode))
1339
1340 ;; easily type pretty quotes & other typography, like ‘’“”-–—«»‹›
1341 (use-package typo
1342 :defer 0.5
1343 :config
1344 (typo-global-mode 1)
1345 :hook (text-mode . typo-mode))
1346
1347 ;; highlight TODOs in buffers
1348 (use-package hl-todo
1349 :defer 0.5
1350 :config
1351 (global-hl-todo-mode))
1352
1353 (use-package shrink-path
1354 :defer 0.5
1355 :after eshell
1356 :config
1357 (defvar user-@-host (concat (user-login-name) "@" (system-name) " "))
1358 (defun +eshell/prompt ()
1359 (let ((base/dir (shrink-path-prompt default-directory)))
1360 (concat (propertize user-@-host 'face 'default)
1361 (propertize (car base/dir)
1362 'face 'font-lock-comment-face)
1363 (propertize (cdr base/dir)
1364 'face 'font-lock-constant-face)
1365 (propertize "> " 'face 'default))))
1366 (setq eshell-prompt-regexp (concat user-@-host ".*> ")
1367 eshell-prompt-function #'+eshell/prompt))
1368
1369 (use-package eshell-up
1370 :after eshell
1371 :commands eshell-up)
1372
1373 (use-package multi-term
1374 :defer 0.6
1375 :bind (("C-c a s m m" . multi-term)
1376 ("C-c a s m d" . multi-term-dedicated-toggle)
1377 ("C-c a s m p" . multi-term-prev)
1378 ("C-c a s m n" . multi-term-next)
1379 :map term-mode-map
1380 ("C-c C-j" . term-char-mode)
1381 :map term-raw-map
1382 ("C-c C-j" . term-line-mode))
1383 :config
1384 (setq multi-term-program "screen"
1385 multi-term-program-switches (concat "-c"
1386 (getenv "XDG_CONFIG_HOME")
1387 "/screen/screenrc")
1388 ;; TODO: add separate bindings for connecting to existing
1389 ;; session vs. always creating a new one
1390 multi-term-dedicated-select-after-open-p t
1391 multi-term-dedicated-window-height 20
1392 multi-term-dedicated-max-window-height 30
1393 term-bind-key-alist
1394 '(("C-c C-c" . term-interrupt-subjob)
1395 ("C-c C-e" . term-send-esc)
1396 ("C-k" . kill-line)
1397 ;; ("C-y" . term-paste)
1398 ("C-y" . term-send-raw)
1399 ("M-f" . term-send-forward-word)
1400 ("M-b" . term-send-backward-word)
1401 ("M-p" . term-send-up)
1402 ("M-n" . term-send-down)
1403 ("M-j" . term-send-raw-meta)
1404 ("M-y" . term-send-raw-meta)
1405 ("M-/" . term-send-raw-meta)
1406 ("M-0" . term-send-raw-meta)
1407 ("M-1" . term-send-raw-meta)
1408 ("M-2" . term-send-raw-meta)
1409 ("M-3" . term-send-raw-meta)
1410 ("M-4" . term-send-raw-meta)
1411 ("M-5" . term-send-raw-meta)
1412 ("M-6" . term-send-raw-meta)
1413 ("M-7" . term-send-raw-meta)
1414 ("M-8" . term-send-raw-meta)
1415 ("M-9" . term-send-raw-meta)
1416 ("<C-backspace>" . term-send-backward-kill-word)
1417 ("<M-DEL>" . term-send-backward-kill-word)
1418 ("M-d" . term-send-delete-word)
1419 ("M-," . term-send-raw)
1420 ("M-." . comint-dynamic-complete))
1421 term-unbind-key-alist
1422 '("C-z" "C-x" "C-c" "C-h"
1423 ;; "C-y"
1424 "<ESC>")))
1425
1426 (use-package page-break-lines
1427 :defer 0.5
1428 :config
1429 (global-page-break-lines-mode))
1430
1431 (use-package expand-region
1432 :bind ("C-=" . er/expand-region))
1433
1434 (use-package multiple-cursors
1435 :bind
1436 (("C-S-<mouse-1>" . mc/add-cursor-on-click)
1437 (:prefix-map a/mc-prefix-map
1438 :prefix "C-c m"
1439 ("c" . mc/edit-lines)
1440 ("n" . mc/mark-next-like-this)
1441 ("p" . mc/mark-previous-like-this)
1442 ("a" . mc/mark-all-like-this))))
1443
1444 (use-package forge
1445 :after magit
1446 :demand)
1447
1448 (use-package yasnippet
1449 :defer 0.6
1450 :config
1451 (defconst yas-verbosity-cur yas-verbosity)
1452 (setq yas-verbosity 2)
1453 (add-to-list 'yas-snippet-dirs "~/src/git/guix/etc/snippets")
1454 (yas-reload-all)
1455 (setq yas-verbosity yas-verbosity-cur)
1456 :hook
1457 (text-mode . yas-minor-mode))
1458
1459 (use-package debbugs
1460 :straight (debbugs
1461 :host github
1462 :repo "emacs-straight/debbugs"
1463 :files (:defaults "Debbugs.wsdl")))
1464
1465 (use-package org-ref
1466 :init
1467 (a/setq-every '("~/usr/org/references.bib")
1468 reftex-default-bibliography
1469 org-ref-default-bibliography)
1470 (setq
1471 org-ref-bibliography-notes "~/usr/org/notes.org"
1472 org-ref-pdf-directory "~/usr/org/bibtex-pdfs/"))
1473
1474 ;; ugh, temporary (still better than using the proprietary web app)
1475 (use-package slack
1476 :commands (slack-start)
1477 :init
1478 (eval-when-compile ; silence the byte-compiler
1479 (defvar url-http-data nil)
1480 (defvar url-http-extra-headers nil)
1481 (defvar url-http-method nil)
1482 (defvar url-callback-function nil)
1483 (defvar url-callback-arguments nil)
1484 (defvar oauth--token-data nil))
1485 (setq slack-buffer-emojify t
1486 slack-prefer-current-team t)
1487 :config
1488 (slack-register-team
1489 :name "nday-students"
1490 :default t
1491 :token nday-students-token
1492 :subscribed-channels '(general)
1493 :full-and-display-names t)
1494 (add-to-list 'swiper-font-lock-exclude 'slack-message-buffer-mode t)
1495 (setq lui-time-stamp-format "[%Y-%m-%d %H:%M:%S]"
1496 lui-time-stamp-only-when-changed-p t
1497 lui-time-stamp-position 'right)
1498 :bind
1499 (("C-c s s" . slack-start)
1500 ("C-c s u" . slack-select-unread-rooms)
1501 ("C-c s b" . slack-select-rooms)
1502 ("C-c s t" . slack-change-current-team)
1503 ("C-c s c" . slack-ws-close)
1504 :map slack-mode-map
1505 ("M-p" . slack-buffer-goto-prev-message)
1506 ("M-n" . slack-buffer-goto-next-message)
1507 ("C-c e" . slack-message-edit)
1508 ("C-c k" . slack-message-delete)
1509 ("C-c C-k" . slack-channel-leave)
1510 ("C-c r a" . slack-message-add-reaction)
1511 ("C-c r r" . slack-message-remove-reaction)
1512 ("C-c r s" . slack-message-show-reaction-users)
1513 ("C-c p l" . slack-room-pins-list)
1514 ("C-c p a" . slack-message-pins-add)
1515 ("C-c p r" . slack-message-pins-remove)
1516 ("@" . slack-message-embed-mention)
1517 ("#" . slack-message-embed-channel)))
1518
1519 (use-package alert
1520 :commands (alert)
1521 :init
1522 (setq alert-default-style 'notifier))
1523
1524 \f
1525 ;;; Email (with Gnus)
1526
1527 (defvar a/maildir (expand-file-name "~/mail/"))
1528 (with-eval-after-load 'recentf
1529 (add-to-list 'recentf-exclude a/maildir))
1530
1531 (setq
1532 a/gnus-init-file (no-littering-expand-etc-file-name "gnus")
1533 mail-user-agent 'gnus-user-agent
1534 read-mail-command 'gnus)
1535
1536 (use-feature gnus
1537 :bind (("s-m" . gnus)
1538 ("s-M" . gnus-unplugged))
1539 :init
1540 (setq
1541 gnus-select-method '(nnnil "")
1542 gnus-secondary-select-methods
1543 '((nnimap "amin"
1544 (nnimap-stream plain)
1545 (nnimap-address "127.0.0.1")
1546 (nnimap-server-port 143)
1547 (nnimap-authenticator plain)
1548 (nnimap-user "amin@bndl.local"))
1549 (nnimap "uw"
1550 (nnimap-stream plain)
1551 (nnimap-address "127.0.0.1")
1552 (nnimap-server-port 143)
1553 (nnimap-authenticator plain)
1554 (nnimap-user "abandali@uw.local"))
1555 (nnimap "csc"
1556 (nnimap-stream plain)
1557 (nnimap-address "127.0.0.1")
1558 (nnimap-server-port 143)
1559 (nnimap-authenticator plain)
1560 (nnimap-user "abandali@csc.uw.local")))
1561 gnus-message-archive-group "nnimap+amin:Sent"
1562 gnus-parameters
1563 '(("gnu\\.deepspec"
1564 (to-address . "deepspec@lists.cs.princeton.edu")
1565 (to-list . "deepspec@lists.cs.princeton.edu"))
1566 ("gnu\\.emacs-devel"
1567 (to-address . "emacs-devel@gnu.org")
1568 (to-list . "emacs-devel@gnu.org"))
1569 ("gnu\\.emacs-orgmode"
1570 (to-address . "emacs-orgmode@gnu.org")
1571 (to-list . "emacs-orgmode@gnu.org"))
1572 ("gnu\\.emacsconf-discuss"
1573 (to-address . "emacsconf-discuss@gnu.org")
1574 (to-list . "emacsconf-discuss@gnu.org"))
1575 ("gnu\\.fencepost-users"
1576 (to-address . "fencepost-users@gnu.org")
1577 (to-list . "fencepost-users@gnu.org"))
1578 ("gnu\\.gnunet-developers"
1579 (to-address . "gnunet-developers@gnu.org")
1580 (to-list . "gnunet-developers@gnu.org"))
1581 ("gnu\\.guile-devel"
1582 (to-address . "guile-devel@gnu.org")
1583 (to-list . "guile-devel@gnu.org"))
1584 ("gnu\\.guix-devel"
1585 (to-address . "guix-devel@gnu.org")
1586 (to-list . "guix-devel@gnu.org"))
1587 ("gnu\\.haskell-art"
1588 (to-address . "haskell-art@we.lurk.org")
1589 (to-list . "haskell-art@we.lurk.org"))
1590 ("gnu\\.haskell-cafe"
1591 (to-address . "haskell-cafe@haskell.org")
1592 (to-list . "haskell-cafe@haskell.org"))
1593 ("gnu\\.help-gnu-emacs"
1594 (to-address . "help-gnu-emacs@gnu.org")
1595 (to-list . "help-gnu-emacs@gnu.org"))
1596 ("gnu\\.info-gnu-emacs"
1597 (to-address . "info-gnu-emacs@gnu.org")
1598 (to-list . "info-gnu-emacs@gnu.org"))
1599 ("gnu\\.info-guix"
1600 (to-address . "info-guix@gnu.org")
1601 (to-list . "info-guix@gnu.org"))
1602 ("gnu\\.notmuch"
1603 (to-address . "notmuch@notmuchmail.org")
1604 (to-list . "notmuch@notmuchmail.org"))
1605 ("gnu\\.parabola-dev"
1606 (to-address . "dev@lists.parabola.nu")
1607 (to-list . "dev@lists.parabola.nu"))
1608 ("gnu\\.webmasters"
1609 (to-address . "webmasters@gnu.org")
1610 (to-list . "webmasters@gnu.org"))
1611 ("gnu\\.www-commits"
1612 (to-address . "www-commits@gnu.org")
1613 (to-list . "www-commits@gnu.org"))
1614 ("gnu\\.www-discuss"
1615 (to-address . "www-discuss@gnu.org")
1616 (to-list . "www-discuss@gnu.org"))
1617 ("gnu\\.~bandali\\.public-inbox"
1618 (to-address . "~bandali/public-inbox@lists.sr.ht")
1619 (to-list . "~bandali/public-inbox@lists.sr.ht"))
1620 ("gnu\\.~sircmpwn\\.srht-admins"
1621 (to-address . "~sircmpwn/sr.ht-admins@lists.sr.ht")
1622 (to-list . "~sircmpwn/sr.ht-admins@lists.sr.ht"))
1623 ("gnu\\.~sircmpwn\\.srht-announce"
1624 (to-address . "~sircmpwn/sr.ht-announce@lists.sr.ht")
1625 (to-list . "~sircmpwn/sr.ht-announce@lists.sr.ht"))
1626 ("gnu\\.~sircmpwn\\.srht-dev"
1627 (to-address . "~sircmpwn/sr.ht-dev@lists.sr.ht")
1628 (to-list . "~sircmpwn/sr.ht-dev@lists.sr.ht"))
1629 ("gnu\\.~sircmpwn\\.srht-discuss"
1630 (to-address . "~sircmpwn/sr.ht-discuss@lists.sr.ht")
1631 (to-list . "~sircmpwn/sr.ht-discuss@lists.sr.ht"))
1632 ("gnu.*"
1633 (gcc-self . t))
1634 ("gnu\\."
1635 (subscribed . t)))
1636 gnus-large-newsgroup 50
1637 gnus-home-directory (no-littering-expand-var-file-name "gnus/")
1638 gnus-directory (concat gnus-home-directory "news/")
1639 message-directory (concat gnus-home-directory "mail/")
1640 nndraft-directory (concat gnus-home-directory "drafts/")
1641 gnus-save-newsrc-file nil
1642 gnus-read-newsrc-file nil
1643 gnus-interactive-exit nil
1644 gnus-gcc-mark-as-read t)
1645 :config
1646 (require 'ebdb)
1647 (require 'ebdb-mua)
1648 (require 'ebdb-gnus)
1649
1650 (with-eval-after-load 'recentf
1651 (add-to-list 'recentf-exclude gnus-home-directory)))
1652
1653 (use-feature gnus-art
1654 :config
1655 (setq
1656 gnus-visible-headers
1657 (concat gnus-visible-headers "\\|^List-Id:\\|^X-RT-Originator:\\|^User-Agent:")
1658 gnus-sorted-header-list
1659 '("^From:" "^Subject:" "^Summary:" "^Keywords:"
1660 "^Followup-To:" "^To:" "^Cc:" "X-RT-Originator"
1661 "^Newsgroups:" "List-Id:" "^Organization:"
1662 "^User-Agent:" "^Date:")
1663 ;; local-lapsed article dates
1664 ;; from https://www.emacswiki.org/emacs/GnusFormatting#toc11
1665 gnus-article-date-headers '(user-defined)
1666 gnus-article-time-format
1667 (lambda (time)
1668 (let* ((date (format-time-string "%a, %d %b %Y %T %z" time))
1669 (local (article-make-date-line date 'local))
1670 (combined-lapsed (article-make-date-line date
1671 'combined-lapsed))
1672 (lapsed (progn
1673 (string-match " (.+" combined-lapsed)
1674 (match-string 0 combined-lapsed))))
1675 (concat local lapsed))))
1676 (bind-keys
1677 :map gnus-article-mode-map
1678 ("M-L" . org-store-link)))
1679
1680 (use-feature gnus-sum
1681 :bind (:map gnus-summary-mode-map
1682 :prefix-map a/gnus-summary-prefix-map
1683 :prefix "v"
1684 ("r" . gnus-summary-reply)
1685 ("w" . gnus-summary-wide-reply)
1686 ("v" . gnus-summary-show-raw-article))
1687 :config
1688 (bind-keys
1689 :map gnus-summary-mode-map
1690 ("M-L" . org-store-link))
1691 :hook (gnus-summary-mode . a/no-mouse-autoselect-window))
1692
1693 (use-feature gnus-msg
1694 :config
1695 (setq gnus-posting-styles
1696 '((".*"
1697 (address "amin@bndl.org")
1698 (body "\nBest,\n")
1699 (eval (setq a/message-cite-say-hi t)))
1700 ("gnu.*"
1701 (address "bandali@gnu.org")
1702 (eval (set (make-local-variable 'message-user-fqdn) "fencepost.gnu.org")))
1703 ((header "subject" "ThankCRM")
1704 (to "webmasters-comment@gnu.org")
1705 (body "Added to 2019supporters.html.\n\nMoving to campaigns.\n\n-amin\n")
1706 (eval (setq a/message-cite-say-hi nil)))
1707 ("nnimap\\+uw:.*"
1708 (address "abandali@uwaterloo.ca")
1709 (gcc "\"nnimap+uw:Sent Items\""))
1710 ("nnimap\\+csc:.*"
1711 (address "abandali@csclub.uwaterloo.ca")
1712 (gcc "nnimap+csc:Sent")))))
1713
1714 (use-feature gnus-topic
1715 :hook (gnus-group-mode . gnus-topic-mode)
1716 :config (setq gnus-topic-line-format "%i[ %A: %(%{%n%}%) ]%v\n"))
1717
1718 (use-feature gnus-agent
1719 :config
1720 (setq gnus-agent-synchronize-flags 'ask)
1721 :hook (gnus-group-mode . gnus-agent-mode))
1722
1723 (use-feature gnus-group
1724 :config
1725 (setq gnus-permanently-visible-groups "\\(:INBOX$\\|:gnu$\\)"))
1726
1727 (use-feature gnus-win
1728 :config
1729 (setq gnus-use-full-window nil))
1730
1731 (use-feature gnus-dired
1732 :commands gnus-dired-mode
1733 :init
1734 (add-hook 'dired-mode-hook 'gnus-dired-mode))
1735
1736 (use-feature mm-decode
1737 :config
1738 (setq mm-discouraged-alternatives '("text/html" "text/richtext")))
1739
1740 (use-feature sendmail
1741 :config
1742 (setq sendmail-program "/usr/bin/msmtp"
1743 ;; message-sendmail-extra-arguments '("-v" "-d")
1744 mail-specify-envelope-from t
1745 mail-envelope-from 'header))
1746
1747 (use-feature message
1748 :config
1749 ;; redefine for a simplified In-Reply-To header
1750 ;; (see https://todo.sr.ht/~sircmpwn/lists.sr.ht/67)
1751 (defun message-make-in-reply-to ()
1752 "Return the In-Reply-To header for this message."
1753 (when message-reply-headers
1754 (let ((from (mail-header-from message-reply-headers))
1755 (msg-id (mail-header-id message-reply-headers)))
1756 (when from
1757 msg-id))))
1758
1759 (defconst a/message-cite-style-format "On %Y-%m-%d %l:%M %p, %N wrote:")
1760 (defconst message-cite-style-bandali
1761 '((message-cite-function 'message-cite-original)
1762 (message-citation-line-function 'message-insert-formatted-citation-line)
1763 (message-cite-reply-position 'traditional)
1764 (message-yank-prefix "> ")
1765 (message-yank-cited-prefix ">")
1766 (message-yank-empty-prefix ">")
1767 (message-citation-line-format
1768 (if a/message-cite-say-hi
1769 (concat "Hi %F,\n\n" a/message-cite-style-format)
1770 a/message-cite-style-format)))
1771 "Citation style based on Mozilla Thunderbird's. Use with message-cite-style.")
1772 (setq ;; message-cite-style 'message-cite-style-bandali
1773 message-kill-buffer-on-exit t
1774 message-send-mail-function 'message-send-mail-with-sendmail
1775 message-sendmail-envelope-from 'header
1776 message-subscribed-address-functions
1777 '(gnus-find-subscribed-addresses)
1778 message-dont-reply-to-names
1779 "\\(\\(amin@bndl\\.org\\)\\|\\(.*@\\(aminb\\|amin\\.bndl\\)\\.org\\)\\|\\(\\(bandali\\|aminb?\\|mab\\)@gnu\\.org\\)\\|\\(a\\(min\\.\\)?bandali@uwaterloo\\.ca\\)\\|\\(abandali@csclub\\.uwaterloo\\.ca\\)\\)")
1780 (require 'company-ebdb)
1781 :hook (;; (message-setup . mml-secure-message-sign-pgpmime)
1782 (message-mode . flyspell-mode)
1783 (message-mode . (lambda ()
1784 ;; (setq fill-column 65
1785 ;; message-fill-column 65)
1786 (make-local-variable 'company-idle-delay)
1787 (setq company-idle-delay 0.2))))
1788 ;; :custom-face
1789 ;; (message-header-subject ((t (:foreground "#111" :weight semi-bold))))
1790 ;; (message-header-to ((t (:foreground "#111" :weight normal))))
1791 ;; (message-header-cc ((t (:foreground "#333" :weight normal))))
1792 )
1793
1794 (with-eval-after-load 'mml-sec
1795 (setq mml-secure-openpgp-encrypt-to-self t
1796 mml-secure-openpgp-sign-with-sender t))
1797
1798 (use-feature footnote
1799 :after message
1800 ;; :config
1801 ;; (setq footnote-start-tag ""
1802 ;; footnote-end-tag ""
1803 ;; footnote-style 'unicode)
1804 :bind
1805 (:map message-mode-map
1806 :prefix-map a/footnote-prefix-map
1807 :prefix "C-c f"
1808 ("a" . footnote-add-footnote)
1809 ("b" . footnote-back-to-message)
1810 ("c" . footnote-cycle-style)
1811 ("d" . footnote-delete-footnote)
1812 ("g" . footnote-goto-footnote)
1813 ("r" . footnote-renumber-footnotes)
1814 ("s" . footnote-set-style)))
1815
1816 (use-package ebdb
1817 :straight (:host github :repo "girzel/ebdb")
1818 :after gnus
1819 :bind (:map gnus-group-mode-map ("e" . ebdb))
1820 :config
1821 (setq ebdb-sources (no-littering-expand-var-file-name "ebdb"))
1822 (with-eval-after-load 'swiper
1823 (add-to-list 'swiper-font-lock-exclude 'ebdb-mode t)))
1824
1825 (use-feature ebdb-com
1826 :after ebdb)
1827
1828 ;; (use-package ebdb-complete
1829 ;; :after ebdb
1830 ;; :config
1831 ;; (ebdb-complete-enable))
1832
1833 (use-package company-ebdb
1834 :config
1835 (defun company-ebdb--post-complete (_) nil))
1836
1837 (use-feature ebdb-gnus
1838 :after ebdb
1839 :custom
1840 (ebdb-gnus-window-configuration
1841 '(article
1842 (vertical 1.0
1843 (summary 0.25 point)
1844 (horizontal 1.0
1845 (article 1.0)
1846 (ebdb-gnus 0.3))))))
1847
1848 (use-feature ebdb-mua
1849 :after ebdb
1850 ;; :custom (ebdb-mua-pop-up nil)
1851 )
1852
1853 ;; (use-package ebdb-message
1854 ;; :after ebdb)
1855
1856
1857 ;; (use-package ebdb-vcard
1858 ;; :after ebdb)
1859
1860 (use-package message-x)
1861
1862 (comment
1863 (use-package message-x
1864 :custom
1865 (message-x-completion-alist
1866 (quote
1867 (("\\([rR]esent-\\|[rR]eply-\\)?[tT]o:\\|[bB]?[cC][cC]:" . gnus-harvest-find-address)
1868 ((if
1869 (boundp
1870 (quote message-newgroups-header-regexp))
1871 message-newgroups-header-regexp message-newsgroups-header-regexp)
1872 . message-expand-group))))))
1873
1874 (comment
1875 (use-package gnus-harvest
1876 :commands gnus-harvest-install
1877 :demand t
1878 :config
1879 (if (featurep 'message-x)
1880 (gnus-harvest-install 'message-x)
1881 (gnus-harvest-install))))
1882
1883 \f
1884 ;;; IRC
1885
1886 (use-package znc
1887 :straight (:host nil :repo "https://git.bndl.org/amin/znc.el")
1888 :bind (("C-c a e e" . znc-erc)
1889 ("C-c a e a" . znc-all))
1890 :config
1891 (let ((pwd (let ((auth (auth-source-search :host "znca")))
1892 (cond
1893 ((null auth) (error "Couldn't find znca's authinfo"))
1894 (t (funcall (plist-get (car auth) :secret)))))))
1895 (setq znc-servers
1896 `(("znc.bndl.org" 1337 t
1897 ((freenode "amin/freenode" ,pwd)))
1898 ("znc.bndl.org" 1337 t
1899 ((moznet "amin/moznet" ,pwd)))))))
1900
1901 \f
1902 ;;; Post initialization
1903
1904 (message "Loading %s...done (%.3fs)" user-init-file
1905 (float-time (time-subtract (current-time)
1906 a/before-user-init-time)))
1907
1908 ;;; init.el ends here