[emacs] Update 2 drones
[~bandali/configs] / init.org
CommitLineData
180cab37
AB
1#+title: =aminb='s Literate Emacs Configuration
2#+author: Amin Bandali
3#+babel: :cache yes
4#+property: header-args :tangle yes
5
6* About
7:PROPERTIES:
8:CUSTOM_ID: about
9:END:
10
11This org file is my literate configuration for GNU Emacs, and is
3b98e899
AB
12tangled to [[./init.el][init.el]]. Packages are installed and managed using
13[[https://github.com/emacscollective/borg][Borg]]. Over the years, I've taken inspiration from configurations of
14many different people. Some of the configurations that I can remember
15off the top of my head are:
16
17- [[https://github.com/dieggsy/dotfiles][dieggsy/dotfiles]]: literate Emacs and dotfiles configuration, uses
18 straight.el for managing packages
19- [[https://github.com/dakra/dmacs][dakra/dmacs]]: literate Emacs configuration, using Borg for managing
20 packages
21- [[http://pages.sachachua.com/.emacs.d/Sacha.html][Sacha Chua's literate Emacs configuration]]
22- [[https://github.com/dakrone/eos][dakrone/eos]]
23- Ryan Rix's [[http://doc.rix.si/cce/cce.html][Complete Computing Environment]] ([[http://doc.rix.si/projects/fsem.html][about cce]])
24- [[https://github.com/jwiegley/dot-emacs][jwiegley/dot-emacs]]: nix-based configuration
25- [[https://github.com/wasamasa/dotemacs][wasamasa/dotemacs]]
26- [[https://github.com/hlissner/doom-emacs][Doom Emacs]]
180cab37
AB
27
28I'd like to have a fully reproducible Emacs setup (part of the reason
29why I store my configuration in this repository) but unfortunately out
30of the box, that's not achievable with =package.el=, not currently
31anyway. So, I've opted to use Borg. For what it's worth, I briefly
32experimented with [[https://github.com/raxod502/straight.el][straight.el]], but found that it added about 2 seconds
33to my init time; which is unacceptable for me: I use Emacs as my
34window manager (via EXWM) and coming from bspwm, I'm too used to
35having fast startup times.
36
3b98e899
AB
37** Installation
38
4ae2cd62
AB
39To use this config for your Emacs, first you need to clone this repo,
40then bootstrap Borg, tell Borg to retrieve package submodules, and
41byte-compiled the packages. Something along these lines should work:
42
4b4e432d 43#+begin_src sh :tangle no
4ae2cd62
AB
44git clone https://github.com/aminb/dotfiles ~/.emacs.d
45cd ~/.emacs.d
46make bootstrap-borg
4ae2cd62
AB
47make bootstrap
48make build
49#+end_src
50
180cab37
AB
51* Contents :toc_1:noexport:
52
53- [[#about][About]]
54- [[#header][Header]]
55- [[#initial-setup][Initial setup]]
56- [[#core][Core]]
967b0a82 57- [[#post-initialization][Post initialization]]
180cab37
AB
58- [[#footer][Footer]]
59
60* Header
61:PROPERTIES:
62:CUSTOM_ID: header
63:END:
64
65** First line
66
67#+begin_src emacs-lisp :comments none
68;;; init.el --- Amin Bandali's Emacs config -*- lexical-binding: t ; eval: (view-mode 1)-*-
69#+end_src
70
71Enable =view-mode=, which both makes the file read-only (as a reminder
72that =init.el= is an auto-generated file, not supposed to be edited),
73and provides some convenient key bindings for browsing through the
74file.
75
76** License
77
78#+begin_src emacs-lisp :comments none
2d7a5a85 79;; Copyright (C) 2018 Amin Bandali <bandali@gnu.org>
180cab37
AB
80
81;; This program is free software: you can redistribute it and/or modify
82;; it under the terms of the GNU General Public License as published by
83;; the Free Software Foundation, either version 3 of the License, or
84;; (at your option) any later version.
85
86;; This program is distributed in the hope that it will be useful,
87;; but WITHOUT ANY WARRANTY; without even the implied warranty of
88;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
89;; GNU General Public License for more details.
90
91;; You should have received a copy of the GNU General Public License
92;; along with this program. If not, see <https://www.gnu.org/licenses/>.
93#+end_src
94
95** Commentary
96
97#+begin_src emacs-lisp :comments none
98;;; Commentary:
99
100;; Emacs configuration of Amin Bandali, computer scientist and functional
101;; programmer.
102
103;; THIS FILE IS AUTO-GENERATED FROM `init.org'.
104#+end_src
105
106** Naming conventions
107
850dd012 108The conventions below were inspired by [[https://github.com/hlissner/doom-emacs][Doom]]'s, found [[https://github.com/hlissner/doom-emacs/blob/5dacbb7cb1c6ac246a9ccd15e6c4290def67757c/core/core.el#L3-L17][here]].
180cab37
AB
109
110#+begin_src emacs-lisp :comments none
111;; Naming conventions:
112;;
850dd012
AB
113;; amin-... public variables or non-interactive functions
114;; amin--... private anything (non-interactive), not safe for direct use
115;; amin/... an interactive function; safe for M-x or keybinding
116;; amin:... an evil operator, motion, or command
117;; amin|... a hook function
118;; amin*... an advising function
119;; amin@... a hydra command
120;; ...! a macro
180cab37
AB
121#+end_src
122
123* Initial setup
124:PROPERTIES:
125:CUSTOM_ID: initial-setup
126:END:
127
128#+begin_src emacs-lisp :comments none
129;;; Code:
130#+end_src
131
132** Emacs initialization
133
134I'd like to do a couple of measurements of Emacs' startup time. First,
135let's see how long Emacs takes to start up, before even loading
136=init.el=, i.e. =user-init-file=:
137
138#+begin_src emacs-lisp
850dd012 139(defvar amin--before-user-init-time (current-time)
180cab37
AB
140 "Value of `current-time' when Emacs begins loading `user-init-file'.")
141(message "Loading Emacs...done (%.3fs)"
850dd012 142 (float-time (time-subtract amin--before-user-init-time
180cab37
AB
143 before-init-time)))
144#+end_src
145
146Also, temporarily increase ~gc-cons-threshhold~ and
147~gc-cons-percentage~ during startup to reduce garbage collection
148frequency. Clearing the ~file-name-handler-alist~ seems to help reduce
149startup time as well.
150
151#+begin_src emacs-lisp
850dd012
AB
152(defvar amin--gc-cons-threshold gc-cons-threshold)
153(defvar amin--gc-cons-percentage gc-cons-percentage)
154(defvar amin--file-name-handler-alist file-name-handler-alist)
180cab37
AB
155(setq gc-cons-threshold (* 400 1024 1024) ; 400 MiB
156 gc-cons-percentage 0.6
157 file-name-handler-alist nil
158 ;; sidesteps a bug when profiling with esup
159 esup-child-profile-require-level 0)
160#+end_src
161
162Of course, we'd like to set them back to their defaults once we're
163done initializing.
164
165#+begin_src emacs-lisp
166(add-hook
167 'after-init-hook
168 (lambda ()
850dd012
AB
169 (setq gc-cons-threshold amin--gc-cons-threshold
170 gc-cons-percentage amin--gc-cons-percentage
171 file-name-handler-alist amin--file-name-handler-alist)))
180cab37
AB
172#+end_src
173
174Increase the number of lines kept in message logs (the =*Messages*=
175buffer).
176
177#+begin_src emacs-lisp
178(setq message-log-max 20000)
179#+end_src
180
181Optionally, we could suppress some byte compiler warnings like below,
182but for now I've decided to keep them enabled. See documentation for
183~byte-compile-warnings~ for more details.
184
185#+begin_src emacs-lisp
186;; (setq byte-compile-warnings
187;; '(not free-vars unresolved noruntime lexical make-local))
188#+end_src
189
41a4f26a
AB
190** whoami
191
192#+begin_src emacs-lisp
193(setq user-full-name "Amin Bandali"
2c0f7884 194 user-mail-address "amin@aminb.org")
41a4f26a
AB
195#+end_src
196
180cab37
AB
197** Package management
198
199*** No =package.el=
200
201I can do all my package management things with Borg, and don't need
202Emacs' built-in =package.el=. Emacs 27 lets us disable =package.el= in
203the =early-init-file= (see [[https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=24acb31c04b4048b85311d794e600ecd7ce60d3b][here]]).
204
205#+begin_src emacs-lisp :tangle early-init.el
206(setq package-enable-at-startup nil)
207#+end_src
208
209But since Emacs 27 isn't out yet (Emacs 26 is just around the corner
210right now), and even when released it'll be long before most distros
211ship in their repos, I'll still put the old workaround with the
212commented call to ~package-initialize~ here anyway.
213
214#+begin_src emacs-lisp
215(setq package-enable-at-startup nil)
216;; (package-initialize)
217#+end_src
218
219*** Borg
220
221#+begin_quote
222Assimilate Emacs packages as Git submodules
223#+end_quote
224
225[[https://github.com/emacscollective/borg][Borg]] is at the heart of package management of my Emacs setup. In
226short, it creates a git submodule in =lib/= for each package, which
227can then be managed with the help of Magit or other tools.
228
229#+begin_src emacs-lisp
230(setq user-init-file (or load-file-name buffer-file-name)
231 user-emacs-directory (file-name-directory user-init-file))
232(add-to-list 'load-path
233 (expand-file-name "lib/borg" user-emacs-directory))
234(require 'borg)
235(borg-initialize)
d14698a3 236
87f61b04
AB
237;; (require 'borg-nix-shell)
238;; (setq borg-build-shell-command 'borg-nix-shell-build-command)
0f3d4eb5 239
d14698a3 240(with-eval-after-load 'bind-key
d14698a3
AB
241 (bind-keys
242 :package borg
3e03ee84
AB
243 ("C-c b A" . borg-activate)
244 ("C-c b a" . borg-assimilate)
245 ("C-c b b" . borg-build)
246 ("C-c b c" . borg-clone)
3e03ee84 247 ("C-c b r" . borg-remove)))
180cab37
AB
248#+end_src
249
250*** =use-package=
251
252#+begin_quote
253A use-package declaration for simplifying your .emacs
254#+end_quote
255
256[[https://github.com/jwiegley/use-package][use-package]] is an awesome utility for managing and configuring
257packages (in our case especially the latter) in a neatly organized way
258and without compromising on performance.
259
260#+begin_src emacs-lisp
261(require 'use-package)
eb186a5a 262(if nil ; set to t when need to debug init
180cab37
AB
263 (setq use-package-verbose t
264 use-package-expand-minimally nil
265 use-package-compute-statistics t
266 debug-on-error t)
267 (setq use-package-verbose nil
268 use-package-expand-minimally t))
269#+end_src
270
271*** Epkg
272
273#+begin_quote
274Browse the Emacsmirror package database
275#+end_quote
276
277Epkg provides access to a local copy of the [[https://emacsmirror.net][Emacsmirror]] package
278database, low-level functions for querying the database, and a
279=package.el=-like user interface for browsing the available packages.
280
281#+begin_src emacs-lisp
282(use-package epkg
d14698a3
AB
283 :defer t
284 :bind
3e03ee84
AB
285 (("C-c b d" . epkg-describe-package)
286 ("C-c b p" . epkg-list-packages)
287 ("C-c b u" . epkg-update)))
180cab37
AB
288#+end_src
289
290** No littering in =~/.emacs.d=
291
292#+begin_quote
293Help keeping ~/.emacs.d clean
294#+end_quote
295
296By default, even for Emacs' built-in packages, the configuration files
297and persistent data are all over the place. Use =no-littering= to help
298contain the mess.
299
300#+begin_src emacs-lisp
301(use-package no-littering
302 :demand t
303 :config
304 (savehist-mode 1)
305 (add-to-list 'savehist-additional-variables 'kill-ring)
306 (save-place-mode 1)
307 (setq auto-save-file-name-transforms
308 `((".*" ,(no-littering-expand-var-file-name "auto-save/") t))))
309#+end_src
310
180cab37
AB
311** Custom file (=custom.el=)
312
313I'm not planning on using the custom file much, but even so, I
314definitely don't want it mixing with =init.el=. So, here; let's give
315it it's own file. While at it, treat themes as safe.
316
317#+begin_src emacs-lisp
318(use-package custom
319 :no-require t
320 :config
321 (setq custom-file (no-littering-expand-etc-file-name "custom.el"))
322 (when (file-exists-p custom-file)
323 (load custom-file))
324 (setf custom-safe-themes t))
325#+end_src
326
313f5877
AB
327** Secrets file
328
319010c3
AB
329Load the secrets file if it exists, otherwise show a warning.
330
313f5877 331#+begin_src emacs-lisp
319010c3
AB
332(with-demoted-errors
333 (load (no-littering-expand-etc-file-name "secrets")))
313f5877
AB
334#+end_src
335
180cab37
AB
336** Better =$PATH= handling
337
338Let's use [[https://github.com/purcell/exec-path-from-shell][exec-path-from-shell]] to make Emacs use the =$PATH= as set up
339in my shell.
340
341#+begin_src emacs-lisp
7538956f
AB
342(use-package exec-path-from-shell
343 :defer 1
344 :init
345 (setq exec-path-from-shell-check-startup-files nil)
346 :config
347 (exec-path-from-shell-initialize)
348 ;; while we're at it, let's fix access to our running ssh-agent
349 (exec-path-from-shell-copy-env "SSH_AGENT_PID")
350 (exec-path-from-shell-copy-env "SSH_AUTH_SOCK"))
180cab37
AB
351#+end_src
352
1f56a9b9 353** COMMENT Only one custom theme at a time
ebec2c18
AB
354
355#+begin_src emacs-lisp
356(defadvice load-theme (before clear-previous-themes activate)
357 "Clear existing theme settings instead of layering them"
358 (mapc #'disable-theme custom-enabled-themes))
359#+end_src
360
dfe440bc 361** Server
180cab37
AB
362
363Start server if not already running. Alternatively, can be done by
364issuing =emacs --daemon= in the terminal, which can be automated with
365a systemd service or using =brew services start emacs= on macOS. I use
366Emacs as my window manager (via EXWM), so I always start Emacs on
367login; so starting the server from inside Emacs is good enough for me.
368
369See [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Server.html#Emacs-Server][Using Emacs as a Server]].
370
371#+begin_src emacs-lisp
372(use-package server
ce842fdf 373 :defer 1
180cab37
AB
374 :config (or (server-running-p) (server-mode)))
375#+end_src
376
e27e0383 377** COMMENT Unicode support
e9bcfa30
AB
378
379Font stack with better unicode support, around =Ubuntu Mono= and
380=Hack=.
381
1f2bc66e 382#+begin_src emacs-lisp :tangle no
e9bcfa30
AB
383(dolist (ft (fontset-list))
384 (set-fontset-font
385 ft
386 'unicode
1f2bc66e 387 (font-spec :name "Source Code Pro" :size 14))
e9bcfa30
AB
388 (set-fontset-font
389 ft
390 'unicode
16d70d6f 391 (font-spec :name "DejaVu Sans Mono")
e9bcfa30
AB
392 nil
393 'append)
16d70d6f
AB
394 ;; (set-fontset-font
395 ;; ft
396 ;; 'unicode
397 ;; (font-spec
398 ;; :name "Symbola monospacified for DejaVu Sans Mono")
399 ;; nil
400 ;; 'append)
401 ;; (set-fontset-font
402 ;; ft
403 ;; #x2115 ; ℕ
404 ;; (font-spec :name "DejaVu Sans Mono")
405 ;; nil
406 ;; 'append)
e9bcfa30
AB
407 (set-fontset-font
408 ft
16d70d6f
AB
409 (cons ?Α ?ω)
410 (font-spec :name "DejaVu Sans Mono" :size 14)
e9bcfa30 411 nil
16d70d6f 412 'prepend))
e9bcfa30
AB
413#+end_src
414
523e4f87
AB
415** Gentler font resizing
416
417#+begin_src emacs-lisp
418(setq text-scale-mode-step 1.05)
419#+end_src
420
b9d46ec7
AB
421** Focus follows mouse
422
423I’d like focus to follow the mouse when I move the cursor from one
424window to the next.
425
426#+begin_src emacs-lisp
427(setq mouse-autoselect-window t)
428#+end_src
429
430Let’s define a function to conveniently disable this for certain
431buffers and/or modes.
432
433#+begin_src emacs-lisp
434(defun amin--no-mouse-autoselect-window ()
435 (make-local-variable 'mouse-autoselect-window)
436 (setq mouse-autoselect-window nil))
437#+end_src
438
51db62d8
AB
439** Libraries
440
441#+begin_src emacs-lisp
442(require 'cl-lib)
443(require 'subr-x)
444#+end_src
445
446** Useful utilities
447
448#+begin_src emacs-lisp
850dd012 449(defun amin-enlist (exp)
51db62d8
AB
450 "Return EXP wrapped in a list, or as-is if already a list."
451(if (listp exp) exp (list exp)))
452
453; from https://github.com/hlissner/doom-emacs/commit/589108fdb270f24a98ba6209f6955fe41530b3ef
454(defmacro after! (features &rest body)
455 "A smart wrapper around `with-eval-after-load'. Supresses warnings during
456compilation."
457 (declare (indent defun) (debug t))
458 (list (if (or (not (bound-and-true-p byte-compile-current-file))
850dd012 459 (dolist (next (amin-enlist features))
51db62d8
AB
460 (if (symbolp next)
461 (require next nil :no-error)
462 (load next :no-message :no-error))))
463 #'progn
464 #'with-no-warnings)
465 (cond ((symbolp features)
466 `(eval-after-load ',features '(progn ,@body)))
467 ((and (consp features)
468 (memq (car features) '(:or :any)))
469 `(progn
470 ,@(cl-loop for next in (cdr features)
471 collect `(after! ,next ,@body))))
472 ((and (consp features)
473 (memq (car features) '(:and :all)))
474 (dolist (next (cdr features))
475 (setq body `(after! ,next ,@body)))
476 body)
477 ((listp features)
eb186a5a 478 `(after! (:all ,@features) ,@body)))))
51db62d8
AB
479#+end_src
480
2090f409
AB
481Convenience macro for =setq='ing multiple variables to the same value:
482
483#+begin_src emacs-lisp
484(defmacro setq-every! (value &rest vars)
485 "Set all the variables from VARS to value VALUE."
486 (declare (indent defun) (debug t))
487 `(progn ,@(mapcar (lambda (x) (list 'setq x value)) vars)))
488#+end_src
489
180cab37
AB
490* Core
491:PROPERTIES:
492:CUSTOM_ID: core
493:END:
494
495** Defaults
496
e602de37
AB
497*** Time and battery in mode-line
498
499Enable displaying time and battery in the mode-line, since I'm not
500using the Xfce panel anymore. Also, I don't need to see the load
501average on a regular basis, so disable that.
502
63073abd
AB
503Note: using =i3status= on sway at the moment, so disabling this.
504
505#+begin_src emacs-lisp :tangle no
e602de37 506(use-package time
e602de37
AB
507 :init
508 (setq display-time-default-load-average nil)
509 :config
510 (display-time-mode))
511
512(use-package battery
e602de37
AB
513 :config
514 (display-battery-mode))
515#+end_src
516
180cab37
AB
517*** Smaller fringe
518
2f8102f0
AB
519Might want to set the fringe to a smaller value, especially if using
520EXWM. I'm fine with the default for now.
180cab37
AB
521
522#+begin_src emacs-lisp
2f8102f0 523;; (fringe-mode '(3 . 1))
4b4e432d 524(fringe-mode nil)
180cab37
AB
525#+end_src
526
527*** Disable disabled commands
528
529Emacs disables some commands by default that could persumably be
530confusing for novice users. Let's disable that.
531
532#+begin_src emacs-lisp
533(setq disabled-command-function nil)
534#+end_src
535
536*** Kill-ring
537
538Save what I copy into clipboard from other applications into Emacs'
539kill-ring, which would allow me to still be able to easily access it
540in case I kill (cut or copy) something else inside Emacs before
541yanking (pasting) what I'd originally intended to.
542
543#+begin_src emacs-lisp
544(setq save-interprogram-paste-before-kill t)
545#+end_src
546
547*** Minibuffer
548
549#+begin_src emacs-lisp
550(setq enable-recursive-minibuffers t
551 resize-mini-windows t)
552#+end_src
553
554*** Lazy-person-friendly yes/no prompts
555
556Lazy people would prefer to type fewer keystrokes, especially for yes
557or no questions. I'm lazy.
558
559#+begin_src emacs-lisp
560(defalias 'yes-or-no-p #'y-or-n-p)
561#+end_src
562
563*** Startup screen and =*scratch*=
564
565Firstly, let Emacs know that I'd like to have =*scratch*= as my
566startup buffer.
567
568#+begin_src emacs-lisp
569(setq initial-buffer-choice t)
570#+end_src
571
572Now let's customize the =*scratch*= buffer a bit. First off, I don't
573need the default hint.
574
575#+begin_src emacs-lisp
576(setq initial-scratch-message nil)
577#+end_src
578
579Also, let's use Text mode as the major mode, in case I want to
580customize it (=*scratch*='s default major mode, Fundamental mode,
581can't really be customized).
582
583#+begin_src emacs-lisp
584(setq initial-major-mode 'text-mode)
585#+end_src
586
587Inhibit the buffer list when more than 2 files are loaded.
588
589#+begin_src emacs-lisp
590(setq inhibit-startup-buffer-menu t)
591#+end_src
592
593I don't really need to see the startup screen or echo area message
594either.
595
596#+begin_src emacs-lisp
597(advice-add #'display-startup-echo-area-message :override #'ignore)
598(setq inhibit-startup-screen t
599 inhibit-startup-echo-area-message user-login-name)
600#+end_src
601
602*** More useful frame titles
603
604Show either the file name or the buffer name (in case the buffer isn't
605visiting a file). Borrowed from Emacs Prelude.
606
607#+begin_src emacs-lisp
608(setq frame-title-format
609 '("" invocation-name " - "
610 (:eval (if (buffer-file-name)
611 (abbreviate-file-name (buffer-file-name))
612 "%b"))))
613#+end_src
614
615*** Backups
616
617Emacs' default backup settings aren't that great. Let's use more
618sensible options. See documentation for the ~make-backup-file~
619variable.
620
621#+begin_src emacs-lisp
622(setq backup-by-copying t
72a03130
AB
623 version-control t
624 delete-old-versions t)
180cab37
AB
625#+end_src
626
89394449
AB
627*** Auto revert
628
629Enable automatic reloading of changed buffers and files.
630
631#+begin_src emacs-lisp
632(global-auto-revert-mode 1)
633(setq auto-revert-verbose nil
0e340dbb 634 global-auto-revert-non-file-buffers nil)
89394449
AB
635#+end_src
636
637*** Always use space for indentation
638
639#+begin_src emacs-lisp
640(setq-default
641 indent-tabs-mode nil
642 require-final-newline t
643 tab-width 4)
644#+end_src
645
d14698a3
AB
646*** Winner mode
647
648Enable =winner-mode=.
649
650#+begin_src emacs-lisp
651(winner-mode 1)
652#+end_src
653
165ca268
AB
654*** Close =*compilation*= on success
655
656#+begin_src emacs-lisp
657(setq compilation-exit-message-function
658 (lambda (status code msg)
659 "Close the compilation window if successful."
660 ;; if M-x compile exits with 0
661 (when (and (eq status 'exit) (zerop code))
662 (bury-buffer)
663 (delete-window (get-buffer-window (get-buffer "*compilation*"))))
664 ;; return the result of compilation-exit-message-function
665 (cons msg code)))
666#+end_src
667
d409a2cf
AB
668*** Search for non-ASCII characters
669
670I’d like non-ASCII characters such as ‘’“”«»‹›áⓐ𝒶 to be selected when
671I search for their ASCII counterpart. Shoutout to [[http://endlessparentheses.com/new-in-emacs-25-1-easily-search-non-ascii-characters.html][endlessparentheses]]
672for this.
673
674#+begin_src emacs-lisp
675(setq search-default-mode #'char-fold-to-regexp)
676
677;; uncomment to extend this behaviour to query-replace
678;; (setq replace-char-fold t)
679#+end_src
680
d14698a3
AB
681** Bindings
682
06e16600 683#+begin_src emacs-lisp
d14698a3 684(bind-keys
3c3055c7
AB
685 ("s-c e b" . eval-buffer)
686 ("s-c e r" . eval-region)
11c0d265 687
3c3055c7
AB
688 ("s-p" . beginning-of-buffer)
689 ("s-n" . end-of-buffer))
d14698a3
AB
690#+end_src
691
180cab37
AB
692** Packages
693
694The packages in this section are absolutely essential to my everyday
695workflow, and they play key roles in how I do my computing. They
696immensely enhance the Emacs experience for me; both using Emacs, and
697customizing it.
698
699*** [[https://github.com/emacscollective/auto-compile][auto-compile]]
700
701#+begin_src emacs-lisp
702(use-package auto-compile
703 :demand t
704 :config
705 (auto-compile-on-load-mode)
706 (auto-compile-on-save-mode)
707 (setq auto-compile-display-buffer nil
eb186a5a
AB
708 auto-compile-mode-line-counter t
709 auto-compile-source-recreate-deletes-dest t
710 auto-compile-toggle-deletes-nonlib-dest t
711 auto-compile-update-autoloads t)
180cab37
AB
712 (add-hook 'auto-compile-inhibit-compile-hook
713 'auto-compile-inhibit-compile-detached-git-head))
714#+end_src
715
3e03ee84
AB
716*** [[https://github.com/noctuid/general.el][general]]
717
718#+begin_src emacs-lisp
719(use-package general
720 :demand t
721 :config
722 (general-evil-setup t)
723 (general-override-mode)
724
725 (general-create-definer
726 amin--leader-keys
727 :keymaps 'override
728 :states '(emacs normal visual motion insert)
729 :non-normal-prefix "M-m"
730 :prefix "SPC"))
731#+end_src
732
733*** [[https://github.com/emacs-evil/evil][evil]]
734
735#+begin_src emacs-lisp
736(use-package evil
737 :demand t
738 ;; :hook (org-src-mode . evil-motion-state)
3e03ee84
AB
739 :config
740 (evil-mode 1)
741 (general-swap-key nil '(normal motion) ";" ":")
742
268e1077
AB
743 (setq evil-want-visual-char-semi-exclusive t
744 evil-cross-lines t)
3e03ee84 745
f333db13 746 ;; custom mode state mappings
7d1b2f9a
AB
747 (dolist (mspair '((ebdb-mode . emacs)
748 (term-mode . emacs)
749 (helpful-mode . motion)
750 (magit-blame-mode . motion)
751 (view-mode . motion)))
f333db13 752 (evil-set-initial-state (car mspair) (cdr mspair)))
3e03ee84
AB
753
754 ;; fix tab and indentation in src blocks inside org-mode buffer
755 ;; also see https://git.sr.ht/~bandali/dotfiles/commit/0e2ffd584aafdd4cf256bcdf2473f01c3aaaed55
05f602d9
AB
756 (unbind-key "TAB" evil-motion-state-map)
757
758 (unbind-key "C-d" evil-insert-state-map)
759 (unbind-key "C-v" evil-insert-state-map)
760 (unbind-key "C-y" evil-insert-state-map)
761 (unbind-key "C-a" evil-insert-state-map)
762 (unbind-key "C-e" evil-insert-state-map)
763 (unbind-key "C-p" evil-insert-state-map)
837dacf9
AB
764 (unbind-key "C-n" evil-insert-state-map)
765 (unbind-key "C-k" evil-insert-state-map)
766 (bind-keys
767 :map evil-insert-state-map
768 ("C-k" . kill-line)
769 ("C-S-k" . evil-insert-digraph)
770 :map evil-motion-state-map
771 ([down-mouse-1] . nil)))
3e03ee84
AB
772#+end_src
773
774#+begin_src emacs-lisp
775(use-package evil-escape
776 :after evil
777 :init
778 (setq evil-escape-excluded-states '(normal visual multiedit emacs motion)
779 evil-escape-excluded-major-modes '(neotree-mode)
780 evil-escape-key-sequence "jk"
781 evil-escape-delay 0.25)
782 ;; :general
783 ;; (:states '(insert replace visual operator)
784 ;; "C-g" #'evil-escape)
785 :config
786 (evil-escape-mode 1)
787 ;; no `evil-escape' in minibuffer
788 (push #'minibufferp evil-escape-inhibit-functions))
789#+end_src
790
7e18e28d
AB
791#+begin_src emacs-lisp
792(use-package evil-nerd-commenter
793 :after evil
794 :general
795 (nmap
796 "gc" 'evilnc-comment-operator
797 "gy" 'evilnc-copy-and-comment-lines))
798#+end_src
799
800#+begin_src emacs-lisp
801(use-package evil-surround
802 :after evil
803 :general
804 (omap
805 "s" 'evil-surround-edit
806 "S" 'evil-Surround-edit)
807 (vmap
808 "S" 'evil-surround-region
809 "gS" 'evil-Surround-region))
810#+end_src
811
3e03ee84
AB
812#+begin_src emacs-lisp
813(amin--leader-keys
814 "/" '(:ignore t :wk "search")
815
0864b4db
AB
816 "a" '(:ignore t :wk "apps")
817 "a i" 'ielm
818
12f3e4b8
AB
819 "a s" '(:ignore t :wk "shells/terms")
820
3e03ee84
AB
821 "b" '(:ignore t :wk "buffers")
822 "b k" 'kill-this-buffer
823 "b s" 'save-buffer
824
05f602d9
AB
825 "e" '(:ignore t :wk "eval")
826 "e b" 'eval-buffer
827 "e r" 'eval-region
828
3e03ee84
AB
829 "f" '(:ignore t :wk "files")
830
05f602d9
AB
831 "F" '(:ignore t :wk "frames")
832 "F m" 'make-frame-command
833 "F d" 'delete-frame
834 "F D" 'delete-other-frames
835
3e03ee84
AB
836 "h" '(:ignore t :wk "help(ful)")
837 "h c" 'describe-char
838 "h f" 'describe-function
839 "h F" 'describe-face
840 "h H" 'view-hello-file
841 "h i" 'info
842 "h k" 'describe-key
843 "h l" 'view-lossage
844 "h v" 'describe-variable
845
846 "o" 'other-window
847
848 "w" '(:ignore t :wk "window")
849 "w o" 'other-window
18f7141a
AB
850 "w 0" 'delete-window
851 "w 1" 'delete-other-windows
852 "w 2" 'split-window-below
853 "w 3" 'split-window-right
854 "w u" 'winner-undo
855 "w r" 'winner-redo
3e03ee84
AB
856
857 "q" '(:ignore t :wk "quit")
858 "q q" 'save-buffers-kill-terminal)
859#+end_src
860
180cab37
AB
861*** [[https://orgmode.org/][Org mode]]
862
863#+begin_quote
864Org mode is for keeping notes, maintaining TODO lists, planning
865projects, and authoring documents with a fast and effective plain-text
866system.
867#+end_quote
868
869In short, my favourite way of life.
870
871#+begin_src emacs-lisp
51f3b22b 872(use-package org
b2d378eb 873 :defer 1
3e03ee84
AB
874 :general
875 (amin--leader-keys
876 :states 'normal
877 :keymaps 'org-mode-map
878 "'" 'org-edit-special)
879 (amin--leader-keys
880 :definer 'minor-mode
881 :states 'normal
882 :keymaps 'org-src-mode
883 "'" 'org-edit-src-exit
884 "k" 'org-edit-src-abort)
885 (general-define-key
886 :definer 'minor-mode
887 :states 'normal
888 :keymaps 'org-src-mode
889 "q" 'org-edit-src-exit)
51f3b22b
AB
890 :config
891 (setq org-src-tab-acts-natively t
892 org-src-preserve-indentation nil
5ebf6597 893 org-edit-src-content-indentation 0
3e70dc4a 894 org-email-link-description-format "Email %c: %s" ; %.30s
4b4c2c1d 895 org-highlight-latex-and-related '(entities)
5ebf6597 896 org-log-done 'time)
39ecbcc0 897 (add-to-list 'org-structure-template-alist '("L" . "src emacs-lisp") t)
3e03ee84
AB
898 (after! org-src
899 (define-key org-src-mode-map [remap evil-write] 'org-edit-src-save)
900 (define-key org-src-mode-map [remap evil-save-and-close]
901 (lambda () (interactive)
902 (org-edit-src-save)
903 (org-edit-src-exit)))
904 (define-key org-src-mode-map [remap evil-save-modified-and-close]
905 (lambda () (interactive)
906 (org-edit-src-save)
907 (org-edit-src-exit)))
908 (define-key org-src-mode-map [remap evil-quit] 'org-edit-src-abort))
4b4c2c1d
AB
909 (font-lock-add-keywords
910 'org-mode
911 '(("[ \t]*\\(#\\+\\(BEGIN\\|END\\|begin\\|end\\)_\\(\\S-+\\)\\)[ \t]*\\([^\n:]*\\)"
912 (1 '(:foreground "#5a5b5a" :background "#292b2b") t) ; directive
913 (3 '(:foreground "#81a2be" :background "#292b2b") t) ; kind
914 (4 '(:foreground "#c5c8c6") t))) ; title
915 t)
3e70dc4a 916 :bind (:map org-mode-map ("M-L" . org-insert-last-stored-link))
bdf99c0d
AB
917 :hook ((org-mode . org-indent-mode)
918 (org-mode . auto-fill-mode)
919 (org-mode . flyspell-mode))
3e7e82b4 920 :custom
4b4c2c1d
AB
921 (org-latex-packages-alist '(("" "listings") ("" "color")))
922 :custom-face
923 '(org-block-begin-line ((t (:foreground "#5a5b5a" :background "#1d1f21"))))
924 '(org-block ((t (:background "#1d1f21"))))
925 '(org-latex-and-related ((t (:foreground "#b294bb")))))
3e7e82b4
AB
926
927(use-package ox-latex
ce842fdf 928 :after ox
3e7e82b4 929 :config
3bb16326
AB
930 (setq org-latex-listings 'listings
931 ;; org-latex-prefer-user-labels t
932 )
3e7e82b4
AB
933 (add-to-list 'org-latex-packages-alist '("" "listings"))
934 (add-to-list 'org-latex-packages-alist '("" "color"))
935 (add-to-list 'org-latex-classes
936 '("IEEEtran" "\\documentclass[11pt]{IEEEtran}"
937 ("\\section{%s}" . "\\section*{%s}")
938 ("\\subsection{%s}" . "\\subsection*{%s}")
939 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
940 ("\\paragraph{%s}" . "\\paragraph*{%s}")
941 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
942 t))
6578a877 943
ce842fdf
AB
944(use-package ox-beamer
945 :after ox)
6bda705d 946
3e03ee84
AB
947(use-package ob-tangle
948 :general
949 (amin--leader-keys
950 :states 'normal
951 :keymaps 'org-mode-map
952 "b t" 'org-babel-tangle))
953
a4aa1167 954(use-package orgalist
ce842fdf 955 :after message
a4aa1167 956 :hook (message-mode . orgalist-mode))
180cab37
AB
957#+end_src
958
eb689aa4
AB
959**** asynchronous tangle
960
961=amin/async-babel-tangle= is a function closely inspired by [[https://github.com/dieggsy/dotfiles/tree/cc10edf7701958eff1cd94d4081da544d882a28c/emacs.d#dotfiles][dieggsy's
962d/async-babel-tangle]] which uses [[https://github.com/jwiegley/emacs-async][async]] to asynchronously tangle an org
963file.
964
965#+begin_src emacs-lisp
966(after! org
967 (defvar amin-show-async-tangle-results nil
968 "Keep *emacs* async buffers around for later inspection.")
969
970 (defvar amin-show-async-tangle-time nil
971 "Show the time spent tangling the file.")
972
b07c1cc4
AB
973 (defvar amin-async-tangle-post-compile "make ti"
974 "If non-nil, pass to `compile' after successful tangle.")
975
eb689aa4
AB
976 (defun amin/async-babel-tangle ()
977 "Tangle org file asynchronously."
978 (interactive)
979 (let* ((file-tangle-start-time (current-time))
980 (file (buffer-file-name))
981 (file-nodir (file-name-nondirectory file))
982 (async-quiet-switch "-q"))
983 (async-start
984 `(lambda ()
985 (require 'org)
986 (org-babel-tangle-file ,file))
987 (unless amin-show-async-tangle-results
988 `(lambda (result)
989 (if result
b07c1cc4
AB
990 (progn
991 (message "Tangled %s%s"
992 ,file-nodir
993 (if amin-show-async-tangle-time
994 (format " (%.3fs)"
995 (float-time (time-subtract (current-time)
996 ',file-tangle-start-time)))
997 ""))
998 (when amin-async-tangle-post-compile
999 (compile amin-async-tangle-post-compile)))
eb689aa4
AB
1000 (message "Tangling %s failed" ,file-nodir))))))))
1001
1002(add-to-list
1003 'safe-local-variable-values
1004 '(eval add-hook 'after-save-hook #'amin/async-babel-tangle 'append 'local))
1005#+end_src
1006
180cab37
AB
1007*** [[https://magit.vc/][Magit]]
1008
1009#+begin_quote
1010It's Magit! A Git porcelain inside Emacs.
1011#+end_quote
1012
1013Not just how I do git, but /the/ way to do git.
1014
1015#+begin_src emacs-lisp
1016(use-package magit
b2d378eb 1017 :defer 1
bb7be9d4
AB
1018 :general
1019 (amin--leader-keys
1020 "g s" 'magit-status
1021 "g l" 'magit-log-buffer-file)
3e03ee84 1022 :bind ("s-g" . magit-status)
180cab37
AB
1023 :config
1024 (magit-add-section-hook 'magit-status-sections-hook
1025 'magit-insert-modules
1026 'magit-insert-stashes
1278d522 1027 'append)
05f602d9
AB
1028 (setq
1029 magit-repository-directories '(("~/.emacs.d/" . 0)
1030 ("~/src/git/" . 1)))
d7e1ea83
AB
1031 (nconc magit-section-initial-visibility-alist
1032 '(([unpulled status] . show)
1033 ([unpushed status] . show)))
1278d522 1034 :custom-face (magit-diff-file-heading ((t (:weight normal)))))
180cab37
AB
1035#+end_src
1036
1037*** [[https://github.com/abo-abo/swiper][Ivy]] (and friends)
1038
1039#+begin_quote
1040Ivy - a generic completion frontend for Emacs, Swiper - isearch with
1041an overview, and more. Oh, man!
1042#+end_quote
1043
1044There's no way I could top that, so I won't attempt to.
1045
1046**** Ivy
1047
1048#+begin_src emacs-lisp
f7752223 1049(use-package ivy
3ea5e792 1050 :defer 1
3e03ee84 1051 :general (amin--leader-keys "," 'ivy-switch-buffer)
f7752223 1052 :bind
3e03ee84 1053 (:map ivy-minibuffer-map
d14698a3
AB
1054 ([escape] . keyboard-escape-quit)
1055 ([S-up] . ivy-previous-history-element)
1056 ([S-down] . ivy-next-history-element)
1057 ("DEL" . ivy-backward-delete-char))
f7752223 1058 :config
f6d8e3e4 1059 (setq ivy-wrap t)
1278d522 1060 (ivy-mode 1)
4b4c2c1d
AB
1061 ;; :custom-face
1062 ;; (ivy-minibuffer-match-face-2 ((t (:background "#e99ce8" :weight semi-bold))))
1063 ;; (ivy-minibuffer-match-face-3 ((t (:background "#bbbbff" :weight semi-bold))))
1064 ;; (ivy-minibuffer-match-face-4 ((t (:background "#ffbbff" :weight semi-bold))))
1065)
180cab37
AB
1066#+end_src
1067
1068**** Swiper
1069
1070#+begin_src emacs-lisp
f7752223 1071(use-package swiper
3e03ee84 1072 :general (:states '(normal motion) "/" 'swiper)
f811cdad
AB
1073 :bind (("C-s" . swiper)
1074 ("C-r" . swiper)))
180cab37
AB
1075#+end_src
1076
1077**** Counsel
1078
1079#+begin_src emacs-lisp
f7752223 1080(use-package counsel
3d35bdff 1081 :defer 1
3e03ee84
AB
1082 :general
1083 (amin--leader-keys
1084 "r" 'counsel-recentf
1085 "SPC" 'counsel-M-x
1086 "." 'counsel-find-file)
f7752223 1087 :bind (([remap execute-extended-command] . counsel-M-x)
d14698a3
AB
1088 ([remap find-file] . counsel-find-file)
1089 ("s-r" . counsel-recentf)
06e16600
AB
1090 ("C-c x" . counsel-M-x)
1091 ("C-c f ." . counsel-find-file)
f7752223 1092 :map minibuffer-local-map
eb186a5a 1093 ("C-r" . counsel-minibuffer-history))
f7752223
AB
1094 :config
1095 (counsel-mode 1)
1096 (defalias 'locate #'counsel-locate))
180cab37
AB
1097#+end_src
1098
4d987946
AB
1099*** eshell
1100
1101#+begin_src emacs-lisp
1102(use-package eshell
1b93c5be 1103 :defer 1
4d987946
AB
1104 :commands eshell
1105 :config
1106 (eval-when-compile (defvar eshell-prompt-regexp))
1107 (defun amin/eshell-quit-or-delete-char (arg)
1108 (interactive "p")
1109 (if (and (eolp) (looking-back eshell-prompt-regexp nil))
1110 (eshell-life-is-too-much)
1111 (delete-char arg)))
1112
a8702c03
AB
1113 (defun amin/eshell-clear ()
1114 (interactive)
1115 (let ((inhibit-read-only t))
1116 (erase-buffer))
1117 (eshell-send-input))
1118
4d987946 1119 (defun amin|eshell-setup ()
933e8d27
AB
1120 (make-local-variable 'company-idle-delay)
1121 (setq company-idle-delay nil)
4d987946 1122 (bind-keys :map eshell-mode-map
f314414d
AB
1123 ("C-d" . amin/eshell-quit-or-delete-char)
1124 ("C-S-l" . amin/eshell-clear)
1125 ("M-r" . counsel-esh-history)
1126 ([tab] . company-complete)))
4d987946 1127
933e8d27
AB
1128 :hook (eshell-mode . amin|eshell-setup)
1129 :custom
1130 (eshell-hist-ignoredups t)
1131 (eshell-input-filter 'eshell-input-filter-initial-space))
4d987946
AB
1132#+end_src
1133
4d86735a
AB
1134*** Ibuffer
1135
1136#+begin_src emacs-lisp
1137(use-package ibuffer
ce842fdf 1138 :defer t
3e03ee84 1139 :general (amin--leader-keys "b b" 'ibuffer-other-window)
4d86735a
AB
1140 :bind
1141 (("C-x C-b" . ibuffer-other-window)
4d86735a
AB
1142 :map ibuffer-mode-map
1143 ("P" . ibuffer-backward-filter-group)
1144 ("N" . ibuffer-forward-filter-group)
1145 ("M-p" . ibuffer-do-print)
1146 ("M-n" . ibuffer-do-shell-command-pipe-replace))
1147 :config
1148 ;; Use human readable Size column instead of original one
1149 (define-ibuffer-column size-h
1150 (:name "Size" :inline t)
1151 (cond
1152 ((> (buffer-size) 1000000) (format "%7.1fM" (/ (buffer-size) 1000000.0)))
1153 ((> (buffer-size) 100000) (format "%7.0fk" (/ (buffer-size) 1000.0)))
1154 ((> (buffer-size) 1000) (format "%7.1fk" (/ (buffer-size) 1000.0)))
1155 (t (format "%8d" (buffer-size)))))
1156 :custom
1157 (ibuffer-saved-filter-groups
1158 '(("default"
1159 ("dired" (mode . dired-mode))
9e756a57 1160 ("org" (mode . org-mode))
4d86735a
AB
1161 ("web"
1162 (or
1163 (mode . web-mode)
746c8c1a
AB
1164 (mode . css-mode)
1165 (mode . scss-mode)
4d86735a
AB
1166 (mode . js2-mode)))
1167 ("shell"
1168 (or
1169 (mode . eshell-mode)
1170 (mode . shell-mode)))
1171 ("notmuch" (name . "\*notmuch\*"))
1172 ("programming"
1173 (or
1174 (mode . python-mode)
1175 (mode . c++-mode)
1176 (mode . emacs-lisp-mode)))
1177 ("emacs"
1178 (or
1179 (name . "^\\*scratch\\*$")
3bb16326
AB
1180 (name . "^\\*Messages\\*$")))
1181 ("slack"
1182 (or
1183 (name . "^\\*Slack*"))))))
4d86735a
AB
1184 (ibuffer-formats
1185 '((mark modified read-only locked " "
1186 (name 18 18 :left :elide)
1187 " "
1188 (size-h 9 -1 :right)
1189 " "
1190 (mode 16 16 :left :elide)
1191 " " filename-and-process)
1192 (mark " "
1193 (name 16 -1)
1194 " " filename)))
1195 :hook (ibuffer . (lambda () (ibuffer-switch-to-saved-filter-groups "default"))))
1196#+end_src
1197
458ff84b
AB
1198*** Outline
1199
1200#+begin_src emacs-lisp
1201(use-package outline
ce842fdf 1202 :defer t
458ff84b
AB
1203 :hook (prog-mode . outline-minor-mode)
1204 :bind
1205 (:map
1206 outline-minor-mode-map
1207 ("<s-tab>" . outline-toggle-children)
3ffa4732
AB
1208 ("M-p" . outline-previous-visible-heading)
1209 ("M-n" . outline-next-visible-heading)
458ff84b
AB
1210 :prefix-map amin--outline-prefix-map
1211 :prefix "s-o"
1212 ("TAB" . outline-toggle-children)
1213 ("a" . outline-hide-body)
1214 ("H" . outline-hide-body)
1215 ("S" . outline-show-all)
1216 ("h" . outline-hide-subtree)
1217 ("s" . outline-show-subtree)))
1218#+end_src
1219
180cab37
AB
1220* Borg's =layer/essentials=
1221
1222TODO: break this giant source block down into individual org sections.
1223
1224#+begin_src emacs-lisp
1225(use-package dash
1226 :config (dash-enable-font-lock))
1227
1228(use-package diff-hl
1229 :config
1230 (setq diff-hl-draw-borders nil)
1231 (global-diff-hl-mode)
1232 (add-hook 'magit-post-refresh-hook 'diff-hl-magit-post-refresh t))
1233
1234(use-package dired
1235 :defer t
1236 :config (setq dired-listing-switches "-alh"))
1237
1238(use-package eldoc
1239 :when (version< "25" emacs-version)
1240 :config (global-eldoc-mode))
1241
1242(use-package help
1243 :defer t
3e03ee84
AB
1244 :config
1245 (temp-buffer-resize-mode)
1246 (setq help-window-select t))
180cab37
AB
1247
1248(progn ; `isearch'
1249 (setq isearch-allow-scroll t))
1250
1251(use-package lisp-mode
1252 :config
1253 (add-hook 'emacs-lisp-mode-hook 'outline-minor-mode)
1254 (add-hook 'emacs-lisp-mode-hook 'reveal-mode)
1255 (defun indent-spaces-mode ()
1256 (setq indent-tabs-mode nil))
1257 (add-hook 'lisp-interaction-mode-hook #'indent-spaces-mode))
1258
1259(use-package man
1260 :defer t
1261 :config (setq Man-width 80))
1262
1263(use-package paren
1264 :config (show-paren-mode))
1265
1266(use-package prog-mode
1267 :config (global-prettify-symbols-mode)
1268 (defun indicate-buffer-boundaries-left ()
1269 (setq indicate-buffer-boundaries 'left))
1270 (add-hook 'prog-mode-hook #'indicate-buffer-boundaries-left))
1271
1272(use-package recentf
ce842fdf 1273 :defer 0.5
633de78a
AB
1274 :config
1275 (add-to-list 'recentf-exclude "^/\\(?:ssh\\|su\\|sudo\\)?:")
1276 (setq recentf-max-saved-items 40))
180cab37
AB
1277
1278(use-package savehist
1279 :config (savehist-mode))
1280
1281(use-package saveplace
1282 :when (version< "25" emacs-version)
1283 :config (save-place-mode))
1284
1285(use-package simple
1286 :config (column-number-mode))
1287
1288(progn ; `text-mode'
4b7207e1
AB
1289 (add-hook 'text-mode-hook #'indicate-buffer-boundaries-left)
1290 (add-hook 'text-mode-hook #'abbrev-mode))
180cab37
AB
1291
1292(use-package tramp
1293 :defer t
1294 :config
1295 (add-to-list 'tramp-default-proxies-alist '(nil "\\`root\\'" "/ssh:%h:"))
1296 (add-to-list 'tramp-default-proxies-alist '("localhost" nil nil))
1297 (add-to-list 'tramp-default-proxies-alist
1298 (list (regexp-quote (system-name)) nil nil)))
1299
1300(use-package undo-tree
1301 :config
12a0f8f0
AB
1302 (global-undo-tree-mode -1))
1303 ;; :bind (("C-?" . undo-tree-undo)
1304 ;; ("M-_" . undo-tree-redo))
1305 ;; :config
1306 ;; (global-undo-tree-mode)
1307 ;; (setq undo-tree-mode-lighter ""
1308 ;; undo-tree-auto-save-history t))
180cab37
AB
1309#+end_src
1310
54512e45
AB
1311* Editing
1312
1313** Company
1314
1315#+begin_src emacs-lisp
1316(use-package company
b2d378eb 1317 :defer 1
54512e45
AB
1318 :bind
1319 (:map company-active-map
42da5dd2
AB
1320 ([tab] . company-complete-common-or-cycle)
1321 ([escape] . company-abort))
54512e45 1322 :custom
54512e45
AB
1323 (company-minimum-prefix-length 1)
1324 (company-selection-wrap-around t)
1325 (company-dabbrev-char-regexp "\\sw\\|\\s_\\|[-_]")
94a3349d
AB
1326 (company-dabbrev-downcase nil)
1327 (company-dabbrev-ignore-case nil)
54512e45
AB
1328 :config
1329 (global-company-mode t))
1330#+end_src
1331
284bbe78
AB
1332* Syntax and spell checking
1333#+begin_src emacs-lisp
1334(use-package flycheck
ce842fdf 1335 :defer 3
284bbe78 1336 :hook (prog-mode . flycheck-mode)
3ffa4732
AB
1337 :bind
1338 (:map flycheck-mode-map
1339 ("M-P" . flycheck-previous-error)
1340 ("M-N" . flycheck-next-error))
284bbe78
AB
1341 :config
1342 ;; Use the load-path from running Emacs when checking elisp files
1343 (setq flycheck-emacs-lisp-load-path 'inherit)
1344
1345 ;; Only flycheck when I actually save the buffer
1346 (setq flycheck-check-syntax-automatically '(mode-enabled save)))
46467dc3
AB
1347
1348;; http://endlessparentheses.com/ispell-and-apostrophes.html
1349(use-package ispell
ce842fdf 1350 :defer 3
46467dc3
AB
1351 :config
1352 ;; ’ can be part of a word
1353 (setq ispell-local-dictionary-alist
1354 `((nil "[[:alpha:]]" "[^[:alpha:]]"
1355 "['\x2019]" nil ("-B") nil utf-8)))
1356 ;; don't send ’ to the subprocess
1357 (defun endless/replace-apostrophe (args)
1358 (cons (replace-regexp-in-string
1359 "’" "'" (car args))
1360 (cdr args)))
1361 (advice-add #'ispell-send-string :filter-args
1362 #'endless/replace-apostrophe)
1363
1364 ;; convert ' back to ’ from the subprocess
1365 (defun endless/replace-quote (args)
1366 (if (not (derived-mode-p 'org-mode))
1367 args
1368 (cons (replace-regexp-in-string
1369 "'" "’" (car args))
1370 (cdr args))))
1371 (advice-add #'ispell-parse-output :filter-args
1372 #'endless/replace-quote))
284bbe78 1373#+end_src
3f0f8d01
AB
1374* Programming modes
1375
d43a8eda 1376** [[http://alloytools.org][Alloy]] (with [[https://github.com/dwwmmn/alloy-mode][alloy-mode]])
221cdaa3
AB
1377
1378#+begin_src emacs-lisp
fad62af5 1379(use-package alloy-mode
ce842fdf 1380 :defer t
fad62af5 1381 :config (setq alloy-basic-offset 2))
221cdaa3
AB
1382#+end_src
1383
d43a8eda 1384** [[https://coq.inria.fr][Coq]] (with [[https://github.com/ProofGeneral/PG][Proof General]])
695170a4
AB
1385
1386#+begin_src emacs-lisp
1387(use-package proof-site ; Proof General
ce842fdf 1388 :defer t
695170a4
AB
1389 :load-path "lib/proof-site/generic/")
1390#+end_src
1391
d43a8eda 1392** [[https://leanprover.github.io][Lean]] (with [[https://github.com/leanprover/lean-mode][lean-mode]])
3f0f8d01
AB
1393
1394#+begin_src emacs-lisp
56fd2611 1395(eval-when-compile (defvar lean-mode-map))
e9bcfa30 1396(use-package lean-mode
f97a01bd 1397 :defer 1
e9bcfa30 1398 :bind (:map lean-mode-map
2e7aa30f
AB
1399 ("S-SPC" . company-complete))
1400 :config
1401 (require 'lean-input)
e44b9b7e
AB
1402 (setq default-input-method "Lean"
1403 lean-input-tweak-all '(lean-input-compose
1404 (lean-input-prepend "/")
1405 (lean-input-nonempty))
1406 lean-input-user-translations '(("/" "/")))
1407 (lean-input-setup))
2e7aa30f 1408 #+end_src
3f0f8d01 1409
36fca309
AB
1410** Haskell
1411
1412*** [[https://github.com/haskell/haskell-mode][haskell-mode]]
a81db923
AB
1413
1414#+begin_src emacs-lisp
1415(use-package haskell-mode
ce842fdf 1416 :defer t
a81db923
AB
1417 :config
1418 (setq haskell-indentation-layout-offset 4
1419 haskell-indentation-left-offset 4
eb186a5a
AB
1420 flycheck-checker 'haskell-hlint
1421 flycheck-disabled-checkers '(haskell-stack-ghc haskell-ghc)))
a81db923 1422#+end_src
36fca309 1423
eba52b9c
AB
1424*** [[https://github.com/jyp/dante][dante]]
1425
1426#+begin_src emacs-lisp
1427(use-package dante
1428 :after haskell-mode
1429 :commands dante-mode
1430 :hook (haskell-mode . dante-mode))
1431#+end_src
1432
36fca309
AB
1433*** [[https://github.com/mpickering/hlint-refactor-mode][hlint-refactor]]
1434
1435Emacs bindings for [[https://github.com/ndmitchell/hlint][hlint]]'s refactor option. This requires the refact
1436executable from [[https://github.com/mpickering/apply-refact][apply-refact]].
1437
1438#+begin_src emacs-lisp
1439(use-package hlint-refactor
ce842fdf 1440 :after haskell-mode
36fca309 1441 :bind (:map hlint-refactor-mode-map
eb186a5a
AB
1442 ("C-c l b" . hlint-refactor-refactor-buffer)
1443 ("C-c l r" . hlint-refactor-refactor-at-point))
36fca309
AB
1444 :hook (haskell-mode . hlint-refactor-mode))
1445#+end_src
1446
f76bdaa8
AB
1447*** [[https://github.com/flycheck/flycheck-haskell][flycheck-haskell]]
1448
1449#+begin_src emacs-lisp
ce842fdf
AB
1450(use-package flycheck-haskell
1451 :after haskell-mode)
f76bdaa8
AB
1452#+end_src
1453
1454*** [[https://github.com/ndmitchell/hlint/blob/20e116a043f2073c57b17b24ae6364b5e433ba7e/data/hs-lint.el][hs-lint.el]]
1455:PROPERTIES:
1456:header-args+: :tangle lisp/hs-lint.el :mkdirp yes
1457:END:
1458
1459Currently using =flycheck-haskell= with the =haskell-hlint= checker
1460instead.
1461
1462#+begin_src emacs-lisp :tangle no
1463;;; hs-lint.el --- minor mode for HLint code checking
1464
1465;; Copyright 2009 (C) Alex Ott
1466;;
1467;; Author: Alex Ott <alexott@gmail.com>
1468;; Keywords: haskell, lint, HLint
1469;; Requirements:
1470;; Status: distributed under terms of GPL2 or above
1471
1472;; Typical message from HLint looks like:
1473;;
1474;; /Users/ott/projects/lang-exp/haskell/test.hs:52:1: Eta reduce
1475;; Found:
1476;; count1 p l = length (filter p l)
1477;; Why not:
1478;; count1 p = length . filter p
1479
1480
1481(require 'compile)
1482
1483(defgroup hs-lint nil
1484 "Run HLint as inferior of Emacs, parse error messages."
1485 :group 'tools
1486 :group 'haskell)
1487
1488(defcustom hs-lint-command "hlint"
1489 "The default hs-lint command for \\[hlint]."
1490 :type 'string
1491 :group 'hs-lint)
1492
1493(defcustom hs-lint-save-files t
1494 "Save modified files when run HLint or no (ask user)"
1495 :type 'boolean
1496 :group 'hs-lint)
1497
1498(defcustom hs-lint-replace-with-suggestions nil
1499 "Replace user's code with suggested replacements"
1500 :type 'boolean
1501 :group 'hs-lint)
1502
1503(defcustom hs-lint-replace-without-ask nil
1504 "Replace user's code with suggested replacements automatically"
1505 :type 'boolean
1506 :group 'hs-lint)
1507
1508(defun hs-lint-process-setup ()
1509 "Setup compilation variables and buffer for `hlint'."
1510 (run-hooks 'hs-lint-setup-hook))
1511
1512;; regex for replace suggestions
1513;;
1514;; ^\(.*?\):\([0-9]+\):\([0-9]+\): .*
1515;; Found:
1516;; \s +\(.*\)
1517;; Why not:
1518;; \s +\(.*\)
1519
1520(defvar hs-lint-regex
1521 "^\\(.*?\\):\\([0-9]+\\):\\([0-9]+\\): .*[\n\C-m]Found:[\n\C-m]\\s +\\(.*\\)[\n\C-m]Why not:[\n\C-m]\\s +\\(.*\\)[\n\C-m]"
1522 "Regex for HLint messages")
1523
1524(defun make-short-string (str maxlen)
1525 (if (< (length str) maxlen)
1526 str
1527 (concat (substring str 0 (- maxlen 3)) "...")))
1528
1529(defun hs-lint-replace-suggestions ()
1530 "Perform actual replacement of suggestions"
1531 (goto-char (point-min))
1532 (while (re-search-forward hs-lint-regex nil t)
1533 (let* ((fname (match-string 1))
1534 (fline (string-to-number (match-string 2)))
1535 (old-code (match-string 4))
1536 (new-code (match-string 5))
1537 (msg (concat "Replace '" (make-short-string old-code 30)
1538 "' with '" (make-short-string new-code 30) "'"))
1539 (bline 0)
1540 (eline 0)
1541 (spos 0)
1542 (new-old-code ""))
1543 (save-excursion
1544 (switch-to-buffer (get-file-buffer fname))
eb186a5a
AB
1545 (goto-char (point-min))
1546 (forward-line (1- fline))
f76bdaa8
AB
1547 (beginning-of-line)
1548 (setf bline (point))
1549 (when (or hs-lint-replace-without-ask
1550 (yes-or-no-p msg))
1551 (end-of-line)
1552 (setf eline (point))
1553 (beginning-of-line)
1554 (setf old-code (regexp-quote old-code))
1555 (while (string-match "\\\\ " old-code spos)
1556 (setf new-old-code (concat new-old-code
1557 (substring old-code spos (match-beginning 0))
1558 "\\ *"))
1559 (setf spos (match-end 0)))
1560 (setf new-old-code (concat new-old-code (substring old-code spos)))
1561 (remove-text-properties bline eline '(composition nil))
1562 (when (re-search-forward new-old-code eline t)
1563 (replace-match new-code nil t)))))))
1564
1565(defun hs-lint-finish-hook (buf msg)
1566 "Function, that is executed at the end of HLint execution"
1567 (if hs-lint-replace-with-suggestions
1568 (hs-lint-replace-suggestions)
1569 (next-error 1 t)))
1570
1571(define-compilation-mode hs-lint-mode "HLint"
1572 "Mode for check Haskell source code."
1573 (set (make-local-variable 'compilation-process-setup-function)
1574 'hs-lint-process-setup)
1575 (set (make-local-variable 'compilation-disable-input) t)
1576 (set (make-local-variable 'compilation-scroll-output) nil)
1577 (set (make-local-variable 'compilation-finish-functions)
1578 (list 'hs-lint-finish-hook))
1579 )
1580
1581(defun hs-lint ()
1582 "Run HLint for current buffer with haskell source"
1583 (interactive)
1584 (save-some-buffers hs-lint-save-files)
1585 (compilation-start (concat hs-lint-command " \"" buffer-file-name "\"")
1586 'hs-lint-mode))
1587
1588(provide 'hs-lint)
1589;;; hs-lint.el ends here
1590#+end_src
1591
1592#+begin_src emacs-lisp :tangle no
1593(use-package hs-lint
1594 :load-path "lisp/"
1595 :bind (:map haskell-mode-map
1596 ("C-c l l" . hs-lint)))
1597#+end_src
d98421d5 1598
2090f409
AB
1599** Web dev
1600
1601*** SGML and HTML
d98421d5
AB
1602
1603#+begin_src emacs-lisp
1604(use-package sgml-mode
ce842fdf 1605 :defer t
d98421d5 1606 :config
2090f409 1607 (setq sgml-basic-offset 2))
d98421d5
AB
1608#+end_src
1609
2090f409
AB
1610*** CSS and SCSS
1611
1612#+begin_src emacs-lisp
1613(use-package css-mode
ce842fdf 1614 :defer t
2090f409
AB
1615 :config
1616 (setq css-indent-offset 2))
1617#+end_src
1618
1619*** Web mode
d98421d5
AB
1620
1621#+begin_src emacs-lisp
1622(use-package web-mode
ce842fdf 1623 :defer t
2090f409
AB
1624 :mode "\\.html\\'"
1625 :config
1626 (setq-every! 2
1627 web-mode-code-indent-offset
1628 web-mode-css-indent-offset
1629 web-mode-markup-indent-offset))
d98421d5
AB
1630#+end_src
1631
2090f409 1632*** Emmet mode
d98421d5
AB
1633
1634#+begin_src emacs-lisp
1635(use-package emmet-mode
ce842fdf 1636 :after (:any web-mode css-mode sgml-mode)
d98421d5
AB
1637 :bind* (("C-)" . emmet-next-edit-point)
1638 ("C-(" . emmet-prev-edit-point))
9be4b796
AB
1639 :config
1640 (unbind-key "C-j" emmet-mode-keymap)
d98421d5
AB
1641 (setq emmet-move-cursor-between-quotes t)
1642 :hook (web-mode css-mode html-mode sgml-mode))
1643#+end_src
1644
1c3eaf15
AB
1645** Nix
1646
1647#+begin_src emacs-lisp
1648(use-package nix-mode
ce842fdf 1649 :defer t
1c3eaf15
AB
1650 :mode "\\.nix\\'")
1651#+end_src
1652
d3ce3580
AB
1653** Java
1654
1655*** meghanada
1656
a9674790 1657#+begin_src emacs-lisp :tangle no
d3ce3580
AB
1658(use-package meghanada
1659 :bind
1660 (:map meghanada-mode-map
1661 (("C-M-o" . meghanada-optimize-import)
1662 ("C-M-t" . meghanada-import-all)))
1663 :hook (java-mode . meghanada-mode))
1664#+end_src
1665
1666*** lsp-java
1667
a9674790
AB
1668#+begin_comment
1669dependencies:
1670
1671ace-window
1672avy
1673bui
1674company-lsp
1675dap-mode
1676lsp-java
1677lsp-mode
1678lsp-ui
1679pfuture
1680tree-mode
1681treemacs
1682#+end_comment
1683
d3ce3580 1684#+begin_src emacs-lisp :tangle no
a9674790
AB
1685(use-package treemacs
1686 :config (setq treemacs-never-persist t))
d3ce3580
AB
1687
1688(use-package yasnippet
1689 :config
1690 ;; (yas-global-mode)
1691 )
1692
1693(use-package lsp-mode
1694 :init (setq lsp-eldoc-render-all nil
1695 lsp-highlight-symbol-at-point nil)
1696 )
1697
1698(use-package hydra)
1699
1700(use-package company-lsp
1701 :after company
1702 :config
1703 (setq company-lsp-cache-candidates t
1704 company-lsp-async t))
1705
1706(use-package lsp-ui
1707 :config
1708 (setq lsp-ui-sideline-update-mode 'point))
1709
1710(use-package lsp-java
1711 :config
1712 (add-hook 'java-mode-hook
1713 (lambda ()
1714 (setq-local company-backends (list 'company-lsp))))
1715
1716 (add-hook 'java-mode-hook 'lsp-java-enable)
1717 (add-hook 'java-mode-hook 'flycheck-mode)
1718 (add-hook 'java-mode-hook 'company-mode)
1719 (add-hook 'java-mode-hook 'lsp-ui-mode))
1720
1721(use-package dap-mode
1722 :after lsp-mode
1723 :config
1724 (dap-mode t)
1725 (dap-ui-mode t))
1726
1727(use-package dap-java
1728 :after (lsp-java))
1729
1730(use-package lsp-java-treemacs
1731 :after (treemacs))
1732#+end_src
1733
0deee788
AB
1734* Emacs Enhancements
1735
1736** [[https://github.com/justbur/emacs-which-key][which-key]]
1737
1738#+begin_quote
1739Emacs package that displays available keybindings in popup
1740#+end_quote
1741
1742#+begin_src emacs-lisp
1743(use-package which-key
1744 :defer 1
1745 :config (which-key-mode))
1746#+end_src
75095920 1747
1f56a9b9
AB
1748** theme
1749
1750#+begin_src emacs-lisp
1751(add-to-list 'custom-theme-load-path "~/.emacs.d/lisp")
1752(load-theme 'tangomod t)
1753#+end_src
1754
4b4c2c1d
AB
1755** doom-modeline
1756
1757#+begin_src emacs-lisp
1758(use-package doom-modeline
1759 :demand t
1760 :config (setq doom-modeline-height 32)
1761 :hook (after-init . doom-modeline-init))
1762#+end_src
1763
1764** doom-themes
1765
1766#+begin_src emacs-lisp
1767(use-package doom-themes)
1768#+end_src
1769
1f56a9b9
AB
1770** theme helper functions
1771
1772#+begin_src emacs-lisp
4b4c2c1d
AB
1773(defun amin/lights-on ()
1774 "Enable my favourite light theme."
1f56a9b9
AB
1775 (interactive)
1776 (progn
1777 (mapc #'disable-theme custom-enabled-themes)
4b4c2c1d 1778 (load-theme 'tangomod t)))
1f56a9b9 1779
4b4c2c1d
AB
1780(defun amin/lights-off ()
1781 "Go dark."
1f56a9b9
AB
1782 (interactive)
1783 (progn
1784 (mapc #'disable-theme custom-enabled-themes)
4b4c2c1d 1785 (load-theme 'doom-tomorrow-night t)))
1f56a9b9
AB
1786
1787(amin--leader-keys
1788 "t" '(:ignore t :wk "theme")
4b4c2c1d
AB
1789 "t d" 'amin/lights-off
1790 "t l" 'amin/lights-on)
1f56a9b9
AB
1791#+end_src
1792
bb93c9e1
AB
1793** [[https://github.com/bbatsov/crux][crux]]
1794
1795#+begin_src emacs-lisp
1796(use-package crux
ce842fdf 1797 :defer 1
3e03ee84
AB
1798 :general
1799 (amin--leader-keys
1800 "b K" 'crux-kill-other-buffers
1801 "c d" 'crux-duplicate-current-line-or-region
1802 "c D" 'crux-duplicate-and-comment-current-line-or-region
1803 "f c" 'crux-copy-file-preserve-attributes
1804 "f d" 'crux-delete-file-and-buffer
1805 "f r" 'crux-rename-file-and-buffer)
05f602d9
AB
1806 :bind (("C-c d" . crux-duplicate-current-line-or-region)
1807 ("C-c D" . crux-duplicate-and-comment-current-line-or-region)
1808 ("C-S-j" . crux-top-join-line)
1809 ("C-c j" . crux-top-join-line)))
bb93c9e1
AB
1810#+end_src
1811
1812** [[https://github.com/alezost/mwim.el][mwim]]
1813
1814#+begin_src emacs-lisp
1815(use-package mwim
3e03ee84
AB
1816 :general
1817 (:states '(normal visual)
1818 "0" 'mwim-beginning-of-code-or-line
1819 "$" 'mwim-end-of-code-or-line)
bb93c9e1
AB
1820 :bind (("C-a" . mwim-beginning-of-code-or-line)
1821 ("C-e" . mwim-end-of-code-or-line)
1822 ("<home>" . mwim-beginning-of-line-or-code)
d14698a3 1823 ("<end>" . mwim-end-of-line-or-code)))
f8869b0b
AB
1824#+end_src
1825
9b646b53
AB
1826** projectile
1827
1828#+begin_src emacs-lisp
1829(use-package projectile
b2d378eb 1830 :defer t
9b646b53
AB
1831 :bind-keymap ("C-c p" . projectile-command-map)
1832 :config
47112ed3 1833 (projectile-mode)
9b646b53
AB
1834
1835 (defun my-projectile-invalidate-cache (&rest _args)
1836 ;; ignore the args to `magit-checkout'
1837 (projectile-invalidate-cache nil))
1838
1839 (eval-after-load 'magit-branch
1840 '(progn
1841 (advice-add 'magit-checkout
1842 :after #'my-projectile-invalidate-cache)
1843 (advice-add 'magit-branch-and-checkout
1844 :after #'my-projectile-invalidate-cache))))
1845#+end_src
1846
b36bd0dd
AB
1847** [[https://github.com/Wilfred/helpful][helpful]]
1848
1849#+begin_src emacs-lisp
1850(use-package helpful
ce842fdf 1851 :defer 1
3e03ee84
AB
1852 :general
1853 (amin--leader-keys
1854 "h h" '(:ignore t :wk "helpful")
1855 "h h c" 'helpful-command
1856 "h h f" 'helpful-callable ; helpful-function
1857 "h h v" 'helpful-variable
1858 "h h k" 'helpful-key
1859 "h h p" 'helpful-at-point))
b36bd0dd
AB
1860#+end_src
1861
1b93c5be 1862** [[https://github.com/knu/shell-toggle.el][shell-toggle]]
6ef44cb7
AB
1863
1864#+begin_src emacs-lisp
1b93c5be
AB
1865(use-package shell-toggle
1866 :after eshell
12f3e4b8 1867 :general (amin--leader-keys "a s e" 'amin/shell-toggle)
1b93c5be
AB
1868 :bind ("C-c e" . amin/shell-toggle)
1869 :config
1870 (defun amin/shell-toggle (make-cd)
1871 "Toggle between the shell buffer and whatever buffer you are editing.
1872With a prefix argument MAKE-CD also insert a \"cd DIR\" command
1873into the shell, where DIR is the directory of the current buffer.
1874
1875When called in the shell buffer returns you to the buffer you were editing
1876before calling this the first time.
1877
1878Options: `shell-toggle-goto-eob'"
1879 (interactive "P")
1880 ;; Try to decide on one of three possibilities:
1881 ;; If not in shell-buffer, switch to it.
1882 ;; If in shell-buffer, return to state before going to the shell-buffer
1883 (if (eq (current-buffer) shell-toggle-shell-buffer)
1884 (shell-toggle-buffer-return-from-shell)
1885 (progn
1886 (shell-toggle-buffer-goto-shell make-cd)
1887 (if shell-toggle-full-screen-window-only (delete-other-windows)))))
1888
1889 ;; override to split horizontally instead
1890 (defun shell-toggle-buffer-switch-to-other-window ()
1891 "Switch to other window.
1892If the current window is the only window in the current frame,
1893create a new window and switch to it.
1894
1895\(This is less intrusive to the current window configuration than
1896`switch-buffer-other-window')"
1897 (let ((this-window (selected-window)))
1898 (other-window 1)
1899 ;; If we did not switch window then we only have one window and need to
1900 ;; create a new one.
1901 (if (eq this-window (selected-window))
1902 (progn
1903 (split-window-horizontally)
1904 (other-window 1)))))
1905
1906 :custom
1907 (shell-toggle-launch-shell 'shell-toggle-eshell))
6ef44cb7
AB
1908#+end_src
1909
8bc647a7
AB
1910** [[https://github.com/EricCrosson/unkillable-scratch][unkillable-scratch]]
1911
1912Make =*scratch*= and =*Messages*= unkillable.
1913
1914#+begin_src emacs-lisp
1915(use-package unkillable-scratch
ce842fdf 1916 :defer 3
8bc647a7
AB
1917 :config
1918 (unkillable-scratch 1)
1919 :custom
15551c07 1920 (unkillable-scratch-behavior 'do-nothing)
8bc647a7
AB
1921 (unkillable-buffers '("^\\*scratch\\*$" "^\\*Messages\\*$")))
1922#+end_src
1923
f20d6a60
AB
1924** [[https://github.com/davep/boxquote.el][boxquote.el]]
1925
1926#+begin_example
1927,----
1928| make pretty boxed quotes like this
1929`----
1930#+end_example
1931
1932#+begin_src emacs-lisp
1933(use-package boxquote
ce842fdf 1934 :defer 3
f20d6a60
AB
1935 :bind
1936 (:prefix-map amin--boxquote-prefix-map
1937 :prefix "C-c q"
1938 ("b" . boxquote-buffer)
1939 ("B" . boxquote-insert-buffer)
1940 ("d" . boxquote-defun)
1941 ("F" . boxquote-insert-file)
1942 ("hf" . boxquote-describe-function)
1943 ("hk" . boxquote-describe-key)
1944 ("hv" . boxquote-describe-variable)
1945 ("hw" . boxquote-where-is)
1946 ("k" . boxquote-kill)
1947 ("p" . boxquote-paragraph)
1948 ("q" . boxquote-boxquote)
1949 ("r" . boxquote-region)
1950 ("s" . boxquote-shell-command)
1951 ("t" . boxquote-text)
1952 ("T" . boxquote-title)
1953 ("u" . boxquote-unbox)
1954 ("U" . boxquote-unbox-region)
1955 ("y" . boxquote-yank)
1956 ("M-q" . boxquote-fill-paragraph)
1957 ("M-w" . boxquote-kill-ring-save)))
1958#+end_src
1959
1960Also see [[https://www.emacswiki.org/emacs/rebox2][rebox2]].
1961
6e9d8a2b 1962** COMMENT [[https://github.com/DarthFennec/highlight-indent-guides][highlight-indent-guides]] :ARCHIVE:
0fbb9f4e
AB
1963
1964#+begin_src emacs-lisp
1965(use-package highlight-indent-guides
ce842fdf 1966 :defer 3
0fbb9f4e 1967 :hook ((prog-mode . highlight-indent-guides-mode)
97cf0fc4
AB
1968 ;; (org-mode . highlight-indent-guides-mode)
1969 )
0fbb9f4e
AB
1970 :config
1971 (setq highlight-indent-guides-character ?\|)
1972 (setq highlight-indent-guides-auto-enabled nil)
1973 (setq highlight-indent-guides-method 'character)
1974 (setq highlight-indent-guides-responsive 'top)
1975 (set-face-foreground 'highlight-indent-guides-character-face "gainsboro")
1976 (set-face-foreground 'highlight-indent-guides-top-character-face "grey40")) ; grey13 is nice too
1977#+end_src
1978
f811cdad
AB
1979** pdf-tools
1980
1981#+begin_src emacs-lisp
1982(use-package pdf-tools
ce842fdf 1983 :defer t
f811cdad 1984 :magic ("%PDF" . pdf-view-mode)
a25e5659
AB
1985 :config
1986 (setq pdf-view-resize-factor 1.05)
1987 (pdf-tools-install)
f811cdad
AB
1988 :bind
1989 (:map pdf-view-mode-map
1990 ("C-s" . isearch-forward)
1991 ("C-r" . isearch-backward)
1992 ("j" . pdf-view-next-line-or-next-page)
a25e5659
AB
1993 ("k" . pdf-view-previous-line-or-previous-page)
1994 ("h" . image-backward-hscroll)
1995 ("l" . image-forward-hscroll)))
f811cdad
AB
1996#+end_src
1997
1998** anzu
1999
2000#+begin_src emacs-lisp
2001(use-package anzu)
2002#+end_src
2003
46467dc3
AB
2004** typo.el
2005
2006#+begin_src emacs-lisp
2007(use-package typo
ce842fdf 2008 :defer 2
46467dc3
AB
2009 :config
2010 (typo-global-mode 1)
2011 :hook (text-mode . typo-mode))
2012#+end_src
2013
5a96c388
AB
2014** hl-todo
2015
2016#+begin_src emacs-lisp
2017(use-package hl-todo
2018 :defer 4
2019 :config
2020 (global-hl-todo-mode))
2021#+end_src
2022
2023** shrink-path
2024
2025#+begin_src emacs-lisp
2026(use-package shrink-path
2027 :after eshell
2028 :config
2029 (setq eshell-prompt-regexp "\\(.*\n\\)*λ "
2030 eshell-prompt-function #'+eshell/prompt)
2031
2032 (defun +eshell/prompt ()
2033 (let ((base/dir (shrink-path-prompt default-directory)))
2034 (concat (propertize (car base/dir)
2035 'face 'font-lock-comment-face)
2036 (propertize (cdr base/dir)
2037 'face 'font-lock-constant-face)
2038 (propertize (+eshell--current-git-branch)
2039 'face 'font-lock-function-name-face)
2040 "\n"
2041 (propertize "λ" 'face 'eshell-prompt-face)
2042 ;; needed for the input text to not have prompt face
2043 (propertize " " 'face 'default))))
2044
2045 (defun +eshell--current-git-branch ()
2046 (let ((branch (car (loop for match in (split-string (shell-command-to-string "git branch") "\n")
2047 when (string-match "^\*" match)
2048 collect match))))
2049 (if (not (eq branch nil))
2050 (concat " " (substring branch 2))
2051 ""))))
2052#+end_src
2053
2054** COMMENT slack :ARCHIVE:
313f5877
AB
2055
2056Hopefully temporary.
2057
2058#+begin_src emacs-lisp
2059(use-package slack
2060 :commands (slack-start)
2061 :init
2062 (eval-when-compile ; silence the byte-compiler
2063 (defvar url-http-data nil)
2064 (defvar url-http-extra-headers nil)
2065 (defvar url-http-method nil)
2066 (defvar url-callback-function nil)
2067 (defvar url-callback-arguments nil)
2068 (defvar oauth--token-data nil))
2069 (setq slack-buffer-emojify t
2070 slack-prefer-current-team t)
2071 :config
2072 (slack-register-team
2073 :name "uw-apv"
2074 :default t
2075 :client-id uw-apv-client-id
2076 :client-secret uw-apv-client-secret
2077 :token uw-apv-token
2078 :subscribed-channels '(general)
2079 :full-and-display-names t)
2080 (slack-register-team
2081 :name "watform"
2082 :default nil
2083 :client-id watform-client-id
2084 :client-secret watform-client-secret
2085 :token watform-token
2086 :subscribed-channels '(general)
d851faed
AB
2087 :full-and-display-names t)
2088 (add-to-list 'swiper-font-lock-exclude 'slack-message-buffer-mode t)
ace71572
AB
2089 (setq lui-time-stamp-format "[%Y-%m-%d %H:%M:%S]"
2090 lui-time-stamp-only-when-changed-p t
2091 lui-time-stamp-position 'right)
313f5877
AB
2092 :bind
2093 (("C-c s s" . slack-start)
2094 ("C-c s u" . slack-select-unread-rooms)
2095 ("C-c s b" . slack-select-rooms)
2096 ("C-c s t" . slack-change-current-team)
2097 ("C-c s c" . slack-ws-close)
2098 :map slack-mode-map
3bb16326
AB
2099 ("M-p" . slack-buffer-goto-prev-message)
2100 ("M-n" . slack-buffer-goto-next-message)
313f5877
AB
2101 ("C-c e" . slack-message-edit)
2102 ("C-c k" . slack-message-delete)
2103 ("C-c C-k" . slack-channel-leave)
3bb16326
AB
2104 ("C-c r a" . slack-message-add-reaction)
2105 ("C-c r r" . slack-message-remove-reaction)
2106 ("C-c r s" . slack-message-show-reaction-users)
2107 ("C-c p l" . slack-room-pins-list)
2108 ("C-c p a" . slack-message-pins-add)
2109 ("C-c p r" . slack-message-pins-remove)
313f5877 2110 ("@" . slack-message-embed-mention)
d851faed 2111 ("#" . slack-message-embed-channel)))
313f5877
AB
2112
2113(use-package alert
2114 :commands (alert)
2115 :init
2116 (setq alert-default-style 'notifier))
2117#+end_src
2118
5a96c388 2119** COMMENT magithub :ARCHIVE:
620ed689
AB
2120
2121For when I /have to/ use GH.
2122
2123#+begin_src emacs-lisp
2124(use-package magithub
2125 :after magit
2126 :config
2127 (magithub-feature-autoinject t)
2128 (setq magithub-clone-default-directory "~/src/git"))
2129#+end_src
2130
73a77e5b
AB
2131** [[https://github.com/peterwvj/eshell-up][eshell-up]]
2132
2133#+begin_src emacs-lisp
2134(use-package eshell-up
2135 :after eshell)
2136#+end_src
2137
12f3e4b8
AB
2138** multi-term
2139
2140#+begin_src emacs-lisp
2141(use-package multi-term
2142 :defer 1
2143 :general (amin--leader-keys
2144 "a s m" 'multi-term
2145 "a s p" 'multi-term-dedicated-toggle)
2146 :bind ("C-c C-j" . term-line-mode)
2147 :config
2148 (setq multi-term-program "/bin/screen"
2149 ;; TODO: add separate bindings for connecting to existing
2150 ;; session vs. always creating a new one
2151 multi-term-dedicated-select-after-open-p t
2152 multi-term-dedicated-window-height 20
2153 multi-term-dedicated-max-window-height 30
2154 term-bind-key-alist
2155 '(("C-c C-c" . term-interrupt-subjob)
2156 ("C-c C-e" . term-send-esc)
2157 ("C-k" . kill-line)
2158 ("C-y" . term-paste)
2159 ("M-f" . term-send-forward-word)
2160 ("M-b" . term-send-backward-word)
2161 ("M-p" . term-send-up)
2162 ("M-n" . term-send-down)
2163 ("<C-backspace>" . term-send-backward-kill-word)
2164 ("<M-DEL>" . term-send-backward-kill-word)
2165 ("M-d" . term-send-delete-word)
2166 ("M-," . term-send-raw)
2167 ("M-." . comint-dynamic-complete))
2168 term-unbind-key-alist
2169 '("C-z" "C-x" "C-c" "C-h" "C-y" "<ESC>")))
2170#+end_src
2171
51db62d8 2172* Email
9d5d55c5 2173
51db62d8 2174#+begin_src emacs-lisp
6c5b745f
AB
2175(defvar amin-maildir (expand-file-name "~/mail/"))
2176(after! recentf
2177 (add-to-list 'recentf-exclude amin-maildir))
2178#+end_src
51db62d8 2179
ea40ba6c
AB
2180** Gnus
2181
bc39c780 2182#+begin_src emacs-lisp
9ae707cc
AB
2183(setq
2184 amin-gnus-init-file (no-littering-expand-etc-file-name "gnus")
2185 mail-user-agent 'gnus-user-agent
2186 read-mail-command 'gnus)
ea40ba6c
AB
2187
2188(use-package gnus
3e03ee84
AB
2189 :general
2190 (amin--leader-keys
2191 "m" 'gnus
2192 "M" 'gnus-unplugged)
9ae707cc
AB
2193 :bind (("s-m" . gnus)
2194 ("s-M" . gnus-unplugged))
ea40ba6c
AB
2195 :init
2196 (setq
9ae707cc
AB
2197 gnus-select-method '(nnnil "")
2198 gnus-secondary-select-methods
2199 '((nnimap "amin"
6b6a22a2
AB
2200 (nnimap-stream plain)
2201 (nnimap-address "127.0.0.1")
2202 (nnimap-server-port 143)
2203 (nnimap-authenticator plain)
2204 (nnimap-user "amin@aminb.org"))
9ae707cc 2205 (nnimap "uwaterloo"
6b6a22a2
AB
2206 (nnimap-stream plain)
2207 (nnimap-address "127.0.0.1")
2208 (nnimap-server-port 143)
2209 (nnimap-authenticator plain)
2210 (nnimap-user "abandali@uwaterloo.ca")))
051074d6 2211 gnus-message-archive-group "nnimap+amin:Sent"
6b6a22a2 2212 gnus-parameters
53b0be6b
AB
2213 '(("gnu.*"
2214 (gcc-self . t)))
2215 gnus-large-newsgroup 50
ea40ba6c 2216 gnus-home-directory (no-littering-expand-var-file-name "gnus/")
9ae707cc
AB
2217 gnus-directory (concat gnus-home-directory "news/")
2218 message-directory (concat gnus-home-directory "mail/")
2219 nndraft-directory (concat gnus-home-directory "drafts/")
ea40ba6c
AB
2220 gnus-save-newsrc-file nil
2221 gnus-read-newsrc-file nil
f7f392c7 2222 gnus-interactive-exit nil
ea40ba6c
AB
2223 gnus-gcc-mark-as-read t))
2224
f7f392c7
AB
2225(use-package gnus-art
2226 :config
2227 (setq
2228 gnus-visible-headers
5a343a21 2229 (concat gnus-visible-headers "\\|^List-Id:\\|^X-RT-Originator:\\|^User-Agent:")
f7f392c7
AB
2230 gnus-sorted-header-list
2231 '("^From:" "^Subject:" "^Summary:" "^Keywords:"
2232 "^Followup-To:" "^To:" "^Cc:" "X-RT-Originator"
2233 "^Newsgroups:" "List-Id:" "^Organization:"
5a343a21 2234 "^User-Agent:" "^Date:")
f7f392c7
AB
2235 ;; local-lapsed article dates
2236 ;; from https://www.emacswiki.org/emacs/GnusFormatting#toc11
2237 gnus-article-date-headers '(user-defined)
2238 gnus-article-time-format
2239 (lambda (time)
2240 (let* ((date (format-time-string "%a, %d %b %Y %T %z" time))
2241 (local (article-make-date-line date 'local))
2242 (combined-lapsed (article-make-date-line date
2243 'combined-lapsed))
2244 (lapsed (progn
2245 (string-match " (.+" combined-lapsed)
2246 (match-string 0 combined-lapsed))))
4cf3b363
AB
2247 (concat local lapsed))))
2248 (bind-keys
2249 :map gnus-article-mode-map
3e70dc4a
AB
2250 ("r" . gnus-article-reply-with-original)
2251 ("R" . gnus-article-wide-reply-with-original)
2252 ("M-L" . org-store-link)))
f7f392c7
AB
2253
2254(use-package gnus-sum
4cf3b363
AB
2255 :bind (:map gnus-summary-mode-map
2256 :prefix-map amin--gnus-summary-prefix-map
2257 :prefix "v"
2258 ("r" . gnus-summary-reply)
2259 ("w" . gnus-summary-wide-reply)
2260 ("v" . gnus-summary-show-raw-article))
f7f392c7 2261 :config
4cf3b363
AB
2262 (bind-keys
2263 :map gnus-summary-mode-map
3e70dc4a
AB
2264 ("r" . gnus-summary-reply-with-original)
2265 ("R" . gnus-summary-wide-reply-with-original)
b9d46ec7
AB
2266 ("M-L" . org-store-link))
2267 :hook (gnus-summary-mode . amin--no-mouse-autoselect-window))
f7f392c7 2268
ef8a092b
AB
2269(use-package gnus-msg
2270 :config
2271 (setq gnus-posting-styles
2272 '((".*"
2c0f7884 2273 (address "amin@aminb.org")
b3a673f8 2274 (body "\nBest,\namin\n")
b3a673f8 2275 (eval (setq amin--message-cite-say-hi t)))
ef8a092b 2276 ("gnu.*"
7d1b2f9a 2277 (address "bandali@gnu.org"))
ff95772c 2278 ((header "subject" "ThankCRM")
b3a673f8
AB
2279 (to "webmasters-comment@gnu.org")
2280 (body "\nAdded to 2018supporters.html.\n\nMoving to campaigns.\n\n-amin\n")
2281 (eval (setq amin--message-cite-say-hi nil)))
ef8a092b
AB
2282 ("nnimap\\+uwaterloo:.*"
2283 (address "abandali@uwaterloo.ca")
7d1b2f9a 2284 (gcc "\"nnimap+uwaterloo:Sent Items\"")))))
ef8a092b 2285
9ae707cc 2286(use-package gnus-topic
bc39c780 2287 :hook (gnus-group-mode . gnus-topic-mode))
4cf3b363 2288
9ae707cc
AB
2289(use-package gnus-agent
2290 :config
2291 (setq gnus-agent-synchronize-flags 'ask)
2292 :hook (gnus-group-mode . gnus-agent-mode))
2293
c2f9e851
AB
2294(use-package gnus-group
2295 :config
2296 (setq gnus-permanently-visible-groups "\\((INBOX\\|gnu$\\)"))
9ae707cc 2297
ea40ba6c
AB
2298(use-package mm-decode
2299 :config
2300 (setq mm-discouraged-alternatives '("text/html" "text/richtext")))
2301#+end_src
2302
6c5b745f
AB
2303** sendmail
2304
2305#+begin_src emacs-lisp
51db62d8 2306(use-package sendmail
51db62d8
AB
2307 :config
2308 (setq sendmail-program "/usr/bin/msmtp"
6c5b745f 2309 ;; message-sendmail-extra-arguments '("-v" "-d")
51db62d8
AB
2310 mail-specify-envelope-from t
2311 mail-envelope-from 'header))
6c5b745f
AB
2312#+end_src
2313
2314** message
51db62d8 2315
6c5b745f 2316#+begin_src emacs-lisp
51db62d8 2317(use-package message
51db62d8 2318 :config
b3a673f8 2319 (defconst amin--message-cite-style-format "On %Y-%m-%d %l:%M %p, %N wrote:")
c7edd059
AB
2320 (defconst message-cite-style-bandali
2321 '((message-cite-function 'message-cite-original)
2322 (message-citation-line-function 'message-insert-formatted-citation-line)
2323 (message-cite-reply-position 'traditional)
2324 (message-yank-prefix "> ")
2325 (message-yank-cited-prefix ">")
2326 (message-yank-empty-prefix ">")
b3a673f8
AB
2327 (message-citation-line-format
2328 (if amin--message-cite-say-hi
2329 (concat "Hi %F,\n\n" amin--message-cite-style-format)
2330 amin--message-cite-style-format)))
c7edd059
AB
2331 "Citation style based on Mozilla Thunderbird's. Use with message-cite-style.")
2332 (setq message-cite-style 'message-cite-style-bandali
2333 message-kill-buffer-on-exit t
51db62d8
AB
2334 message-send-mail-function 'message-send-mail-with-sendmail
2335 message-sendmail-envelope-from 'header
9ae707cc 2336 message-dont-reply-to-names
2c0f7884 2337 "\\(\\(.*@aminb\\.org\\)\\|\\(amin@bandali\\.me\\)\\|\\(\\(aminb?\\|mab\\|bandali\\)@gnu\\.org\\)\\|\\(\\(m\\|a\\(min\\.\\)?\\)bandali@uwaterloo\\.ca\\)\\)"
41a4f26a 2338 message-user-fqdn "aminb.org")
9ae707cc
AB
2339 :hook (;; (message-setup . mml-secure-message-sign-pgpmime)
2340 (message-mode . flyspell-mode)
6f6bbd01 2341 (message-mode . (lambda ()
4b7207e1
AB
2342 ;; (setq fill-column 65
2343 ;; message-fill-column 65)
6f6bbd01
AB
2344 (make-local-variable 'company-idle-delay)
2345 (setq company-idle-delay 0.2))))
4b4c2c1d
AB
2346 ;; :custom-face
2347 ;; (message-header-subject ((t (:foreground "#111" :weight semi-bold))))
2348 ;; (message-header-to ((t (:foreground "#111" :weight normal))))
2349 ;; (message-header-cc ((t (:foreground "#333" :weight normal))))
2350 )
51db62d8
AB
2351
2352(after! mml-sec
2353 (setq mml-secure-openpgp-encrypt-to-self t
2354 mml-secure-openpgp-sign-with-sender t))
6c5b745f 2355#+end_src
51db62d8 2356
ca2bcf5f
AB
2357** footnote
2358
2359Convenient footnotes in =message-mode=.
2360
2361#+begin_src emacs-lisp
2362(use-package footnote
2363 :after message
2364 :bind
2365 (:map message-mode-map
2366 :prefix-map amin--footnote-prefix-map
2367 :prefix "C-c f"
2368 ("a" . footnote-add-footnote)
2369 ("b" . footnote-back-to-message)
2370 ("c" . footnote-cycle-style)
2371 ("d" . footnote-delete-footnote)
2372 ("g" . footnote-goto-footnote)
2373 ("r" . footnote-renumber-footnotes)
2374 ("s" . footnote-set-style))
2375 :config
2376 (setq footnote-start-tag ""
2377 footnote-end-tag ""
2378 footnote-style 'unicode))
2379#+end_src
2380
1a5de666 2381** bbdb
81ad062d 2382
1a5de666
AB
2383Manually install bbdb (=lisp/bbdb= copied from an ELPA-based setup),
2384because installing it from source on Emacs 27 using the following
2385submodule configuration for some reason doesn’t work and results in
2386very strange errors when using any of the functions.
2387
2388#+begin_src conf :tangle no
81ad062d
AB
2389[submodule "bbdb"]
2390 path = lib/bbdb
2391 url = https://git.savannah.nongnu.org/git/bbdb.git
1a5de666 2392 load-path = lisp
81ad062d
AB
2393 info-path = doc
2394 build-step = ./autogen.sh
1a5de666 2395 build-step = ./configure
81ad062d
AB
2396 build-step = make
2397 build-step = make install
1a5de666
AB
2398#+end_src
2399
2400I tried using =borg-elpa= instead of doing it like this, but it added
24012 seconds to my startup time, which is unacceptable to me.
81ad062d
AB
2402
2403#+begin_src emacs-lisp
2404(use-package bbdb
1a5de666 2405 :load-path "lisp/bbdb"
81ad062d 2406 :init
1a5de666 2407 (load (expand-file-name "lisp/bbdb/bbdb-autoloads.el" user-emacs-directory))
34fc3c29
AB
2408 ;; (bbdb-mua-auto-update-init 'message)
2409 (setq bbdb-mua-auto-update-p 'query
2410 bbdb-complete-mail nil)
2411 (bbdb-initialize 'gnus 'message))
81ad062d
AB
2412#+end_src
2413
2414** COMMENT message-x
2415
2416#+begin_src emacs-lisp
2417(use-package message-x
2418 :custom
2419 (message-x-completion-alist
2420 (quote
2421 (("\\([rR]esent-\\|[rR]eply-\\)?[tT]o:\\|[bB]?[cC][cC]:" . gnus-harvest-find-address)
2422 ((if
2423 (boundp
2424 (quote message-newgroups-header-regexp))
2425 message-newgroups-header-regexp message-newsgroups-header-regexp)
2426 . message-expand-group)))))
2427#+end_src
2428
2429** COMMENT gnus-harvest
2430
2431#+begin_src emacs-lisp
2432(use-package gnus-harvest
2433 :commands gnus-harvest-install
2434 :demand t
2435 :config
2436 (if (featurep 'message-x)
2437 (gnus-harvest-install 'message-x)
2438 (gnus-harvest-install)))
2439#+end_src
2440
97934ec4
AB
2441* Blogging
2442** [[https://ox-hugo.scripter.co][ox-hugo]]
2443
2444#+begin_src emacs-lisp
2445(use-package ox-hugo
2446 :after ox)
4e88d051
AB
2447
2448(use-package ox-hugo-auto-export
2449 :load-path "lib/ox-hugo")
97934ec4
AB
2450#+end_src
2451
180cab37
AB
2452* Post initialization
2453:PROPERTIES:
967b0a82 2454:CUSTOM_ID: post-initialization
180cab37
AB
2455:END:
2456
2457Display how long it took to load the init file.
2458
2459#+begin_src emacs-lisp
2460(message "Loading %s...done (%.3fs)" user-init-file
2461 (float-time (time-subtract (current-time)
850dd012 2462 amin--before-user-init-time)))
180cab37
AB
2463#+end_src
2464
2465* Footer
2466:PROPERTIES:
2467:CUSTOM_ID: footer
2468:END:
2469
2470#+begin_src emacs-lisp :comments none
2471;;; init.el ends here
2472#+end_src
eb689aa4
AB
2473
2474* COMMENT Local Variables :ARCHIVE:
2475# Local Variables:
2476# eval: (add-hook 'after-save-hook #'amin/async-babel-tangle 'append 'local)
2477# End: