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