[emacs] properly build and use notmuch along with my settings
[~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 <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
108The conventions below were inspired by [[https://github.com/hlissner/doom-emacs][Doom]]'s conventions, found
109[[https://github.com/hlissner/doom-emacs/blob/5dacbb7cb1c6ac246a9ccd15e6c4290def67757c/core/core.el#L3-L17][here]]. Naturally, I use my initials, =ab=, instead of =doom=.
110
111#+begin_src emacs-lisp :comments none
112;; Naming conventions:
113;;
114;; ab-... public variables or non-interactive functions
115;; ab--... private anything (non-interactive), not safe for direct use
116;; ab/... an interactive function; safe for M-x or keybinding
117;; ab:... an evil operator, motion, or command
118;; ab|... a hook function
119;; ab*... an advising function
120;; ab@... a hydra command
121;; ...! a macro
122#+end_src
123
124* Initial setup
125:PROPERTIES:
126:CUSTOM_ID: initial-setup
127:END:
128
129#+begin_src emacs-lisp :comments none
130;;; Code:
131#+end_src
132
133** Emacs initialization
134
135I'd like to do a couple of measurements of Emacs' startup time. First,
136let's see how long Emacs takes to start up, before even loading
137=init.el=, i.e. =user-init-file=:
138
139#+begin_src emacs-lisp
140(defvar ab--before-user-init-time (current-time)
141 "Value of `current-time' when Emacs begins loading `user-init-file'.")
142(message "Loading Emacs...done (%.3fs)"
143 (float-time (time-subtract ab--before-user-init-time
144 before-init-time)))
145#+end_src
146
147Also, temporarily increase ~gc-cons-threshhold~ and
148~gc-cons-percentage~ during startup to reduce garbage collection
149frequency. Clearing the ~file-name-handler-alist~ seems to help reduce
150startup time as well.
151
152#+begin_src emacs-lisp
153(defvar ab--gc-cons-threshold gc-cons-threshold)
154(defvar ab--gc-cons-percentage gc-cons-percentage)
155(defvar ab--file-name-handler-alist file-name-handler-alist)
156(setq gc-cons-threshold (* 400 1024 1024) ; 400 MiB
157 gc-cons-percentage 0.6
158 file-name-handler-alist nil
159 ;; sidesteps a bug when profiling with esup
160 esup-child-profile-require-level 0)
161#+end_src
162
163Of course, we'd like to set them back to their defaults once we're
164done initializing.
165
166#+begin_src emacs-lisp
167(add-hook
168 'after-init-hook
169 (lambda ()
170 (setq gc-cons-threshold ab--gc-cons-threshold
171 gc-cons-percentage ab--gc-cons-percentage
172 file-name-handler-alist ab--file-name-handler-alist)))
173#+end_src
174
175Increase the number of lines kept in message logs (the =*Messages*=
176buffer).
177
178#+begin_src emacs-lisp
179(setq message-log-max 20000)
180#+end_src
181
182Optionally, we could suppress some byte compiler warnings like below,
183but for now I've decided to keep them enabled. See documentation for
184~byte-compile-warnings~ for more details.
185
186#+begin_src emacs-lisp
187;; (setq byte-compile-warnings
188;; '(not free-vars unresolved noruntime lexical make-local))
189#+end_src
190
191** Package management
192
193*** No =package.el=
194
195I can do all my package management things with Borg, and don't need
196Emacs' built-in =package.el=. Emacs 27 lets us disable =package.el= in
197the =early-init-file= (see [[https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=24acb31c04b4048b85311d794e600ecd7ce60d3b][here]]).
198
199#+begin_src emacs-lisp :tangle early-init.el
200(setq package-enable-at-startup nil)
201#+end_src
202
203But since Emacs 27 isn't out yet (Emacs 26 is just around the corner
204right now), and even when released it'll be long before most distros
205ship in their repos, I'll still put the old workaround with the
206commented call to ~package-initialize~ here anyway.
207
208#+begin_src emacs-lisp
209(setq package-enable-at-startup nil)
210;; (package-initialize)
211#+end_src
212
213*** Borg
214
215#+begin_quote
216Assimilate Emacs packages as Git submodules
217#+end_quote
218
219[[https://github.com/emacscollective/borg][Borg]] is at the heart of package management of my Emacs setup. In
220short, it creates a git submodule in =lib/= for each package, which
221can then be managed with the help of Magit or other tools.
222
223#+begin_src emacs-lisp
224(setq user-init-file (or load-file-name buffer-file-name)
225 user-emacs-directory (file-name-directory user-init-file))
226(add-to-list 'load-path
227 (expand-file-name "lib/borg" user-emacs-directory))
228(require 'borg)
229(borg-initialize)
230#+end_src
231
232*** =use-package=
233
234#+begin_quote
235A use-package declaration for simplifying your .emacs
236#+end_quote
237
238[[https://github.com/jwiegley/use-package][use-package]] is an awesome utility for managing and configuring
239packages (in our case especially the latter) in a neatly organized way
240and without compromising on performance.
241
242#+begin_src emacs-lisp
243(require 'use-package)
244(if nil ; set to t when need to debug init
245 (setq use-package-verbose t
246 use-package-expand-minimally nil
247 use-package-compute-statistics t
248 debug-on-error t)
249 (setq use-package-verbose nil
250 use-package-expand-minimally t))
251#+end_src
252
253*** Epkg
254
255#+begin_quote
256Browse the Emacsmirror package database
257#+end_quote
258
259Epkg provides access to a local copy of the [[https://emacsmirror.net][Emacsmirror]] package
260database, low-level functions for querying the database, and a
261=package.el=-like user interface for browsing the available packages.
262
263#+begin_src emacs-lisp
264(use-package epkg
265 :defer t)
266#+end_src
267
268** No littering in =~/.emacs.d=
269
270#+begin_quote
271Help keeping ~/.emacs.d clean
272#+end_quote
273
274By default, even for Emacs' built-in packages, the configuration files
275and persistent data are all over the place. Use =no-littering= to help
276contain the mess.
277
278#+begin_src emacs-lisp
279(use-package no-littering
280 :demand t
281 :config
282 (savehist-mode 1)
283 (add-to-list 'savehist-additional-variables 'kill-ring)
284 (save-place-mode 1)
285 (setq auto-save-file-name-transforms
286 `((".*" ,(no-littering-expand-var-file-name "auto-save/") t))))
287#+end_src
288
289** Custom file (=custom.el=)
290
291I'm not planning on using the custom file much, but even so, I
292definitely don't want it mixing with =init.el=. So, here; let's give
293it it's own file. While at it, treat themes as safe.
294
295#+begin_src emacs-lisp
296(use-package custom
297 :no-require t
298 :config
299 (setq custom-file (no-littering-expand-etc-file-name "custom.el"))
300 (when (file-exists-p custom-file)
301 (load custom-file))
302 (setf custom-safe-themes t))
303#+end_src
304
305** Better =$PATH= handling
306
307Let's use [[https://github.com/purcell/exec-path-from-shell][exec-path-from-shell]] to make Emacs use the =$PATH= as set up
308in my shell.
309
310#+begin_src emacs-lisp
311(use-package exec-path-from-shell
312 :defer 1
313 :init
314 (setq exec-path-from-shell-check-startup-files nil)
315 :config
316 (exec-path-from-shell-initialize)
317 ;; while we're at it, let's fix access to our running ssh-agent
318 (exec-path-from-shell-copy-env "SSH_AGENT_PID")
319 (exec-path-from-shell-copy-env "SSH_AUTH_SOCK"))
320#+end_src
321
322** Server
323
324Start server if not already running. Alternatively, can be done by
325issuing =emacs --daemon= in the terminal, which can be automated with
326a systemd service or using =brew services start emacs= on macOS. I use
327Emacs as my window manager (via EXWM), so I always start Emacs on
328login; so starting the server from inside Emacs is good enough for me.
329
330See [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Server.html#Emacs-Server][Using Emacs as a Server]].
331
332#+begin_src emacs-lisp
333(use-package server
334 :config (or (server-running-p) (server-mode)))
335#+end_src
336
337** Unicode support
338
339Font stack with better unicode support, around =Ubuntu Mono= and
340=Hack=.
341
342#+begin_src emacs-lisp
343(dolist (ft (fontset-list))
344 (set-fontset-font
345 ft
346 'unicode
347 (font-spec :name "Ubuntu Mono"))
348 (set-fontset-font
349 ft
350 'unicode
351 (font-spec :name "DejaVu Sans Mono")
352 nil
353 'append)
354 ;; (set-fontset-font
355 ;; ft
356 ;; 'unicode
357 ;; (font-spec
358 ;; :name "Symbola monospacified for DejaVu Sans Mono")
359 ;; nil
360 ;; 'append)
361 ;; (set-fontset-font
362 ;; ft
363 ;; #x2115 ; â„•
364 ;; (font-spec :name "DejaVu Sans Mono")
365 ;; nil
366 ;; 'append)
367 (set-fontset-font
368 ft
369 (cons ?Α ?ω)
370 (font-spec :name "DejaVu Sans Mono" :size 14)
371 nil
372 'prepend))
373#+end_src
374
375** Libraries
376
377#+begin_src emacs-lisp
378(require 'cl-lib)
379(require 'subr-x)
380#+end_src
381
382** Useful utilities
383
384#+begin_src emacs-lisp
385(defun ab-enlist (exp)
386 "Return EXP wrapped in a list, or as-is if already a list."
387(if (listp exp) exp (list exp)))
388
389; from https://github.com/hlissner/doom-emacs/commit/589108fdb270f24a98ba6209f6955fe41530b3ef
390(defmacro after! (features &rest body)
391 "A smart wrapper around `with-eval-after-load'. Supresses warnings during
392compilation."
393 (declare (indent defun) (debug t))
394 (list (if (or (not (bound-and-true-p byte-compile-current-file))
395 (dolist (next (ab-enlist features))
396 (if (symbolp next)
397 (require next nil :no-error)
398 (load next :no-message :no-error))))
399 #'progn
400 #'with-no-warnings)
401 (cond ((symbolp features)
402 `(eval-after-load ',features '(progn ,@body)))
403 ((and (consp features)
404 (memq (car features) '(:or :any)))
405 `(progn
406 ,@(cl-loop for next in (cdr features)
407 collect `(after! ,next ,@body))))
408 ((and (consp features)
409 (memq (car features) '(:and :all)))
410 (dolist (next (cdr features))
411 (setq body `(after! ,next ,@body)))
412 body)
413 ((listp features)
414 `(after! (:all ,@features) ,@body)))))
415#+end_src
416
417* Core
418:PROPERTIES:
419:CUSTOM_ID: core
420:END:
421
422** Defaults
423
424*** Time and battery in mode-line
425
426Enable displaying time and battery in the mode-line, since I'm not
427using the Xfce panel anymore. Also, I don't need to see the load
428average on a regular basis, so disable that.
429
430#+begin_src emacs-lisp
431(use-package time
432 :ensure nil
433 :init
434 (setq display-time-default-load-average nil)
435 :config
436 (display-time-mode))
437
438(use-package battery
439 :ensure nil
440 :config
441 (display-battery-mode))
442#+end_src
443
444*** Smaller fringe
445
446Might want to set the fringe to a smaller value, especially if using
447EXWM. I'm fine with the default for now.
448
449#+begin_src emacs-lisp
450;; (fringe-mode '(3 . 1))
451(fringe-mode nil)
452#+end_src
453
454*** Disable disabled commands
455
456Emacs disables some commands by default that could persumably be
457confusing for novice users. Let's disable that.
458
459#+begin_src emacs-lisp
460(setq disabled-command-function nil)
461#+end_src
462
463*** Kill-ring
464
465Save what I copy into clipboard from other applications into Emacs'
466kill-ring, which would allow me to still be able to easily access it
467in case I kill (cut or copy) something else inside Emacs before
468yanking (pasting) what I'd originally intended to.
469
470#+begin_src emacs-lisp
471(setq save-interprogram-paste-before-kill t)
472#+end_src
473
474*** Minibuffer
475
476#+begin_src emacs-lisp
477(setq enable-recursive-minibuffers t
478 resize-mini-windows t)
479#+end_src
480
481*** Lazy-person-friendly yes/no prompts
482
483Lazy people would prefer to type fewer keystrokes, especially for yes
484or no questions. I'm lazy.
485
486#+begin_src emacs-lisp
487(defalias 'yes-or-no-p #'y-or-n-p)
488#+end_src
489
490*** Startup screen and =*scratch*=
491
492Firstly, let Emacs know that I'd like to have =*scratch*= as my
493startup buffer.
494
495#+begin_src emacs-lisp
496(setq initial-buffer-choice t)
497#+end_src
498
499Now let's customize the =*scratch*= buffer a bit. First off, I don't
500need the default hint.
501
502#+begin_src emacs-lisp
503(setq initial-scratch-message nil)
504#+end_src
505
506Also, let's use Text mode as the major mode, in case I want to
507customize it (=*scratch*='s default major mode, Fundamental mode,
508can't really be customized).
509
510#+begin_src emacs-lisp
511(setq initial-major-mode 'text-mode)
512#+end_src
513
514Inhibit the buffer list when more than 2 files are loaded.
515
516#+begin_src emacs-lisp
517(setq inhibit-startup-buffer-menu t)
518#+end_src
519
520I don't really need to see the startup screen or echo area message
521either.
522
523#+begin_src emacs-lisp
524(advice-add #'display-startup-echo-area-message :override #'ignore)
525(setq inhibit-startup-screen t
526 inhibit-startup-echo-area-message user-login-name)
527#+end_src
528
529*** More useful frame titles
530
531Show either the file name or the buffer name (in case the buffer isn't
532visiting a file). Borrowed from Emacs Prelude.
533
534#+begin_src emacs-lisp
535(setq frame-title-format
536 '("" invocation-name " - "
537 (:eval (if (buffer-file-name)
538 (abbreviate-file-name (buffer-file-name))
539 "%b"))))
540#+end_src
541
542*** Backups
543
544Emacs' default backup settings aren't that great. Let's use more
545sensible options. See documentation for the ~make-backup-file~
546variable.
547
548#+begin_src emacs-lisp
549(setq backup-by-copying t
550 version-control t)
551#+end_src
552
553** Packages
554
555The packages in this section are absolutely essential to my everyday
556workflow, and they play key roles in how I do my computing. They
557immensely enhance the Emacs experience for me; both using Emacs, and
558customizing it.
559
560*** [[https://github.com/emacscollective/auto-compile][auto-compile]]
561
562#+begin_src emacs-lisp
563(use-package auto-compile
564 :demand t
565 :config
566 (auto-compile-on-load-mode)
567 (auto-compile-on-save-mode)
568 (setq auto-compile-display-buffer nil
569 auto-compile-mode-line-counter t
570 auto-compile-source-recreate-deletes-dest t
571 auto-compile-toggle-deletes-nonlib-dest t
572 auto-compile-update-autoloads t)
573 (add-hook 'auto-compile-inhibit-compile-hook
574 'auto-compile-inhibit-compile-detached-git-head))
575#+end_src
576
577*** TODO [[https://github.com/Kungsgeten/ryo-modal][ryo-modal]]
578
579#+begin_quote
580Roll your own modal mode
581#+end_quote
582
583*** [[https://github.com/ch11ng/exwm][EXWM]] (window manager)
584
585#+begin_src emacs-lisp :tangle no
586(use-package exwm
587 :demand t
588 :config
589 (require 'exwm-config)
590
591 ;; Set the initial workspace number.
592 (setq exwm-workspace-number 4)
593
594 ;; Make class name the buffer name, truncating beyond 50 characters
595 (defun exwm-rename-buffer ()
596 (interactive)
597 (exwm-workspace-rename-buffer
598 (concat exwm-class-name ":"
599 (if (<= (length exwm-title) 50) exwm-title
600 (concat (substring exwm-title 0 49) "...")))))
601 (add-hook 'exwm-update-class-hook 'exwm-rename-buffer)
602 (add-hook 'exwm-update-title-hook 'exwm-rename-buffer)
603
604 ;; 's-R': Reset
605 (exwm-input-set-key (kbd "s-R") #'exwm-reset)
606 ;; 's-\': Switch workspace
607 (exwm-input-set-key (kbd "s-\\") #'exwm-workspace-switch)
608 ;; 's-N': Switch to certain workspace
609 (dotimes (i 10)
610 (exwm-input-set-key (kbd (format "s-%d" i))
611 (lambda ()
612 (interactive)
613 (exwm-workspace-switch-create i))))
614 ;; 's-SPC': Launch application
615 ;; (exwm-input-set-key
616 ;; (kbd "s-SPC")
617 ;; (lambda (command)
618 ;; (interactive (list (read-shell-command "➜ ")))
619 ;; (start-process-shell-command command nil command)))
620
621 (exwm-input-set-key (kbd "M-s-SPC") #'counsel-linux-app)
622
623 ;; Shorten 'C-c C-q' to 'C-q'
624 (define-key exwm-mode-map [?\C-q] #'exwm-input-send-next-key)
625
626 ;; Line-editing shortcuts
627 (setq exwm-input-simulation-keys
628 '(;; movement
629 ([?\C-b] . [left])
630 ([?\M-b] . [C-left])
631 ([?\C-f] . [right])
632 ([?\M-f] . [C-right])
633 ([?\C-p] . [up])
634 ([?\C-n] . [down])
635 ([?\C-a] . [home])
636 ([?\C-e] . [end])
637 ([?\M-v] . [prior])
638 ([?\C-v] . [next])
639 ([?\C-d] . [delete])
640 ([?\C-k] . [S-end delete])
641 ;; cut/copy/paste
642 ;; ([?\C-w] . [?\C-x])
643 ([?\M-w] . [?\C-c])
644 ([?\C-y] . [?\C-v])
645 ;; search
646 ([?\C-s] . [?\C-f])))
647
648 ;; Enable EXWM
649 (exwm-enable)
650
651 (add-hook 'exwm-init-hook #'exwm-config--fix/ido-buffer-window-other-frame)
652
653 (require 'exwm-systemtray)
654 (exwm-systemtray-enable)
655
656 (require 'exwm-randr)
657 (exwm-randr-enable)
658
659 ;; (exwm-input-set-key
660 ;; (kbd "s-<return>")
661 ;; (lambda ()
662 ;; (interactive)
663 ;; (start-process "urxvt" nil "urxvt")))
664
665 ;; (exwm-input-set-key
666 ;; (kbd "s-SPC") ;; rofi doesn't properly launch programs when started from emacs
667 ;; (lambda ()
668 ;; (interactive)
669 ;; (start-process-shell-command "rofi-run" nil "rofi -show run -display-run '> ' -display-window ' 🗔 '")))
670
671 ;; (exwm-input-set-key
672 ;; (kbd "s-/")
673 ;; (lambda ()
674 ;; (interactive)
675 ;; (start-process-shell-command "rofi-win" nil "rofi -show window -display-run '> ' -display-window ' 🗔 '")))
676
677 ;; (exwm-input-set-key
678 ;; (kbd "M-SPC")
679 ;; (lambda ()
680 ;; (interactive)
681 ;; (start-process "rofi-pass" nil "rofi-pass")))
682
683 ;; (exwm-input-set-key
684 ;; (kbd "<XF86AudioMute>")
685 ;; (lambda ()
686 ;; (interactive)
687 ;; (start-process-shell-command "pamixer" nil "pamixer --toggle-mute")))
688
689 ;; (exwm-input-set-key
690 ;; (kbd "<XF86AudioLowerVolume>")
691 ;; (lambda ()
692 ;; (interactive)
693 ;; (start-process-shell-command "pamixer" nil "pamixer --allow-boost --decrease 5")))
694
695 ;; (exwm-input-set-key
696 ;; (kbd "<XF86AudioRaiseVolume>")
697 ;; (lambda ()
698 ;; (interactive)
699 ;; (start-process-shell-command "pamixer" nil "pamixer --allow-boost --increase 5")))
700
701 ;; (exwm-input-set-key
702 ;; (kbd "<XF86AudioPlay>")
703 ;; (lambda ()
704 ;; (interactive)
705 ;; (start-process-shell-command "mpc" nil "mpc toggle")))
706
707 ;; (exwm-input-set-key
708 ;; (kbd "<XF86AudioPrev>")
709 ;; (lambda ()
710 ;; (interactive)
711 ;; (start-process-shell-command "mpc" nil "mpc prev")))
712
713 ;; (exwm-input-set-key
714 ;; (kbd "<XF86AudioNext>")
715 ;; (lambda ()
716 ;; (interactive)
717 ;; (start-process-shell-command "mpc" nil "mpv next")))
718
719 (defun ab--exwm-pasystray ()
720 "A command used to start pasystray."
721 (interactive)
722 (if (executable-find "pasystray")
723 (progn
724 (message "EXWM: starting pasystray ...")
725 (start-process-shell-command "pasystray" nil "pasystray --notify=all"))
726 (message "EXWM: pasystray is not installed, abort!")))
727
728 (add-hook 'exwm-init-hook #'ab--exwm-pasystray)
729
730 (exwm-input-set-key
731 (kbd "s-t")
732 (lambda ()
733 (interactive)
734 (exwm-floating-toggle-floating)))
735
736 (exwm-input-set-key
737 (kbd "s-f")
738 (lambda ()
739 (interactive)
740 (exwm-layout-toggle-fullscreen)))
741
742 (exwm-input-set-key
743 (kbd "s-w")
744 (lambda ()
745 (interactive)
746 (kill-buffer (current-buffer))))
747
748 (exwm-input-set-key
749 (kbd "s-q")
750 (lambda ()
751 (interactive)
752 (exwm-manage--kill-client))))
753#+end_src
754
755**** sxhkdrc
756:PROPERTIES:
757:header-args+: :tangle ~/.config/sxhkd/sxhkdrc :mkdirp yes
758:END:
759
760#+begin_src conf :tangle no
761# terminal emulator
762super + Return
763 urxvt
764
765# program launcher
766super + space
767 rofi -show run -display-run '> ' -display-window ' 🗔 '
768
769# window finder
770super + slash
771 rofi -show window -display-run '> ' -display-window ' 🗔 '
772
773# password manager
774alt + space
775 rofi-pass
776
777# make sxhkd reload its configuration files:
778super + Escape
779 pkill -USR1 -x sxhkd
780
781# volume {up,down}
782XF86Audio{Raise,Lower}Volume
783 pamixer --allow-boost --{in,de}crease 5
784
785# mute
786XF86AudioMute
787 pamixer --toggle-mute
788
789# playback control
790XF86Audio{Play,Prev,Next}
791 mpc {toggle,prev,next}
792
793# Toggle keyboard layout
794# super + F7
795# toggle-layout
796
797# Toggle Xfce presentation mode
798# XF86LaunchB
799# toggle-presentation-mode
800
801# monitor brightness
802XF86MonBrightness{Up,Down}
803 light -{A,U} 5
804
805super + apostrophe
806 rofi-light
807#+end_src
808
809*** [[https://orgmode.org/][Org mode]]
810
811#+begin_quote
812Org mode is for keeping notes, maintaining TODO lists, planning
813projects, and authoring documents with a fast and effective plain-text
814system.
815#+end_quote
816
817In short, my favourite way of life.
818
819#+begin_src emacs-lisp
820(setq org-src-tab-acts-natively t
821 org-src-preserve-indentation nil
822 org-edit-src-content-indentation 0)
823#+end_src
824
825*** [[https://magit.vc/][Magit]]
826
827#+begin_quote
828It's Magit! A Git porcelain inside Emacs.
829#+end_quote
830
831Not just how I do git, but /the/ way to do git.
832
833#+begin_src emacs-lisp
834(use-package magit
835 :defer t
836 :bind (("s-g" . magit-status)
837 ("C-x g" . magit-status)
838 ("C-x M-g" . magit-dispatch-popup))
839 :config
840 (magit-add-section-hook 'magit-status-sections-hook
841 'magit-insert-modules
842 'magit-insert-stashes
843 'append))
844#+end_src
845
846*** [[https://github.com/abo-abo/swiper][Ivy]] (and friends)
847
848#+begin_quote
849Ivy - a generic completion frontend for Emacs, Swiper - isearch with
850an overview, and more. Oh, man!
851#+end_quote
852
853There's no way I could top that, so I won't attempt to.
854
855**** Ivy
856
857#+begin_src emacs-lisp
858(use-package ivy
859 :bind
860 (:map ivy-minibuffer-map
861 ([escape] . keyboard-escape-quit)
862 ;; ("C-j" . ivy-next-line)
863 ;; ("C-k" . ivy-previous-line)
864 ([S-up] . ivy-previous-history-element)
865 ([S-down] . ivy-next-history-element)
866 ("DEL" . ivy-backward-delete-char))
867 :config
868 (setq ivy-wrap t)
869 (ivy-mode 1))
870#+end_src
871
872**** Swiper
873
874#+begin_src emacs-lisp
875(use-package swiper
876 :bind (([remap isearch-forward] . swiper)
877 ([remap isearch-backward] . swiper)))
878#+end_src
879
880**** Counsel
881
882#+begin_src emacs-lisp
883(use-package counsel
884 :defer 1
885 :bind (([remap execute-extended-command] . counsel-M-x)
886 ([remap find-file] . counsel-find-file)
887 ("s-r" . counsel-recentf)
888 :map minibuffer-local-map
889 ("C-r" . counsel-minibuffer-history))
890 :config
891 (counsel-mode 1)
892 (defalias 'locate #'counsel-locate))
893#+end_src
894
895* Borg's =layer/essentials=
896
897TODO: break this giant source block down into individual org sections.
898
899#+begin_src emacs-lisp
900(use-package dash
901 :config (dash-enable-font-lock))
902
903(use-package diff-hl
904 :config
905 (setq diff-hl-draw-borders nil)
906 (global-diff-hl-mode)
907 (add-hook 'magit-post-refresh-hook 'diff-hl-magit-post-refresh t))
908
909(use-package dired
910 :defer t
911 :config (setq dired-listing-switches "-alh"))
912
913(use-package eldoc
914 :when (version< "25" emacs-version)
915 :config (global-eldoc-mode))
916
917(use-package help
918 :defer t
919 :config (temp-buffer-resize-mode))
920
921(progn ; `isearch'
922 (setq isearch-allow-scroll t))
923
924(use-package lisp-mode
925 :config
926 (add-hook 'emacs-lisp-mode-hook 'outline-minor-mode)
927 (add-hook 'emacs-lisp-mode-hook 'reveal-mode)
928 (defun indent-spaces-mode ()
929 (setq indent-tabs-mode nil))
930 (add-hook 'lisp-interaction-mode-hook #'indent-spaces-mode))
931
932(use-package man
933 :defer t
934 :config (setq Man-width 80))
935
936(use-package paren
937 :config (show-paren-mode))
938
939(use-package prog-mode
940 :config (global-prettify-symbols-mode)
941 (defun indicate-buffer-boundaries-left ()
942 (setq indicate-buffer-boundaries 'left))
943 (add-hook 'prog-mode-hook #'indicate-buffer-boundaries-left))
944
945(use-package recentf
946 :demand t
947 :config (add-to-list 'recentf-exclude "^/\\(?:ssh\\|su\\|sudo\\)?:"))
948
949(use-package savehist
950 :config (savehist-mode))
951
952(use-package saveplace
953 :when (version< "25" emacs-version)
954 :config (save-place-mode))
955
956(use-package simple
957 :config (column-number-mode))
958
959(progn ; `text-mode'
960 (add-hook 'text-mode-hook #'indicate-buffer-boundaries-left))
961
962(use-package tramp
963 :defer t
964 :config
965 (add-to-list 'tramp-default-proxies-alist '(nil "\\`root\\'" "/ssh:%h:"))
966 (add-to-list 'tramp-default-proxies-alist '("localhost" nil nil))
967 (add-to-list 'tramp-default-proxies-alist
968 (list (regexp-quote (system-name)) nil nil)))
969
970(use-package undo-tree
971 :config
972 (global-undo-tree-mode)
973 (setq undo-tree-mode-lighter ""))
974#+end_src
975
976* Editing
977
978** Company
979
980#+begin_src emacs-lisp
981(use-package company
982 :defer 5
983 :bind
984 (:map company-active-map
985 ([tab] . company-complete-common-or-cycle))
986 :custom
987 (company-idle-delay 0.3)
988 (company-minimum-prefix-length 1)
989 (company-selection-wrap-around t)
990 (company-dabbrev-char-regexp "\\sw\\|\\s_\\|[-_]")
991 :config
992 (global-company-mode t))
993#+end_src
994
995* Syntax and spell checking
996#+begin_src emacs-lisp
997(use-package flycheck
998 :hook (prog-mode . flycheck-mode)
999 :config
1000 ;; Use the load-path from running Emacs when checking elisp files
1001 (setq flycheck-emacs-lisp-load-path 'inherit)
1002
1003 ;; Only flycheck when I actually save the buffer
1004 (setq flycheck-check-syntax-automatically '(mode-enabled save)))
1005#+end_src
1006* Programming modes
1007
1008** [[https://github.com/leanprover/lean-mode][Lean]]
1009
1010#+begin_src emacs-lisp
1011(use-package lean-mode
1012 :bind (:map lean-mode-map
1013 ("S-SPC" . company-complete)))
1014#+end_src
1015
1016** Haskell
1017
1018*** [[https://github.com/haskell/haskell-mode][haskell-mode]]
1019
1020#+begin_src emacs-lisp
1021(use-package haskell-mode
1022 :config
1023 (setq haskell-indentation-layout-offset 4
1024 haskell-indentation-left-offset 4
1025 flycheck-checker 'haskell-hlint
1026 flycheck-disabled-checkers '(haskell-stack-ghc haskell-ghc)))
1027#+end_src
1028
1029*** [[https://github.com/jyp/dante][dante]]
1030
1031#+begin_src emacs-lisp
1032(use-package dante
1033 :after haskell-mode
1034 :commands dante-mode
1035 :hook (haskell-mode . dante-mode))
1036#+end_src
1037
1038*** [[https://github.com/mpickering/hlint-refactor-mode][hlint-refactor]]
1039
1040Emacs bindings for [[https://github.com/ndmitchell/hlint][hlint]]'s refactor option. This requires the refact
1041executable from [[https://github.com/mpickering/apply-refact][apply-refact]].
1042
1043#+begin_src emacs-lisp
1044(use-package hlint-refactor
1045 :bind (:map hlint-refactor-mode-map
1046 ("C-c l b" . hlint-refactor-refactor-buffer)
1047 ("C-c l r" . hlint-refactor-refactor-at-point))
1048 :hook (haskell-mode . hlint-refactor-mode))
1049#+end_src
1050
1051*** [[https://github.com/flycheck/flycheck-haskell][flycheck-haskell]]
1052
1053#+begin_src emacs-lisp
1054(use-package flycheck-haskell)
1055#+end_src
1056
1057*** [[https://github.com/ndmitchell/hlint/blob/20e116a043f2073c57b17b24ae6364b5e433ba7e/data/hs-lint.el][hs-lint.el]]
1058:PROPERTIES:
1059:header-args+: :tangle lisp/hs-lint.el :mkdirp yes
1060:END:
1061
1062Currently using =flycheck-haskell= with the =haskell-hlint= checker
1063instead.
1064
1065#+begin_src emacs-lisp :tangle no
1066;;; hs-lint.el --- minor mode for HLint code checking
1067
1068;; Copyright 2009 (C) Alex Ott
1069;;
1070;; Author: Alex Ott <alexott@gmail.com>
1071;; Keywords: haskell, lint, HLint
1072;; Requirements:
1073;; Status: distributed under terms of GPL2 or above
1074
1075;; Typical message from HLint looks like:
1076;;
1077;; /Users/ott/projects/lang-exp/haskell/test.hs:52:1: Eta reduce
1078;; Found:
1079;; count1 p l = length (filter p l)
1080;; Why not:
1081;; count1 p = length . filter p
1082
1083
1084(require 'compile)
1085
1086(defgroup hs-lint nil
1087 "Run HLint as inferior of Emacs, parse error messages."
1088 :group 'tools
1089 :group 'haskell)
1090
1091(defcustom hs-lint-command "hlint"
1092 "The default hs-lint command for \\[hlint]."
1093 :type 'string
1094 :group 'hs-lint)
1095
1096(defcustom hs-lint-save-files t
1097 "Save modified files when run HLint or no (ask user)"
1098 :type 'boolean
1099 :group 'hs-lint)
1100
1101(defcustom hs-lint-replace-with-suggestions nil
1102 "Replace user's code with suggested replacements"
1103 :type 'boolean
1104 :group 'hs-lint)
1105
1106(defcustom hs-lint-replace-without-ask nil
1107 "Replace user's code with suggested replacements automatically"
1108 :type 'boolean
1109 :group 'hs-lint)
1110
1111(defun hs-lint-process-setup ()
1112 "Setup compilation variables and buffer for `hlint'."
1113 (run-hooks 'hs-lint-setup-hook))
1114
1115;; regex for replace suggestions
1116;;
1117;; ^\(.*?\):\([0-9]+\):\([0-9]+\): .*
1118;; Found:
1119;; \s +\(.*\)
1120;; Why not:
1121;; \s +\(.*\)
1122
1123(defvar hs-lint-regex
1124 "^\\(.*?\\):\\([0-9]+\\):\\([0-9]+\\): .*[\n\C-m]Found:[\n\C-m]\\s +\\(.*\\)[\n\C-m]Why not:[\n\C-m]\\s +\\(.*\\)[\n\C-m]"
1125 "Regex for HLint messages")
1126
1127(defun make-short-string (str maxlen)
1128 (if (< (length str) maxlen)
1129 str
1130 (concat (substring str 0 (- maxlen 3)) "...")))
1131
1132(defun hs-lint-replace-suggestions ()
1133 "Perform actual replacement of suggestions"
1134 (goto-char (point-min))
1135 (while (re-search-forward hs-lint-regex nil t)
1136 (let* ((fname (match-string 1))
1137 (fline (string-to-number (match-string 2)))
1138 (old-code (match-string 4))
1139 (new-code (match-string 5))
1140 (msg (concat "Replace '" (make-short-string old-code 30)
1141 "' with '" (make-short-string new-code 30) "'"))
1142 (bline 0)
1143 (eline 0)
1144 (spos 0)
1145 (new-old-code ""))
1146 (save-excursion
1147 (switch-to-buffer (get-file-buffer fname))
1148 (goto-char (point-min))
1149 (forward-line (1- fline))
1150 (beginning-of-line)
1151 (setf bline (point))
1152 (when (or hs-lint-replace-without-ask
1153 (yes-or-no-p msg))
1154 (end-of-line)
1155 (setf eline (point))
1156 (beginning-of-line)
1157 (setf old-code (regexp-quote old-code))
1158 (while (string-match "\\\\ " old-code spos)
1159 (setf new-old-code (concat new-old-code
1160 (substring old-code spos (match-beginning 0))
1161 "\\ *"))
1162 (setf spos (match-end 0)))
1163 (setf new-old-code (concat new-old-code (substring old-code spos)))
1164 (remove-text-properties bline eline '(composition nil))
1165 (when (re-search-forward new-old-code eline t)
1166 (replace-match new-code nil t)))))))
1167
1168(defun hs-lint-finish-hook (buf msg)
1169 "Function, that is executed at the end of HLint execution"
1170 (if hs-lint-replace-with-suggestions
1171 (hs-lint-replace-suggestions)
1172 (next-error 1 t)))
1173
1174(define-compilation-mode hs-lint-mode "HLint"
1175 "Mode for check Haskell source code."
1176 (set (make-local-variable 'compilation-process-setup-function)
1177 'hs-lint-process-setup)
1178 (set (make-local-variable 'compilation-disable-input) t)
1179 (set (make-local-variable 'compilation-scroll-output) nil)
1180 (set (make-local-variable 'compilation-finish-functions)
1181 (list 'hs-lint-finish-hook))
1182 )
1183
1184(defun hs-lint ()
1185 "Run HLint for current buffer with haskell source"
1186 (interactive)
1187 (save-some-buffers hs-lint-save-files)
1188 (compilation-start (concat hs-lint-command " \"" buffer-file-name "\"")
1189 'hs-lint-mode))
1190
1191(provide 'hs-lint)
1192;;; hs-lint.el ends here
1193#+end_src
1194
1195#+begin_src emacs-lisp :tangle no
1196(use-package hs-lint
1197 :load-path "lisp/"
1198 :bind (:map haskell-mode-map
1199 ("C-c l l" . hs-lint)))
1200#+end_src
1201* Emacs Enhancements
1202
1203** [[https://github.com/justbur/emacs-which-key][which-key]]
1204
1205#+begin_quote
1206Emacs package that displays available keybindings in popup
1207#+end_quote
1208
1209#+begin_src emacs-lisp
1210(use-package which-key
1211 :defer 1
1212 :config (which-key-mode))
1213#+end_src
1214* Email
1215** notmuch
1216
1217#+begin_src emacs-lisp
1218(defun ab/notmuch ()
1219 "Delete other windows, then launch `notmuch'."
1220 (interactive)
1221 (require 'notmuch)
1222 (delete-other-windows)
1223 (notmuch))
1224
1225;; (map!
1226;; :leader
1227;; :desc "notmuch" :n "m" #'ab/notmuch
1228;; (:desc "search" :prefix "/"
1229;; :desc "notmuch" :n "m" #'counsel-notmuch))
1230#+end_src
1231
1232#+begin_src emacs-lisp
1233(defvar ab-maildir "~/mail")
1234
1235(use-package sendmail
1236 ;; :ensure nil
1237 :config
1238 (setq sendmail-program "/usr/bin/msmtp"
1239 mail-specify-envelope-from t
1240 mail-envelope-from 'header))
1241
1242(use-package message
1243 ;; :ensure nil
1244 :config
1245 (setq message-kill-buffer-on-exit t
1246 message-send-mail-function 'message-send-mail-with-sendmail
1247 message-sendmail-envelope-from 'header
1248 message-directory "drafts"
1249 message-user-fqdn "aminb.org")
1250 (add-hook 'message-mode-hook
1251 (lambda () (setq fill-column 65
1252 message-fill-column 65)))
1253 (add-hook 'message-mode-hook
1254 #'flyspell-mode)
1255 ;; (add-hook 'notmuch-message-mode-hook #'+doom-modeline|set-special-modeline)
1256 ;; TODO: is there a way to only run this when replying and not composing?
1257 (add-hook 'notmuch-message-mode-hook
1258 (lambda () (progn
1259 (newline)
1260 (newline)
1261 (forward-line -1)
1262 (forward-line -1))))
1263 ;; (add-hook 'message-setup-hook
1264 ;; #'mml-secure-message-sign-pgpmime)
1265 )
1266
1267(after! mml-sec
1268 (setq mml-secure-openpgp-encrypt-to-self t
1269 mml-secure-openpgp-sign-with-sender t))
1270
1271(use-package notmuch
1272 :config
1273 (setq notmuch-hello-sections
1274 '(notmuch-hello-insert-header
1275 notmuch-hello-insert-saved-searches
1276 ;; notmuch-hello-insert-search
1277 notmuch-hello-insert-alltags)
1278 notmuch-search-oldest-first nil
1279 notmuch-show-all-tags-list t
1280 notmuch-hello-thousands-separator ","
1281 notmuch-fcc-dirs
1282 '(("amin@aminb.org" . "amin/Sent")
1283 ("abandali@uwaterloo.ca" . "\"uwaterloo/Sent Items\"")
1284 ("amin.bandali@uwaterloo.ca" . "\"uwaterloo/Sent Items\"")
1285 ("aminb@gnu.org" . "gnu/Sent")
1286 (".*" . "sent")))
1287 ;; (add-hook 'visual-fill-column-mode-hook
1288 ;; (lambda ()
1289 ;; (when (string= major-mode 'notmuch-message-mode)
1290 ;; (setq visual-fill-column-width 70))))
1291 ;; (set! :evil-state 'notmuch-message-mode 'insert)
1292 ;; (advice-add #'notmuch-bury-or-kill-this-buffer
1293 ;; :override #'kill-this-buffer)
1294 :bind
1295 (:map notmuch-hello-mode-map
1296 ("g" . notmuch-poll-and-refresh-this-buffer)
1297 ("i" . (lambda ()
1298 "Search for `inbox' tagged messages"
1299 (interactive)
1300 (notmuch-hello-search "tag:inbox")))
1301 ("u" . (lambda ()
1302 "Search for `unread' tagged messages"
1303 (interactive)
1304 (notmuch-hello-search "tag:unread")))
1305 ("M" . (lambda ()
1306 "Compose new mail and prompt for sender"
1307 (interactive)
1308 (let ((current-prefix-arg t))
1309 (call-interactively #'notmuch-mua-new-mail)))))
1310 (:map notmuch-search-mode-map
1311 ("g" . notmuch-poll-and-refresh-this-buffer)
1312 ("k" . (lambda ()
1313 "Mark message read"
1314 (interactive)
1315 (notmuch-search-tag '("-unread"))
1316 ;; (notmuch-search-archive-thread)
1317 (notmuch-search-next-thread)))
1318 ("u" . (lambda ()
1319 "Mark message unread"
1320 (interactive)
1321 (notmuch-search-tag '("+unread"))
1322 (notmuch-search-next-thread)))
1323 ("K" . (lambda ()
1324 "Mark message deleted"
1325 (interactive)
1326 (notmuch-search-tag '("-unread" "-inbox" "+deleted"))
1327 (notmuch-search-archive-thread)))
1328 ("S" . (lambda ()
1329 "Mark message as spam"
1330 (interactive)
1331 (notmuch-search-tag '("-unread" "-inbox" "+spam"))
1332 (notmuch-search-archive-thread))))
1333 (:map notmuch-tree-mode-map ; TODO: additional bindings
1334 ("S" . (lambda ()
1335 "Mark message as spam"
1336 (interactive)
1337 (notmuch-tree-tag '("-unread" "-inbox" "+spam"))
1338 (notmuch-tree-archive-thread))))
1339)
1340
1341;; (use-package counsel-notmuch
1342;; :commands counsel-notmuch)
1343
1344(after! notmuch-crypto
1345 (setq notmuch-crypto-process-mime t))
1346
1347;; (after! evil
1348;; (mapc (lambda (str) (evil-set-initial-state (car str) (cdr str)))
1349;; '((notmuch-hello-mode . emacs)
1350;; (notmuch-search-mode . emacs)
1351;; (notmuch-tree-mode . emacs))))
1352
1353(after! recentf
1354 (add-to-list 'recentf-exclude (expand-file-name ab-maildir)))
1355#+end_src
1356
1357* Post initialization
1358:PROPERTIES:
1359:CUSTOM_ID: post-initialization
1360:END:
1361
1362Display how long it took to load the init file.
1363
1364#+begin_src emacs-lisp
1365(message "Loading %s...done (%.3fs)" user-init-file
1366 (float-time (time-subtract (current-time)
1367 ab--before-user-init-time)))
1368#+end_src
1369
1370* Footer
1371:PROPERTIES:
1372:CUSTOM_ID: footer
1373:END:
1374
1375#+begin_src emacs-lisp :comments none
1376;;; init.el ends here
1377#+end_src