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