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