[emacs] Update 2 drones
[~bandali/configs] / init.org
... / ...
CommitLineData
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
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]]
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
37** Installation
38
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
43#+begin_src sh :tangle no
44git clone https://github.com/aminb/dotfiles ~/.emacs.d
45cd ~/.emacs.d
46make bootstrap-borg
47make bootstrap
48make build
49#+end_src
50
51* Contents :toc_1:noexport:
52
53- [[#about][About]]
54- [[#header][Header]]
55- [[#initial-setup][Initial setup]]
56- [[#core][Core]]
57- [[#post-initialization][Post initialization]]
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
79;; Copyright (C) 2018 Amin Bandali <bandali@gnu.org>
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
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]].
109
110#+begin_src emacs-lisp :comments none
111;; Naming conventions:
112;;
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
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
139(defvar amin--before-user-init-time (current-time)
140 "Value of `current-time' when Emacs begins loading `user-init-file'.")
141(message "Loading Emacs...done (%.3fs)"
142 (float-time (time-subtract amin--before-user-init-time
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
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)
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 ()
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)))
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
190** whoami
191
192#+begin_src emacs-lisp
193(setq user-full-name "Amin Bandali"
194 user-mail-address "amin@aminb.org")
195#+end_src
196
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)
236
237;; (require 'borg-nix-shell)
238;; (setq borg-build-shell-command 'borg-nix-shell-build-command)
239
240(with-eval-after-load 'bind-key
241 (bind-keys
242 :package borg
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)
247 ("C-c b r" . borg-remove)))
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)
262(if nil ; set to t when need to debug init
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
283 :defer t
284 :bind
285 (("C-c b d" . epkg-describe-package)
286 ("C-c b p" . epkg-list-packages)
287 ("C-c b u" . epkg-update)))
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
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
327** Secrets file
328
329Load the secrets file if it exists, otherwise show a warning.
330
331#+begin_src emacs-lisp
332(with-demoted-errors
333 (load (no-littering-expand-etc-file-name "secrets")))
334#+end_src
335
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
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"))
351#+end_src
352
353** COMMENT Only one custom theme at a time
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
361** Server
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
373 :defer 1
374 :config (or (server-running-p) (server-mode)))
375#+end_src
376
377** COMMENT Unicode support
378
379Font stack with better unicode support, around =Ubuntu Mono= and
380=Hack=.
381
382#+begin_src emacs-lisp :tangle no
383(dolist (ft (fontset-list))
384 (set-fontset-font
385 ft
386 'unicode
387 (font-spec :name "Source Code Pro" :size 14))
388 (set-fontset-font
389 ft
390 'unicode
391 (font-spec :name "DejaVu Sans Mono")
392 nil
393 'append)
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)
407 (set-fontset-font
408 ft
409 (cons ?Α ?ω)
410 (font-spec :name "DejaVu Sans Mono" :size 14)
411 nil
412 'prepend))
413#+end_src
414
415** Gentler font resizing
416
417#+begin_src emacs-lisp
418(setq text-scale-mode-step 1.05)
419#+end_src
420
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
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
449(defun amin-enlist (exp)
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))
459 (dolist (next (amin-enlist features))
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)
478 `(after! (:all ,@features) ,@body)))))
479#+end_src
480
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
490* Core
491:PROPERTIES:
492:CUSTOM_ID: core
493:END:
494
495** Defaults
496
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
503Note: using =i3status= on sway at the moment, so disabling this.
504
505#+begin_src emacs-lisp :tangle no
506(use-package time
507 :init
508 (setq display-time-default-load-average nil)
509 :config
510 (display-time-mode))
511
512(use-package battery
513 :config
514 (display-battery-mode))
515#+end_src
516
517*** Smaller fringe
518
519Might want to set the fringe to a smaller value, especially if using
520EXWM. I'm fine with the default for now.
521
522#+begin_src emacs-lisp
523;; (fringe-mode '(3 . 1))
524(fringe-mode nil)
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
623 version-control t
624 delete-old-versions t)
625#+end_src
626
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
634 global-auto-revert-non-file-buffers nil)
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
646*** Winner mode
647
648Enable =winner-mode=.
649
650#+begin_src emacs-lisp
651(winner-mode 1)
652#+end_src
653
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
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
681** Bindings
682
683#+begin_src emacs-lisp
684(bind-keys
685 ("s-c e b" . eval-buffer)
686 ("s-c e r" . eval-region)
687
688 ("s-p" . beginning-of-buffer)
689 ("s-n" . end-of-buffer))
690#+end_src
691
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
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)
712 (add-hook 'auto-compile-inhibit-compile-hook
713 'auto-compile-inhibit-compile-detached-git-head))
714#+end_src
715
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)
739 :config
740 (evil-mode 1)
741 (general-swap-key nil '(normal motion) ";" ":")
742
743 (setq evil-want-visual-char-semi-exclusive t
744 evil-cross-lines t)
745
746 ;; custom mode state mappings
747 (dolist (mspair '((ebdb-mode . emacs)
748 (term-mode . emacs)
749 (helpful-mode . motion)
750 (magit-blame-mode . motion)
751 (view-mode . motion)))
752 (evil-set-initial-state (car mspair) (cdr mspair)))
753
754 ;; fix tab and indentation in src blocks inside org-mode buffer
755 ;; also see https://git.sr.ht/~bandali/dotfiles/commit/0e2ffd584aafdd4cf256bcdf2473f01c3aaaed55
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)
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)))
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
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
812#+begin_src emacs-lisp
813(amin--leader-keys
814 "/" '(:ignore t :wk "search")
815
816 "a" '(:ignore t :wk "apps")
817 "a i" 'ielm
818
819 "a s" '(:ignore t :wk "shells/terms")
820
821 "b" '(:ignore t :wk "buffers")
822 "b k" 'kill-this-buffer
823 "b s" 'save-buffer
824
825 "e" '(:ignore t :wk "eval")
826 "e b" 'eval-buffer
827 "e r" 'eval-region
828
829 "f" '(:ignore t :wk "files")
830
831 "F" '(:ignore t :wk "frames")
832 "F m" 'make-frame-command
833 "F d" 'delete-frame
834 "F D" 'delete-other-frames
835
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
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
856
857 "q" '(:ignore t :wk "quit")
858 "q q" 'save-buffers-kill-terminal)
859#+end_src
860
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
872(use-package org
873 :defer 1
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)
890 :config
891 (setq org-src-tab-acts-natively t
892 org-src-preserve-indentation nil
893 org-edit-src-content-indentation 0
894 org-email-link-description-format "Email %c: %s" ; %.30s
895 org-highlight-latex-and-related '(entities)
896 org-log-done 'time)
897 (add-to-list 'org-structure-template-alist '("L" . "src emacs-lisp") t)
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))
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)
916 :bind (:map org-mode-map ("M-L" . org-insert-last-stored-link))
917 :hook ((org-mode . org-indent-mode)
918 (org-mode . auto-fill-mode)
919 (org-mode . flyspell-mode))
920 :custom
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")))))
926
927(use-package ox-latex
928 :after ox
929 :config
930 (setq org-latex-listings 'listings
931 ;; org-latex-prefer-user-labels t
932 )
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))
943
944(use-package ox-beamer
945 :after ox)
946
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
954(use-package orgalist
955 :after message
956 :hook (message-mode . orgalist-mode))
957#+end_src
958
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
973 (defvar amin-async-tangle-post-compile "make ti"
974 "If non-nil, pass to `compile' after successful tangle.")
975
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
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)))
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
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
1017 :defer 1
1018 :general
1019 (amin--leader-keys
1020 "g s" 'magit-status
1021 "g l" 'magit-log-buffer-file)
1022 :bind ("s-g" . magit-status)
1023 :config
1024 (magit-add-section-hook 'magit-status-sections-hook
1025 'magit-insert-modules
1026 'magit-insert-stashes
1027 'append)
1028 (setq
1029 magit-repository-directories '(("~/.emacs.d/" . 0)
1030 ("~/src/git/" . 1)))
1031 (nconc magit-section-initial-visibility-alist
1032 '(([unpulled status] . show)
1033 ([unpushed status] . show)))
1034 :custom-face (magit-diff-file-heading ((t (:weight normal)))))
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
1049(use-package ivy
1050 :defer 1
1051 :general (amin--leader-keys "," 'ivy-switch-buffer)
1052 :bind
1053 (:map ivy-minibuffer-map
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))
1058 :config
1059 (setq ivy-wrap t)
1060 (ivy-mode 1)
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)
1066#+end_src
1067
1068**** Swiper
1069
1070#+begin_src emacs-lisp
1071(use-package swiper
1072 :general (:states '(normal motion) "/" 'swiper)
1073 :bind (("C-s" . swiper)
1074 ("C-r" . swiper)))
1075#+end_src
1076
1077**** Counsel
1078
1079#+begin_src emacs-lisp
1080(use-package counsel
1081 :defer 1
1082 :general
1083 (amin--leader-keys
1084 "r" 'counsel-recentf
1085 "SPC" 'counsel-M-x
1086 "." 'counsel-find-file)
1087 :bind (([remap execute-extended-command] . counsel-M-x)
1088 ([remap find-file] . counsel-find-file)
1089 ("s-r" . counsel-recentf)
1090 ("C-c x" . counsel-M-x)
1091 ("C-c f ." . counsel-find-file)
1092 :map minibuffer-local-map
1093 ("C-r" . counsel-minibuffer-history))
1094 :config
1095 (counsel-mode 1)
1096 (defalias 'locate #'counsel-locate))
1097#+end_src
1098
1099*** eshell
1100
1101#+begin_src emacs-lisp
1102(use-package eshell
1103 :defer 1
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
1113 (defun amin/eshell-clear ()
1114 (interactive)
1115 (let ((inhibit-read-only t))
1116 (erase-buffer))
1117 (eshell-send-input))
1118
1119 (defun amin|eshell-setup ()
1120 (make-local-variable 'company-idle-delay)
1121 (setq company-idle-delay nil)
1122 (bind-keys :map eshell-mode-map
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)))
1127
1128 :hook (eshell-mode . amin|eshell-setup)
1129 :custom
1130 (eshell-hist-ignoredups t)
1131 (eshell-input-filter 'eshell-input-filter-initial-space))
1132#+end_src
1133
1134*** Ibuffer
1135
1136#+begin_src emacs-lisp
1137(use-package ibuffer
1138 :defer t
1139 :general (amin--leader-keys "b b" 'ibuffer-other-window)
1140 :bind
1141 (("C-x C-b" . ibuffer-other-window)
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))
1160 ("org" (mode . org-mode))
1161 ("web"
1162 (or
1163 (mode . web-mode)
1164 (mode . css-mode)
1165 (mode . scss-mode)
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\\*$")
1180 (name . "^\\*Messages\\*$")))
1181 ("slack"
1182 (or
1183 (name . "^\\*Slack*"))))))
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
1198*** Outline
1199
1200#+begin_src emacs-lisp
1201(use-package outline
1202 :defer t
1203 :hook (prog-mode . outline-minor-mode)
1204 :bind
1205 (:map
1206 outline-minor-mode-map
1207 ("<s-tab>" . outline-toggle-children)
1208 ("M-p" . outline-previous-visible-heading)
1209 ("M-n" . outline-next-visible-heading)
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
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
1244 :config
1245 (temp-buffer-resize-mode)
1246 (setq help-window-select t))
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
1273 :defer 0.5
1274 :config
1275 (add-to-list 'recentf-exclude "^/\\(?:ssh\\|su\\|sudo\\)?:")
1276 (setq recentf-max-saved-items 40))
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'
1289 (add-hook 'text-mode-hook #'indicate-buffer-boundaries-left)
1290 (add-hook 'text-mode-hook #'abbrev-mode))
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
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))
1309#+end_src
1310
1311* Editing
1312
1313** Company
1314
1315#+begin_src emacs-lisp
1316(use-package company
1317 :defer 1
1318 :bind
1319 (:map company-active-map
1320 ([tab] . company-complete-common-or-cycle)
1321 ([escape] . company-abort))
1322 :custom
1323 (company-minimum-prefix-length 1)
1324 (company-selection-wrap-around t)
1325 (company-dabbrev-char-regexp "\\sw\\|\\s_\\|[-_]")
1326 (company-dabbrev-downcase nil)
1327 (company-dabbrev-ignore-case nil)
1328 :config
1329 (global-company-mode t))
1330#+end_src
1331
1332* Syntax and spell checking
1333#+begin_src emacs-lisp
1334(use-package flycheck
1335 :defer 3
1336 :hook (prog-mode . flycheck-mode)
1337 :bind
1338 (:map flycheck-mode-map
1339 ("M-P" . flycheck-previous-error)
1340 ("M-N" . flycheck-next-error))
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)))
1347
1348;; http://endlessparentheses.com/ispell-and-apostrophes.html
1349(use-package ispell
1350 :defer 3
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))
1373#+end_src
1374* Programming modes
1375
1376** [[http://alloytools.org][Alloy]] (with [[https://github.com/dwwmmn/alloy-mode][alloy-mode]])
1377
1378#+begin_src emacs-lisp
1379(use-package alloy-mode
1380 :defer t
1381 :config (setq alloy-basic-offset 2))
1382#+end_src
1383
1384** [[https://coq.inria.fr][Coq]] (with [[https://github.com/ProofGeneral/PG][Proof General]])
1385
1386#+begin_src emacs-lisp
1387(use-package proof-site ; Proof General
1388 :defer t
1389 :load-path "lib/proof-site/generic/")
1390#+end_src
1391
1392** [[https://leanprover.github.io][Lean]] (with [[https://github.com/leanprover/lean-mode][lean-mode]])
1393
1394#+begin_src emacs-lisp
1395(eval-when-compile (defvar lean-mode-map))
1396(use-package lean-mode
1397 :defer 1
1398 :bind (:map lean-mode-map
1399 ("S-SPC" . company-complete))
1400 :config
1401 (require 'lean-input)
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))
1408 #+end_src
1409
1410** Haskell
1411
1412*** [[https://github.com/haskell/haskell-mode][haskell-mode]]
1413
1414#+begin_src emacs-lisp
1415(use-package haskell-mode
1416 :defer t
1417 :config
1418 (setq haskell-indentation-layout-offset 4
1419 haskell-indentation-left-offset 4
1420 flycheck-checker 'haskell-hlint
1421 flycheck-disabled-checkers '(haskell-stack-ghc haskell-ghc)))
1422#+end_src
1423
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
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
1440 :after haskell-mode
1441 :bind (:map hlint-refactor-mode-map
1442 ("C-c l b" . hlint-refactor-refactor-buffer)
1443 ("C-c l r" . hlint-refactor-refactor-at-point))
1444 :hook (haskell-mode . hlint-refactor-mode))
1445#+end_src
1446
1447*** [[https://github.com/flycheck/flycheck-haskell][flycheck-haskell]]
1448
1449#+begin_src emacs-lisp
1450(use-package flycheck-haskell
1451 :after haskell-mode)
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))
1545 (goto-char (point-min))
1546 (forward-line (1- fline))
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
1598
1599** Web dev
1600
1601*** SGML and HTML
1602
1603#+begin_src emacs-lisp
1604(use-package sgml-mode
1605 :defer t
1606 :config
1607 (setq sgml-basic-offset 2))
1608#+end_src
1609
1610*** CSS and SCSS
1611
1612#+begin_src emacs-lisp
1613(use-package css-mode
1614 :defer t
1615 :config
1616 (setq css-indent-offset 2))
1617#+end_src
1618
1619*** Web mode
1620
1621#+begin_src emacs-lisp
1622(use-package web-mode
1623 :defer t
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))
1630#+end_src
1631
1632*** Emmet mode
1633
1634#+begin_src emacs-lisp
1635(use-package emmet-mode
1636 :after (:any web-mode css-mode sgml-mode)
1637 :bind* (("C-)" . emmet-next-edit-point)
1638 ("C-(" . emmet-prev-edit-point))
1639 :config
1640 (unbind-key "C-j" emmet-mode-keymap)
1641 (setq emmet-move-cursor-between-quotes t)
1642 :hook (web-mode css-mode html-mode sgml-mode))
1643#+end_src
1644
1645** Nix
1646
1647#+begin_src emacs-lisp
1648(use-package nix-mode
1649 :defer t
1650 :mode "\\.nix\\'")
1651#+end_src
1652
1653** Java
1654
1655*** meghanada
1656
1657#+begin_src emacs-lisp :tangle no
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
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
1684#+begin_src emacs-lisp :tangle no
1685(use-package treemacs
1686 :config (setq treemacs-never-persist t))
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
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
1747
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
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
1770** theme helper functions
1771
1772#+begin_src emacs-lisp
1773(defun amin/lights-on ()
1774 "Enable my favourite light theme."
1775 (interactive)
1776 (progn
1777 (mapc #'disable-theme custom-enabled-themes)
1778 (load-theme 'tangomod t)))
1779
1780(defun amin/lights-off ()
1781 "Go dark."
1782 (interactive)
1783 (progn
1784 (mapc #'disable-theme custom-enabled-themes)
1785 (load-theme 'doom-tomorrow-night t)))
1786
1787(amin--leader-keys
1788 "t" '(:ignore t :wk "theme")
1789 "t d" 'amin/lights-off
1790 "t l" 'amin/lights-on)
1791#+end_src
1792
1793** [[https://github.com/bbatsov/crux][crux]]
1794
1795#+begin_src emacs-lisp
1796(use-package crux
1797 :defer 1
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)
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)))
1810#+end_src
1811
1812** [[https://github.com/alezost/mwim.el][mwim]]
1813
1814#+begin_src emacs-lisp
1815(use-package mwim
1816 :general
1817 (:states '(normal visual)
1818 "0" 'mwim-beginning-of-code-or-line
1819 "$" 'mwim-end-of-code-or-line)
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)
1823 ("<end>" . mwim-end-of-line-or-code)))
1824#+end_src
1825
1826** projectile
1827
1828#+begin_src emacs-lisp
1829(use-package projectile
1830 :defer t
1831 :bind-keymap ("C-c p" . projectile-command-map)
1832 :config
1833 (projectile-mode)
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
1847** [[https://github.com/Wilfred/helpful][helpful]]
1848
1849#+begin_src emacs-lisp
1850(use-package helpful
1851 :defer 1
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))
1860#+end_src
1861
1862** [[https://github.com/knu/shell-toggle.el][shell-toggle]]
1863
1864#+begin_src emacs-lisp
1865(use-package shell-toggle
1866 :after eshell
1867 :general (amin--leader-keys "a s e" 'amin/shell-toggle)
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))
1908#+end_src
1909
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
1916 :defer 3
1917 :config
1918 (unkillable-scratch 1)
1919 :custom
1920 (unkillable-scratch-behavior 'do-nothing)
1921 (unkillable-buffers '("^\\*scratch\\*$" "^\\*Messages\\*$")))
1922#+end_src
1923
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
1934 :defer 3
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
1962** COMMENT [[https://github.com/DarthFennec/highlight-indent-guides][highlight-indent-guides]] :ARCHIVE:
1963
1964#+begin_src emacs-lisp
1965(use-package highlight-indent-guides
1966 :defer 3
1967 :hook ((prog-mode . highlight-indent-guides-mode)
1968 ;; (org-mode . highlight-indent-guides-mode)
1969 )
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
1979** pdf-tools
1980
1981#+begin_src emacs-lisp
1982(use-package pdf-tools
1983 :defer t
1984 :magic ("%PDF" . pdf-view-mode)
1985 :config
1986 (setq pdf-view-resize-factor 1.05)
1987 (pdf-tools-install)
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)
1993 ("k" . pdf-view-previous-line-or-previous-page)
1994 ("h" . image-backward-hscroll)
1995 ("l" . image-forward-hscroll)))
1996#+end_src
1997
1998** anzu
1999
2000#+begin_src emacs-lisp
2001(use-package anzu)
2002#+end_src
2003
2004** typo.el
2005
2006#+begin_src emacs-lisp
2007(use-package typo
2008 :defer 2
2009 :config
2010 (typo-global-mode 1)
2011 :hook (text-mode . typo-mode))
2012#+end_src
2013
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:
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)
2087 :full-and-display-names t)
2088 (add-to-list 'swiper-font-lock-exclude 'slack-message-buffer-mode t)
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)
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
2099 ("M-p" . slack-buffer-goto-prev-message)
2100 ("M-n" . slack-buffer-goto-next-message)
2101 ("C-c e" . slack-message-edit)
2102 ("C-c k" . slack-message-delete)
2103 ("C-c C-k" . slack-channel-leave)
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)
2110 ("@" . slack-message-embed-mention)
2111 ("#" . slack-message-embed-channel)))
2112
2113(use-package alert
2114 :commands (alert)
2115 :init
2116 (setq alert-default-style 'notifier))
2117#+end_src
2118
2119** COMMENT magithub :ARCHIVE:
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
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
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
2172* Email
2173
2174#+begin_src emacs-lisp
2175(defvar amin-maildir (expand-file-name "~/mail/"))
2176(after! recentf
2177 (add-to-list 'recentf-exclude amin-maildir))
2178#+end_src
2179
2180** Gnus
2181
2182#+begin_src emacs-lisp
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)
2187
2188(use-package gnus
2189 :general
2190 (amin--leader-keys
2191 "m" 'gnus
2192 "M" 'gnus-unplugged)
2193 :bind (("s-m" . gnus)
2194 ("s-M" . gnus-unplugged))
2195 :init
2196 (setq
2197 gnus-select-method '(nnnil "")
2198 gnus-secondary-select-methods
2199 '((nnimap "amin"
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"))
2205 (nnimap "uwaterloo"
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")))
2211 gnus-message-archive-group "nnimap+amin:Sent"
2212 gnus-parameters
2213 '(("gnu.*"
2214 (gcc-self . t)))
2215 gnus-large-newsgroup 50
2216 gnus-home-directory (no-littering-expand-var-file-name "gnus/")
2217 gnus-directory (concat gnus-home-directory "news/")
2218 message-directory (concat gnus-home-directory "mail/")
2219 nndraft-directory (concat gnus-home-directory "drafts/")
2220 gnus-save-newsrc-file nil
2221 gnus-read-newsrc-file nil
2222 gnus-interactive-exit nil
2223 gnus-gcc-mark-as-read t))
2224
2225(use-package gnus-art
2226 :config
2227 (setq
2228 gnus-visible-headers
2229 (concat gnus-visible-headers "\\|^List-Id:\\|^X-RT-Originator:\\|^User-Agent:")
2230 gnus-sorted-header-list
2231 '("^From:" "^Subject:" "^Summary:" "^Keywords:"
2232 "^Followup-To:" "^To:" "^Cc:" "X-RT-Originator"
2233 "^Newsgroups:" "List-Id:" "^Organization:"
2234 "^User-Agent:" "^Date:")
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))))
2247 (concat local lapsed))))
2248 (bind-keys
2249 :map gnus-article-mode-map
2250 ("r" . gnus-article-reply-with-original)
2251 ("R" . gnus-article-wide-reply-with-original)
2252 ("M-L" . org-store-link)))
2253
2254(use-package gnus-sum
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))
2261 :config
2262 (bind-keys
2263 :map gnus-summary-mode-map
2264 ("r" . gnus-summary-reply-with-original)
2265 ("R" . gnus-summary-wide-reply-with-original)
2266 ("M-L" . org-store-link))
2267 :hook (gnus-summary-mode . amin--no-mouse-autoselect-window))
2268
2269(use-package gnus-msg
2270 :config
2271 (setq gnus-posting-styles
2272 '((".*"
2273 (address "amin@aminb.org")
2274 (body "\nBest,\namin\n")
2275 (eval (setq amin--message-cite-say-hi t)))
2276 ("gnu.*"
2277 (address "bandali@gnu.org"))
2278 ((header "subject" "ThankCRM")
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)))
2282 ("nnimap\\+uwaterloo:.*"
2283 (address "abandali@uwaterloo.ca")
2284 (gcc "\"nnimap+uwaterloo:Sent Items\"")))))
2285
2286(use-package gnus-topic
2287 :hook (gnus-group-mode . gnus-topic-mode))
2288
2289(use-package gnus-agent
2290 :config
2291 (setq gnus-agent-synchronize-flags 'ask)
2292 :hook (gnus-group-mode . gnus-agent-mode))
2293
2294(use-package gnus-group
2295 :config
2296 (setq gnus-permanently-visible-groups "\\((INBOX\\|gnu$\\)"))
2297
2298(use-package mm-decode
2299 :config
2300 (setq mm-discouraged-alternatives '("text/html" "text/richtext")))
2301#+end_src
2302
2303** sendmail
2304
2305#+begin_src emacs-lisp
2306(use-package sendmail
2307 :config
2308 (setq sendmail-program "/usr/bin/msmtp"
2309 ;; message-sendmail-extra-arguments '("-v" "-d")
2310 mail-specify-envelope-from t
2311 mail-envelope-from 'header))
2312#+end_src
2313
2314** message
2315
2316#+begin_src emacs-lisp
2317(use-package message
2318 :config
2319 (defconst amin--message-cite-style-format "On %Y-%m-%d %l:%M %p, %N wrote:")
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 ">")
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)))
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
2334 message-send-mail-function 'message-send-mail-with-sendmail
2335 message-sendmail-envelope-from 'header
2336 message-dont-reply-to-names
2337 "\\(\\(.*@aminb\\.org\\)\\|\\(amin@bandali\\.me\\)\\|\\(\\(aminb?\\|mab\\|bandali\\)@gnu\\.org\\)\\|\\(\\(m\\|a\\(min\\.\\)?\\)bandali@uwaterloo\\.ca\\)\\)"
2338 message-user-fqdn "aminb.org")
2339 :hook (;; (message-setup . mml-secure-message-sign-pgpmime)
2340 (message-mode . flyspell-mode)
2341 (message-mode . (lambda ()
2342 ;; (setq fill-column 65
2343 ;; message-fill-column 65)
2344 (make-local-variable 'company-idle-delay)
2345 (setq company-idle-delay 0.2))))
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 )
2351
2352(after! mml-sec
2353 (setq mml-secure-openpgp-encrypt-to-self t
2354 mml-secure-openpgp-sign-with-sender t))
2355#+end_src
2356
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
2381** bbdb
2382
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
2389[submodule "bbdb"]
2390 path = lib/bbdb
2391 url = https://git.savannah.nongnu.org/git/bbdb.git
2392 load-path = lisp
2393 info-path = doc
2394 build-step = ./autogen.sh
2395 build-step = ./configure
2396 build-step = make
2397 build-step = make install
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.
2402
2403#+begin_src emacs-lisp
2404(use-package bbdb
2405 :load-path "lisp/bbdb"
2406 :init
2407 (load (expand-file-name "lisp/bbdb/bbdb-autoloads.el" user-emacs-directory))
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))
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
2441* Blogging
2442** [[https://ox-hugo.scripter.co][ox-hugo]]
2443
2444#+begin_src emacs-lisp
2445(use-package ox-hugo
2446 :after ox)
2447
2448(use-package ox-hugo-auto-export
2449 :load-path "lib/ox-hugo")
2450#+end_src
2451
2452* Post initialization
2453:PROPERTIES:
2454:CUSTOM_ID: post-initialization
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)
2462 amin--before-user-init-time)))
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
2473
2474* COMMENT Local Variables :ARCHIVE:
2475# Local Variables:
2476# eval: (add-hook 'after-save-hook #'amin/async-babel-tangle 'append 'local)
2477# End: