1 #+title: =aminb='s Literate Emacs Configuration
4 #+property: header-args :tangle yes
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:
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
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]]
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.
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:
43 #+begin_src sh :tangle no
44 git clone https://github.com/aminb/dotfiles ~/.emacs.d
51 * Contents :toc_1:noexport:
55 - [[#initial-setup][Initial setup]]
57 - [[#post-initialization][Post initialization]]
67 #+begin_src emacs-lisp :comments none
68 ;;; init.el --- Amin Bandali's Emacs config -*- lexical-binding: t ; eval: (view-mode 1)-*-
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
78 #+begin_src emacs-lisp :comments none
79 ;; Copyright (C) 2018 Amin Bandali <bandali@gnu.org>
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.
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.
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/>.
97 #+begin_src emacs-lisp :comments none
100 ;; Emacs configuration of Amin Bandali, computer scientist and functional
103 ;; THIS FILE IS AUTO-GENERATED FROM `init.org'.
106 ** Naming conventions
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]].
110 #+begin_src emacs-lisp :comments none
111 ;; Naming conventions:
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
125 :CUSTOM_ID: initial-setup
128 #+begin_src emacs-lisp :comments none
132 ** Emacs initialization
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=:
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
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.
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)
162 Of course, we'd like to set them back to their defaults once we're
165 #+begin_src emacs-lisp
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)))
174 Increase the number of lines kept in message logs (the =*Messages*=
177 #+begin_src emacs-lisp
178 (setq message-log-max 20000)
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.
185 #+begin_src emacs-lisp
186 ;; (setq byte-compile-warnings
187 ;; '(not free-vars unresolved noruntime lexical make-local))
192 #+begin_src emacs-lisp
193 (setq user-full-name "Amin Bandali"
194 user-mail-address "amin@aminb.org")
197 ** Package management
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]]).
205 #+begin_src emacs-lisp :tangle early-init.el
206 (setq package-enable-at-startup nil)
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.
214 #+begin_src emacs-lisp
215 (setq package-enable-at-startup nil)
216 ;; (package-initialize)
222 Assimilate Emacs packages as Git submodules
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.
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))
237 ;; (require 'borg-nix-shell)
238 ;; (setq borg-build-shell-command 'borg-nix-shell-build-command)
240 (with-eval-after-load 'bind-key
243 ("C-c b A" . borg-activate)
244 ("C-c b a" . borg-assimilate)
245 ("C-c b b" . borg-build)
246 ("C-c b c" . borg-clone)
247 ("C-c b r" . borg-remove)))
253 A use-package declaration for simplifying your .emacs
256 [[https://github.com/jwiegley/use-package][use-package]] is an awesome utility for managing and configuring
257 packages (in our case especially the latter) in a neatly organized way
258 and without compromising on performance.
260 #+begin_src emacs-lisp
261 (require 'use-package)
262 (if nil ; set to t when need to debug init
263 (setq use-package-verbose t
264 use-package-expand-minimally nil
265 use-package-compute-statistics t
267 (setq use-package-verbose nil
268 use-package-expand-minimally t))
274 Browse the Emacsmirror package database
277 Epkg provides access to a local copy of the [[https://emacsmirror.net][Emacsmirror]] package
278 database, low-level functions for querying the database, and a
279 =package.el=-like user interface for browsing the available packages.
281 #+begin_src emacs-lisp
285 (("C-c b d" . epkg-describe-package)
286 ("C-c b p" . epkg-list-packages)
287 ("C-c b u" . epkg-update)))
290 ** No littering in =~/.emacs.d=
293 Help keeping ~/.emacs.d clean
296 By default, even for Emacs' built-in packages, the configuration files
297 and persistent data are all over the place. Use =no-littering= to help
300 #+begin_src emacs-lisp
301 (use-package no-littering
305 (add-to-list 'savehist-additional-variables 'kill-ring)
307 (setq auto-save-file-name-transforms
308 `((".*" ,(no-littering-expand-var-file-name "auto-save/") t))))
311 ** Custom file (=custom.el=)
313 I'm not planning on using the custom file much, but even so, I
314 definitely don't want it mixing with =init.el=. So, here; let's give
315 it it's own file. While at it, treat themes as safe.
317 #+begin_src emacs-lisp
321 (setq custom-file (no-littering-expand-etc-file-name "custom.el"))
322 (when (file-exists-p custom-file)
324 (setf custom-safe-themes t))
329 Load the secrets file if it exists, otherwise show a warning.
331 #+begin_src emacs-lisp
333 (load (no-littering-expand-etc-file-name "secrets")))
336 ** Better =$PATH= handling
338 Let's use [[https://github.com/purcell/exec-path-from-shell][exec-path-from-shell]] to make Emacs use the =$PATH= as set up
341 #+begin_src emacs-lisp
342 (use-package exec-path-from-shell
345 (setq exec-path-from-shell-check-startup-files nil)
347 (exec-path-from-shell-initialize)
348 ;; while we're at it, let's fix access to our running ssh-agent
349 (exec-path-from-shell-copy-env "SSH_AGENT_PID")
350 (exec-path-from-shell-copy-env "SSH_AUTH_SOCK"))
353 ** COMMENT Only one custom theme at a time
355 #+begin_src emacs-lisp
356 (defadvice load-theme (before clear-previous-themes activate)
357 "Clear existing theme settings instead of layering them"
358 (mapc #'disable-theme custom-enabled-themes))
363 Start server if not already running. Alternatively, can be done by
364 issuing =emacs --daemon= in the terminal, which can be automated with
365 a systemd service or using =brew services start emacs= on macOS. I use
366 Emacs as my window manager (via EXWM), so I always start Emacs on
367 login; so starting the server from inside Emacs is good enough for me.
369 See [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Server.html#Emacs-Server][Using Emacs as a Server]].
371 #+begin_src emacs-lisp
374 :config (or (server-running-p) (server-mode)))
377 ** COMMENT Unicode support
379 Font stack with better unicode support, around =Ubuntu Mono= and
382 #+begin_src emacs-lisp :tangle no
383 (dolist (ft (fontset-list))
387 (font-spec :name "Source Code Pro" :size 14))
391 (font-spec :name "DejaVu Sans Mono")
398 ;; :name "Symbola monospacified for DejaVu Sans Mono")
404 ;; (font-spec :name "DejaVu Sans Mono")
410 (font-spec :name "DejaVu Sans Mono" :size 14)
415 ** Gentler font resizing
417 #+begin_src emacs-lisp
418 (setq text-scale-mode-step 1.05)
421 ** Focus follows mouse
423 I’d like focus to follow the mouse when I move the cursor from one
426 #+begin_src emacs-lisp
427 (setq mouse-autoselect-window t)
430 Let’s define a function to conveniently disable this for certain
431 buffers and/or modes.
433 #+begin_src emacs-lisp
434 (defun amin--no-mouse-autoselect-window ()
435 (make-local-variable 'mouse-autoselect-window)
436 (setq mouse-autoselect-window nil))
441 #+begin_src emacs-lisp
448 #+begin_src emacs-lisp
449 (defun amin-enlist (exp)
450 "Return EXP wrapped in a list, or as-is if already a list."
451 (if (listp exp) exp (list exp)))
453 ; from https://github.com/hlissner/doom-emacs/commit/589108fdb270f24a98ba6209f6955fe41530b3ef
454 (defmacro after! (features &rest body)
455 "A smart wrapper around `with-eval-after-load'. Supresses warnings during
457 (declare (indent defun) (debug t))
458 (list (if (or (not (bound-and-true-p byte-compile-current-file))
459 (dolist (next (amin-enlist features))
461 (require next nil :no-error)
462 (load next :no-message :no-error))))
465 (cond ((symbolp features)
466 `(eval-after-load ',features '(progn ,@body)))
467 ((and (consp features)
468 (memq (car features) '(:or :any)))
470 ,@(cl-loop for next in (cdr features)
471 collect `(after! ,next ,@body))))
472 ((and (consp features)
473 (memq (car features) '(:and :all)))
474 (dolist (next (cdr features))
475 (setq body `(after! ,next ,@body)))
478 `(after! (:all ,@features) ,@body)))))
481 Convenience macro for =setq='ing multiple variables to the same value:
483 #+begin_src emacs-lisp
484 (defmacro setq-every! (value &rest vars)
485 "Set all the variables from VARS to value VALUE."
486 (declare (indent defun) (debug t))
487 `(progn ,@(mapcar (lambda (x) (list 'setq x value)) vars)))
497 *** Time and battery in mode-line
499 Enable displaying time and battery in the mode-line, since I'm not
500 using the Xfce panel anymore. Also, I don't need to see the load
501 average on a regular basis, so disable that.
503 Note: using =i3status= on sway at the moment, so disabling this.
505 #+begin_src emacs-lisp :tangle no
508 (setq display-time-default-load-average nil)
514 (display-battery-mode))
519 Might want to set the fringe to a smaller value, especially if using
520 EXWM. I'm fine with the default for now.
522 #+begin_src emacs-lisp
523 ;; (fringe-mode '(3 . 1))
527 *** Disable disabled commands
529 Emacs disables some commands by default that could persumably be
530 confusing for novice users. Let's disable that.
532 #+begin_src emacs-lisp
533 (setq disabled-command-function nil)
538 Save what I copy into clipboard from other applications into Emacs'
539 kill-ring, which would allow me to still be able to easily access it
540 in case I kill (cut or copy) something else inside Emacs before
541 yanking (pasting) what I'd originally intended to.
543 #+begin_src emacs-lisp
544 (setq save-interprogram-paste-before-kill t)
549 #+begin_src emacs-lisp
550 (setq enable-recursive-minibuffers t
551 resize-mini-windows t)
554 *** Lazy-person-friendly yes/no prompts
556 Lazy people would prefer to type fewer keystrokes, especially for yes
557 or no questions. I'm lazy.
559 #+begin_src emacs-lisp
560 (defalias 'yes-or-no-p #'y-or-n-p)
563 *** Startup screen and =*scratch*=
565 Firstly, let Emacs know that I'd like to have =*scratch*= as my
568 #+begin_src emacs-lisp
569 (setq initial-buffer-choice t)
572 Now let's customize the =*scratch*= buffer a bit. First off, I don't
573 need the default hint.
575 #+begin_src emacs-lisp
576 (setq initial-scratch-message nil)
579 Also, let's use Text mode as the major mode, in case I want to
580 customize it (=*scratch*='s default major mode, Fundamental mode,
581 can't really be customized).
583 #+begin_src emacs-lisp
584 (setq initial-major-mode 'text-mode)
587 Inhibit the buffer list when more than 2 files are loaded.
589 #+begin_src emacs-lisp
590 (setq inhibit-startup-buffer-menu t)
593 I don't really need to see the startup screen or echo area message
596 #+begin_src emacs-lisp
597 (advice-add #'display-startup-echo-area-message :override #'ignore)
598 (setq inhibit-startup-screen t
599 inhibit-startup-echo-area-message user-login-name)
602 *** More useful frame titles
604 Show either the file name or the buffer name (in case the buffer isn't
605 visiting a file). Borrowed from Emacs Prelude.
607 #+begin_src emacs-lisp
608 (setq frame-title-format
609 '("" invocation-name " - "
610 (:eval (if (buffer-file-name)
611 (abbreviate-file-name (buffer-file-name))
617 Emacs' default backup settings aren't that great. Let's use more
618 sensible options. See documentation for the ~make-backup-file~
621 #+begin_src emacs-lisp
622 (setq backup-by-copying t
624 delete-old-versions t)
629 Enable automatic reloading of changed buffers and files.
631 #+begin_src emacs-lisp
632 (global-auto-revert-mode 1)
633 (setq auto-revert-verbose nil
634 global-auto-revert-non-file-buffers nil)
637 *** Always use space for indentation
639 #+begin_src emacs-lisp
642 require-final-newline t
648 Enable =winner-mode=.
650 #+begin_src emacs-lisp
654 *** Close =*compilation*= on success
656 #+begin_src emacs-lisp
657 (setq compilation-exit-message-function
658 (lambda (status code msg)
659 "Close the compilation window if successful."
660 ;; if M-x compile exits with 0
661 (when (and (eq status 'exit) (zerop code))
663 (delete-window (get-buffer-window (get-buffer "*compilation*"))))
664 ;; return the result of compilation-exit-message-function
668 *** Search for non-ASCII characters
670 I’d like non-ASCII characters such as ‘’“”«»‹›áⓐ𝒶 to be selected when
671 I search for their ASCII counterpart. Shoutout to [[http://endlessparentheses.com/new-in-emacs-25-1-easily-search-non-ascii-characters.html][endlessparentheses]]
674 #+begin_src emacs-lisp
675 (setq search-default-mode #'char-fold-to-regexp)
677 ;; uncomment to extend this behaviour to query-replace
678 ;; (setq replace-char-fold t)
683 #+begin_src emacs-lisp
685 ("s-c e b" . eval-buffer)
686 ("s-c e r" . eval-region)
688 ("s-p" . beginning-of-buffer)
689 ("s-n" . end-of-buffer))
694 The packages in this section are absolutely essential to my everyday
695 workflow, and they play key roles in how I do my computing. They
696 immensely enhance the Emacs experience for me; both using Emacs, and
699 *** [[https://github.com/emacscollective/auto-compile][auto-compile]]
701 #+begin_src emacs-lisp
702 (use-package auto-compile
705 (auto-compile-on-load-mode)
706 (auto-compile-on-save-mode)
707 (setq auto-compile-display-buffer nil
708 auto-compile-mode-line-counter t
709 auto-compile-source-recreate-deletes-dest t
710 auto-compile-toggle-deletes-nonlib-dest t
711 auto-compile-update-autoloads t)
712 (add-hook 'auto-compile-inhibit-compile-hook
713 'auto-compile-inhibit-compile-detached-git-head))
716 *** [[https://github.com/noctuid/general.el][general]]
718 #+begin_src emacs-lisp
722 (general-evil-setup t)
723 (general-override-mode)
725 (general-create-definer
728 :states '(emacs normal visual motion insert)
729 :non-normal-prefix "M-m"
733 *** [[https://github.com/emacs-evil/evil][evil]]
735 #+begin_src emacs-lisp
738 ;; :hook (org-src-mode . evil-motion-state)
741 (general-swap-key nil '(normal motion) ";" ":")
743 (setq evil-want-visual-char-semi-exclusive t
746 ;; custom mode state mappings
747 (dolist (mspair '((ebdb-mode . emacs)
749 (helpful-mode . motion)
750 (magit-blame-mode . motion)
751 (view-mode . motion)))
752 (evil-set-initial-state (car mspair) (cdr mspair)))
754 ;; fix tab and indentation in src blocks inside org-mode buffer
755 ;; also see https://git.sr.ht/~bandali/dotfiles/commit/0e2ffd584aafdd4cf256bcdf2473f01c3aaaed55
756 (unbind-key "TAB" evil-motion-state-map)
758 (unbind-key "C-d" evil-insert-state-map)
759 (unbind-key "C-v" evil-insert-state-map)
760 (unbind-key "C-y" evil-insert-state-map)
761 (unbind-key "C-a" evil-insert-state-map)
762 (unbind-key "C-e" evil-insert-state-map)
763 (unbind-key "C-p" evil-insert-state-map)
764 (unbind-key "C-n" evil-insert-state-map)
765 (unbind-key "C-k" evil-insert-state-map)
767 :map evil-insert-state-map
769 ("C-S-k" . evil-insert-digraph)
770 :map evil-motion-state-map
771 ([down-mouse-1] . nil)))
774 #+begin_src emacs-lisp
775 (use-package evil-escape
778 (setq evil-escape-excluded-states '(normal visual multiedit emacs motion)
779 evil-escape-excluded-major-modes '(neotree-mode)
780 evil-escape-key-sequence "jk"
781 evil-escape-delay 0.25)
783 ;; (:states '(insert replace visual operator)
784 ;; "C-g" #'evil-escape)
787 ;; no `evil-escape' in minibuffer
788 (push #'minibufferp evil-escape-inhibit-functions))
791 #+begin_src emacs-lisp
792 (use-package evil-nerd-commenter
796 "gc" 'evilnc-comment-operator
797 "gy" 'evilnc-copy-and-comment-lines))
800 #+begin_src emacs-lisp
801 (use-package evil-surround
805 "s" 'evil-surround-edit
806 "S" 'evil-Surround-edit)
808 "S" 'evil-surround-region
809 "gS" 'evil-Surround-region))
812 #+begin_src emacs-lisp
814 "/" '(:ignore t :wk "search")
816 "a" '(:ignore t :wk "apps")
819 "a s" '(:ignore t :wk "shells/terms")
821 "b" '(:ignore t :wk "buffers")
822 "b k" 'kill-this-buffer
825 "e" '(:ignore t :wk "eval")
829 "f" '(:ignore t :wk "files")
831 "F" '(:ignore t :wk "frames")
832 "F m" 'make-frame-command
834 "F D" 'delete-other-frames
836 "h" '(:ignore t :wk "help(ful)")
838 "h f" 'describe-function
840 "h H" 'view-hello-file
844 "h v" 'describe-variable
848 "w" '(:ignore t :wk "window")
851 "w 1" 'delete-other-windows
852 "w 2" 'split-window-below
853 "w 3" 'split-window-right
857 "q" '(:ignore t :wk "quit")
858 "q q" 'save-buffers-kill-terminal)
861 *** [[https://orgmode.org/][Org mode]]
864 Org mode is for keeping notes, maintaining TODO lists, planning
865 projects, and authoring documents with a fast and effective plain-text
869 In short, my favourite way of life.
871 #+begin_src emacs-lisp
877 :keymaps 'org-mode-map
878 "'" 'org-edit-special)
882 :keymaps 'org-src-mode
883 "'" 'org-edit-src-exit
884 "k" 'org-edit-src-abort)
888 :keymaps 'org-src-mode
889 "q" 'org-edit-src-exit)
891 (setq org-src-tab-acts-natively t
892 org-src-preserve-indentation nil
893 org-edit-src-content-indentation 0
894 org-email-link-description-format "Email %c: %s" ; %.30s
895 org-highlight-latex-and-related '(entities)
897 (add-to-list 'org-structure-template-alist '("L" . "src emacs-lisp") t)
899 (define-key org-src-mode-map [remap evil-write] 'org-edit-src-save)
900 (define-key org-src-mode-map [remap evil-save-and-close]
901 (lambda () (interactive)
903 (org-edit-src-exit)))
904 (define-key org-src-mode-map [remap evil-save-modified-and-close]
905 (lambda () (interactive)
907 (org-edit-src-exit)))
908 (define-key org-src-mode-map [remap evil-quit] 'org-edit-src-abort))
909 (font-lock-add-keywords
911 '(("[ \t]*\\(#\\+\\(BEGIN\\|END\\|begin\\|end\\)_\\(\\S-+\\)\\)[ \t]*\\([^\n:]*\\)"
912 (1 '(:foreground "#5a5b5a" :background "#292b2b") t) ; directive
913 (3 '(:foreground "#81a2be" :background "#292b2b") t) ; kind
914 (4 '(:foreground "#c5c8c6") t))) ; title
916 :bind (:map org-mode-map ("M-L" . org-insert-last-stored-link))
917 :hook ((org-mode . org-indent-mode)
918 (org-mode . auto-fill-mode)
919 (org-mode . flyspell-mode))
921 (org-latex-packages-alist '(("" "listings") ("" "color")))
923 '(org-block-begin-line ((t (:foreground "#5a5b5a" :background "#1d1f21"))))
924 '(org-block ((t (:background "#1d1f21"))))
925 '(org-latex-and-related ((t (:foreground "#b294bb")))))
927 (use-package ox-latex
930 (setq org-latex-listings 'listings
931 ;; org-latex-prefer-user-labels t
933 (add-to-list 'org-latex-packages-alist '("" "listings"))
934 (add-to-list 'org-latex-packages-alist '("" "color"))
935 (add-to-list 'org-latex-classes
936 '("IEEEtran" "\\documentclass[11pt]{IEEEtran}"
937 ("\\section{%s}" . "\\section*{%s}")
938 ("\\subsection{%s}" . "\\subsection*{%s}")
939 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
940 ("\\paragraph{%s}" . "\\paragraph*{%s}")
941 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
944 (use-package ox-beamer
947 (use-package ob-tangle
951 :keymaps 'org-mode-map
952 "b t" 'org-babel-tangle))
954 (use-package orgalist
956 :hook (message-mode . orgalist-mode))
959 **** asynchronous tangle
961 =amin/async-babel-tangle= is a function closely inspired by [[https://github.com/dieggsy/dotfiles/tree/cc10edf7701958eff1cd94d4081da544d882a28c/emacs.d#dotfiles][dieggsy's
962 d/async-babel-tangle]] which uses [[https://github.com/jwiegley/emacs-async][async]] to asynchronously tangle an org
965 #+begin_src emacs-lisp
967 (defvar amin-show-async-tangle-results nil
968 "Keep *emacs* async buffers around for later inspection.")
970 (defvar amin-show-async-tangle-time nil
971 "Show the time spent tangling the file.")
973 (defvar amin-async-tangle-post-compile "make ti"
974 "If non-nil, pass to `compile' after successful tangle.")
976 (defun amin/async-babel-tangle ()
977 "Tangle org file asynchronously."
979 (let* ((file-tangle-start-time (current-time))
980 (file (buffer-file-name))
981 (file-nodir (file-name-nondirectory file))
982 (async-quiet-switch "-q"))
986 (org-babel-tangle-file ,file))
987 (unless amin-show-async-tangle-results
991 (message "Tangled %s%s"
993 (if amin-show-async-tangle-time
995 (float-time (time-subtract (current-time)
996 ',file-tangle-start-time)))
998 (when amin-async-tangle-post-compile
999 (compile amin-async-tangle-post-compile)))
1000 (message "Tangling %s failed" ,file-nodir))))))))
1003 'safe-local-variable-values
1004 '(eval add-hook 'after-save-hook #'amin/async-babel-tangle 'append 'local))
1007 *** [[https://magit.vc/][Magit]]
1010 It's Magit! A Git porcelain inside Emacs.
1013 Not just how I do git, but /the/ way to do git.
1015 #+begin_src emacs-lisp
1021 "g l" 'magit-log-buffer-file)
1022 :bind ("s-g" . magit-status)
1024 (magit-add-section-hook 'magit-status-sections-hook
1025 'magit-insert-modules
1026 'magit-insert-stashes
1029 magit-repository-directories '(("~/.emacs.d/" . 0)
1030 ("~/src/git/" . 1)))
1031 (nconc magit-section-initial-visibility-alist
1032 '(([unpulled status] . show)
1033 ([unpushed status] . show)))
1034 :custom-face (magit-diff-file-heading ((t (:weight normal)))))
1037 *** [[https://github.com/abo-abo/swiper][Ivy]] (and friends)
1040 Ivy - a generic completion frontend for Emacs, Swiper - isearch with
1041 an overview, and more. Oh, man!
1044 There's no way I could top that, so I won't attempt to.
1048 #+begin_src emacs-lisp
1051 :general (amin--leader-keys "," 'ivy-switch-buffer)
1053 (:map ivy-minibuffer-map
1054 ([escape] . keyboard-escape-quit)
1055 ([S-up] . ivy-previous-history-element)
1056 ([S-down] . ivy-next-history-element)
1057 ("DEL" . ivy-backward-delete-char))
1062 ;; (ivy-minibuffer-match-face-2 ((t (:background "#e99ce8" :weight semi-bold))))
1063 ;; (ivy-minibuffer-match-face-3 ((t (:background "#bbbbff" :weight semi-bold))))
1064 ;; (ivy-minibuffer-match-face-4 ((t (:background "#ffbbff" :weight semi-bold))))
1070 #+begin_src emacs-lisp
1072 :general (:states '(normal motion) "/" 'swiper)
1073 :bind (("C-s" . swiper)
1079 #+begin_src emacs-lisp
1080 (use-package counsel
1084 "r" 'counsel-recentf
1086 "." 'counsel-find-file)
1087 :bind (([remap execute-extended-command] . counsel-M-x)
1088 ([remap find-file] . counsel-find-file)
1089 ("s-r" . counsel-recentf)
1090 ("C-c x" . counsel-M-x)
1091 ("C-c f ." . counsel-find-file)
1092 :map minibuffer-local-map
1093 ("C-r" . counsel-minibuffer-history))
1096 (defalias 'locate #'counsel-locate))
1101 #+begin_src emacs-lisp
1106 (eval-when-compile (defvar eshell-prompt-regexp))
1107 (defun amin/eshell-quit-or-delete-char (arg)
1109 (if (and (eolp) (looking-back eshell-prompt-regexp nil))
1110 (eshell-life-is-too-much)
1113 (defun amin/eshell-clear ()
1115 (let ((inhibit-read-only t))
1117 (eshell-send-input))
1119 (defun amin|eshell-setup ()
1120 (make-local-variable 'company-idle-delay)
1121 (setq company-idle-delay nil)
1122 (bind-keys :map eshell-mode-map
1123 ("C-d" . amin/eshell-quit-or-delete-char)
1124 ("C-S-l" . amin/eshell-clear)
1125 ("M-r" . counsel-esh-history)
1126 ([tab] . company-complete)))
1128 :hook (eshell-mode . amin|eshell-setup)
1130 (eshell-hist-ignoredups t)
1131 (eshell-input-filter 'eshell-input-filter-initial-space))
1136 #+begin_src emacs-lisp
1137 (use-package ibuffer
1139 :general (amin--leader-keys "b b" 'ibuffer-other-window)
1141 (("C-x C-b" . ibuffer-other-window)
1142 :map ibuffer-mode-map
1143 ("P" . ibuffer-backward-filter-group)
1144 ("N" . ibuffer-forward-filter-group)
1145 ("M-p" . ibuffer-do-print)
1146 ("M-n" . ibuffer-do-shell-command-pipe-replace))
1148 ;; Use human readable Size column instead of original one
1149 (define-ibuffer-column size-h
1150 (:name "Size" :inline t)
1152 ((> (buffer-size) 1000000) (format "%7.1fM" (/ (buffer-size) 1000000.0)))
1153 ((> (buffer-size) 100000) (format "%7.0fk" (/ (buffer-size) 1000.0)))
1154 ((> (buffer-size) 1000) (format "%7.1fk" (/ (buffer-size) 1000.0)))
1155 (t (format "%8d" (buffer-size)))))
1157 (ibuffer-saved-filter-groups
1159 ("dired" (mode . dired-mode))
1160 ("org" (mode . org-mode))
1169 (mode . eshell-mode)
1170 (mode . shell-mode)))
1171 ("notmuch" (name . "\*notmuch\*"))
1174 (mode . python-mode)
1176 (mode . emacs-lisp-mode)))
1179 (name . "^\\*scratch\\*$")
1180 (name . "^\\*Messages\\*$")))
1183 (name . "^\\*Slack*"))))))
1185 '((mark modified read-only locked " "
1186 (name 18 18 :left :elide)
1188 (size-h 9 -1 :right)
1190 (mode 16 16 :left :elide)
1191 " " filename-and-process)
1195 :hook (ibuffer . (lambda () (ibuffer-switch-to-saved-filter-groups "default"))))
1200 #+begin_src emacs-lisp
1201 (use-package outline
1203 :hook (prog-mode . outline-minor-mode)
1206 outline-minor-mode-map
1207 ("<s-tab>" . outline-toggle-children)
1208 ("M-p" . outline-previous-visible-heading)
1209 ("M-n" . outline-next-visible-heading)
1210 :prefix-map amin--outline-prefix-map
1212 ("TAB" . outline-toggle-children)
1213 ("a" . outline-hide-body)
1214 ("H" . outline-hide-body)
1215 ("S" . outline-show-all)
1216 ("h" . outline-hide-subtree)
1217 ("s" . outline-show-subtree)))
1220 * Borg's =layer/essentials=
1222 TODO: break this giant source block down into individual org sections.
1224 #+begin_src emacs-lisp
1226 :config (dash-enable-font-lock))
1228 (use-package diff-hl
1230 (setq diff-hl-draw-borders nil)
1231 (global-diff-hl-mode)
1232 (add-hook 'magit-post-refresh-hook 'diff-hl-magit-post-refresh t))
1236 :config (setq dired-listing-switches "-alh"))
1239 :when (version< "25" emacs-version)
1240 :config (global-eldoc-mode))
1245 (temp-buffer-resize-mode)
1246 (setq help-window-select t))
1249 (setq isearch-allow-scroll t))
1251 (use-package lisp-mode
1253 (add-hook 'emacs-lisp-mode-hook 'outline-minor-mode)
1254 (add-hook 'emacs-lisp-mode-hook 'reveal-mode)
1255 (defun indent-spaces-mode ()
1256 (setq indent-tabs-mode nil))
1257 (add-hook 'lisp-interaction-mode-hook #'indent-spaces-mode))
1261 :config (setq Man-width 80))
1264 :config (show-paren-mode))
1266 (use-package prog-mode
1267 :config (global-prettify-symbols-mode)
1268 (defun indicate-buffer-boundaries-left ()
1269 (setq indicate-buffer-boundaries 'left))
1270 (add-hook 'prog-mode-hook #'indicate-buffer-boundaries-left))
1272 (use-package recentf
1275 (add-to-list 'recentf-exclude "^/\\(?:ssh\\|su\\|sudo\\)?:")
1276 (setq recentf-max-saved-items 40))
1278 (use-package savehist
1279 :config (savehist-mode))
1281 (use-package saveplace
1282 :when (version< "25" emacs-version)
1283 :config (save-place-mode))
1286 :config (column-number-mode))
1288 (progn ; `text-mode'
1289 (add-hook 'text-mode-hook #'indicate-buffer-boundaries-left)
1290 (add-hook 'text-mode-hook #'abbrev-mode))
1295 (add-to-list 'tramp-default-proxies-alist '(nil "\\`root\\'" "/ssh:%h:"))
1296 (add-to-list 'tramp-default-proxies-alist '("localhost" nil nil))
1297 (add-to-list 'tramp-default-proxies-alist
1298 (list (regexp-quote (system-name)) nil nil)))
1300 (use-package undo-tree
1302 (global-undo-tree-mode -1))
1303 ;; :bind (("C-?" . undo-tree-undo)
1304 ;; ("M-_" . undo-tree-redo))
1306 ;; (global-undo-tree-mode)
1307 ;; (setq undo-tree-mode-lighter ""
1308 ;; undo-tree-auto-save-history t))
1315 #+begin_src emacs-lisp
1316 (use-package company
1319 (:map company-active-map
1320 ([tab] . company-complete-common-or-cycle)
1321 ([escape] . company-abort))
1323 (company-minimum-prefix-length 1)
1324 (company-selection-wrap-around t)
1325 (company-dabbrev-char-regexp "\\sw\\|\\s_\\|[-_]")
1326 (company-dabbrev-downcase nil)
1327 (company-dabbrev-ignore-case nil)
1329 (global-company-mode t))
1332 * Syntax and spell checking
1333 #+begin_src emacs-lisp
1334 (use-package flycheck
1336 :hook (prog-mode . flycheck-mode)
1338 (:map flycheck-mode-map
1339 ("M-P" . flycheck-previous-error)
1340 ("M-N" . flycheck-next-error))
1342 ;; Use the load-path from running Emacs when checking elisp files
1343 (setq flycheck-emacs-lisp-load-path 'inherit)
1345 ;; Only flycheck when I actually save the buffer
1346 (setq flycheck-check-syntax-automatically '(mode-enabled save)))
1348 ;; http://endlessparentheses.com/ispell-and-apostrophes.html
1352 ;; ’ can be part of a word
1353 (setq ispell-local-dictionary-alist
1354 `((nil "[[:alpha:]]" "[^[:alpha:]]"
1355 "['\x2019]" nil ("-B") nil utf-8)))
1356 ;; don't send ’ to the subprocess
1357 (defun endless/replace-apostrophe (args)
1358 (cons (replace-regexp-in-string
1361 (advice-add #'ispell-send-string :filter-args
1362 #'endless/replace-apostrophe)
1364 ;; convert ' back to ’ from the subprocess
1365 (defun endless/replace-quote (args)
1366 (if (not (derived-mode-p 'org-mode))
1368 (cons (replace-regexp-in-string
1371 (advice-add #'ispell-parse-output :filter-args
1372 #'endless/replace-quote))
1376 ** [[http://alloytools.org][Alloy]] (with [[https://github.com/dwwmmn/alloy-mode][alloy-mode]])
1378 #+begin_src emacs-lisp
1379 (use-package alloy-mode
1381 :config (setq alloy-basic-offset 2))
1384 ** [[https://coq.inria.fr][Coq]] (with [[https://github.com/ProofGeneral/PG][Proof General]])
1386 #+begin_src emacs-lisp
1387 (use-package proof-site ; Proof General
1389 :load-path "lib/proof-site/generic/")
1392 ** [[https://leanprover.github.io][Lean]] (with [[https://github.com/leanprover/lean-mode][lean-mode]])
1394 #+begin_src emacs-lisp
1395 (eval-when-compile (defvar lean-mode-map))
1396 (use-package lean-mode
1398 :bind (:map lean-mode-map
1399 ("S-SPC" . company-complete))
1401 (require 'lean-input)
1402 (setq default-input-method "Lean"
1403 lean-input-tweak-all '(lean-input-compose
1404 (lean-input-prepend "/")
1405 (lean-input-nonempty))
1406 lean-input-user-translations '(("/" "/")))
1412 *** [[https://github.com/haskell/haskell-mode][haskell-mode]]
1414 #+begin_src emacs-lisp
1415 (use-package haskell-mode
1418 (setq haskell-indentation-layout-offset 4
1419 haskell-indentation-left-offset 4
1420 flycheck-checker 'haskell-hlint
1421 flycheck-disabled-checkers '(haskell-stack-ghc haskell-ghc)))
1424 *** [[https://github.com/jyp/dante][dante]]
1426 #+begin_src emacs-lisp
1429 :commands dante-mode
1430 :hook (haskell-mode . dante-mode))
1433 *** [[https://github.com/mpickering/hlint-refactor-mode][hlint-refactor]]
1435 Emacs bindings for [[https://github.com/ndmitchell/hlint][hlint]]'s refactor option. This requires the refact
1436 executable from [[https://github.com/mpickering/apply-refact][apply-refact]].
1438 #+begin_src emacs-lisp
1439 (use-package hlint-refactor
1441 :bind (:map hlint-refactor-mode-map
1442 ("C-c l b" . hlint-refactor-refactor-buffer)
1443 ("C-c l r" . hlint-refactor-refactor-at-point))
1444 :hook (haskell-mode . hlint-refactor-mode))
1447 *** [[https://github.com/flycheck/flycheck-haskell][flycheck-haskell]]
1449 #+begin_src emacs-lisp
1450 (use-package flycheck-haskell
1451 :after haskell-mode)
1454 *** [[https://github.com/ndmitchell/hlint/blob/20e116a043f2073c57b17b24ae6364b5e433ba7e/data/hs-lint.el][hs-lint.el]]
1456 :header-args+: :tangle lisp/hs-lint.el :mkdirp yes
1459 Currently using =flycheck-haskell= with the =haskell-hlint= checker
1462 #+begin_src emacs-lisp :tangle no
1463 ;;; hs-lint.el --- minor mode for HLint code checking
1465 ;; Copyright 2009 (C) Alex Ott
1467 ;; Author: Alex Ott <alexott@gmail.com>
1468 ;; Keywords: haskell, lint, HLint
1470 ;; Status: distributed under terms of GPL2 or above
1472 ;; Typical message from HLint looks like:
1474 ;; /Users/ott/projects/lang-exp/haskell/test.hs:52:1: Eta reduce
1476 ;; count1 p l = length (filter p l)
1478 ;; count1 p = length . filter p
1483 (defgroup hs-lint nil
1484 "Run HLint as inferior of Emacs, parse error messages."
1488 (defcustom hs-lint-command "hlint"
1489 "The default hs-lint command for \\[hlint]."
1493 (defcustom hs-lint-save-files t
1494 "Save modified files when run HLint or no (ask user)"
1498 (defcustom hs-lint-replace-with-suggestions nil
1499 "Replace user's code with suggested replacements"
1503 (defcustom hs-lint-replace-without-ask nil
1504 "Replace user's code with suggested replacements automatically"
1508 (defun hs-lint-process-setup ()
1509 "Setup compilation variables and buffer for `hlint'."
1510 (run-hooks 'hs-lint-setup-hook))
1512 ;; regex for replace suggestions
1514 ;; ^\(.*?\):\([0-9]+\):\([0-9]+\): .*
1520 (defvar hs-lint-regex
1521 "^\\(.*?\\):\\([0-9]+\\):\\([0-9]+\\): .*[\n\C-m]Found:[\n\C-m]\\s +\\(.*\\)[\n\C-m]Why not:[\n\C-m]\\s +\\(.*\\)[\n\C-m]"
1522 "Regex for HLint messages")
1524 (defun make-short-string (str maxlen)
1525 (if (< (length str) maxlen)
1527 (concat (substring str 0 (- maxlen 3)) "...")))
1529 (defun hs-lint-replace-suggestions ()
1530 "Perform actual replacement of suggestions"
1531 (goto-char (point-min))
1532 (while (re-search-forward hs-lint-regex nil t)
1533 (let* ((fname (match-string 1))
1534 (fline (string-to-number (match-string 2)))
1535 (old-code (match-string 4))
1536 (new-code (match-string 5))
1537 (msg (concat "Replace '" (make-short-string old-code 30)
1538 "' with '" (make-short-string new-code 30) "'"))
1544 (switch-to-buffer (get-file-buffer fname))
1545 (goto-char (point-min))
1546 (forward-line (1- fline))
1548 (setf bline (point))
1549 (when (or hs-lint-replace-without-ask
1552 (setf eline (point))
1554 (setf old-code (regexp-quote old-code))
1555 (while (string-match "\\\\ " old-code spos)
1556 (setf new-old-code (concat new-old-code
1557 (substring old-code spos (match-beginning 0))
1559 (setf spos (match-end 0)))
1560 (setf new-old-code (concat new-old-code (substring old-code spos)))
1561 (remove-text-properties bline eline '(composition nil))
1562 (when (re-search-forward new-old-code eline t)
1563 (replace-match new-code nil t)))))))
1565 (defun hs-lint-finish-hook (buf msg)
1566 "Function, that is executed at the end of HLint execution"
1567 (if hs-lint-replace-with-suggestions
1568 (hs-lint-replace-suggestions)
1571 (define-compilation-mode hs-lint-mode "HLint"
1572 "Mode for check Haskell source code."
1573 (set (make-local-variable 'compilation-process-setup-function)
1574 'hs-lint-process-setup)
1575 (set (make-local-variable 'compilation-disable-input) t)
1576 (set (make-local-variable 'compilation-scroll-output) nil)
1577 (set (make-local-variable 'compilation-finish-functions)
1578 (list 'hs-lint-finish-hook))
1582 "Run HLint for current buffer with haskell source"
1584 (save-some-buffers hs-lint-save-files)
1585 (compilation-start (concat hs-lint-command " \"" buffer-file-name "\"")
1589 ;;; hs-lint.el ends here
1592 #+begin_src emacs-lisp :tangle no
1593 (use-package hs-lint
1595 :bind (:map haskell-mode-map
1596 ("C-c l l" . hs-lint)))
1603 #+begin_src emacs-lisp
1604 (use-package sgml-mode
1607 (setq sgml-basic-offset 2))
1612 #+begin_src emacs-lisp
1613 (use-package css-mode
1616 (setq css-indent-offset 2))
1621 #+begin_src emacs-lisp
1622 (use-package web-mode
1627 web-mode-code-indent-offset
1628 web-mode-css-indent-offset
1629 web-mode-markup-indent-offset))
1634 #+begin_src emacs-lisp
1635 (use-package emmet-mode
1636 :after (:any web-mode css-mode sgml-mode)
1637 :bind* (("C-)" . emmet-next-edit-point)
1638 ("C-(" . emmet-prev-edit-point))
1640 (unbind-key "C-j" emmet-mode-keymap)
1641 (setq emmet-move-cursor-between-quotes t)
1642 :hook (web-mode css-mode html-mode sgml-mode))
1647 #+begin_src emacs-lisp
1648 (use-package nix-mode
1657 #+begin_src emacs-lisp :tangle no
1658 (use-package meghanada
1660 (:map meghanada-mode-map
1661 (("C-M-o" . meghanada-optimize-import)
1662 ("C-M-t" . meghanada-import-all)))
1663 :hook (java-mode . meghanada-mode))
1684 #+begin_src emacs-lisp :tangle no
1685 (use-package treemacs
1686 :config (setq treemacs-never-persist t))
1688 (use-package yasnippet
1690 ;; (yas-global-mode)
1693 (use-package lsp-mode
1694 :init (setq lsp-eldoc-render-all nil
1695 lsp-highlight-symbol-at-point nil)
1700 (use-package company-lsp
1703 (setq company-lsp-cache-candidates t
1704 company-lsp-async t))
1708 (setq lsp-ui-sideline-update-mode 'point))
1710 (use-package lsp-java
1712 (add-hook 'java-mode-hook
1714 (setq-local company-backends (list 'company-lsp))))
1716 (add-hook 'java-mode-hook 'lsp-java-enable)
1717 (add-hook 'java-mode-hook 'flycheck-mode)
1718 (add-hook 'java-mode-hook 'company-mode)
1719 (add-hook 'java-mode-hook 'lsp-ui-mode))
1721 (use-package dap-mode
1727 (use-package dap-java
1730 (use-package lsp-java-treemacs
1734 * Emacs Enhancements
1736 ** [[https://github.com/justbur/emacs-which-key][which-key]]
1739 Emacs package that displays available keybindings in popup
1742 #+begin_src emacs-lisp
1743 (use-package which-key
1745 :config (which-key-mode))
1750 #+begin_src emacs-lisp
1751 (add-to-list 'custom-theme-load-path "~/.emacs.d/lisp")
1752 (load-theme 'tangomod t)
1757 #+begin_src emacs-lisp
1758 (use-package doom-modeline
1760 :config (setq doom-modeline-height 32)
1761 :hook (after-init . doom-modeline-init))
1766 #+begin_src emacs-lisp
1767 (use-package doom-themes)
1770 ** theme helper functions
1772 #+begin_src emacs-lisp
1773 (defun amin/lights-on ()
1774 "Enable my favourite light theme."
1777 (mapc #'disable-theme custom-enabled-themes)
1778 (load-theme 'tangomod t)))
1780 (defun amin/lights-off ()
1784 (mapc #'disable-theme custom-enabled-themes)
1785 (load-theme 'doom-tomorrow-night t)))
1788 "t" '(:ignore t :wk "theme")
1789 "t d" 'amin/lights-off
1790 "t l" 'amin/lights-on)
1793 ** [[https://github.com/bbatsov/crux][crux]]
1795 #+begin_src emacs-lisp
1800 "b K" 'crux-kill-other-buffers
1801 "c d" 'crux-duplicate-current-line-or-region
1802 "c D" 'crux-duplicate-and-comment-current-line-or-region
1803 "f c" 'crux-copy-file-preserve-attributes
1804 "f d" 'crux-delete-file-and-buffer
1805 "f r" 'crux-rename-file-and-buffer)
1806 :bind (("C-c d" . crux-duplicate-current-line-or-region)
1807 ("C-c D" . crux-duplicate-and-comment-current-line-or-region)
1808 ("C-S-j" . crux-top-join-line)
1809 ("C-c j" . crux-top-join-line)))
1812 ** [[https://github.com/alezost/mwim.el][mwim]]
1814 #+begin_src emacs-lisp
1817 (:states '(normal visual)
1818 "0" 'mwim-beginning-of-code-or-line
1819 "$" 'mwim-end-of-code-or-line)
1820 :bind (("C-a" . mwim-beginning-of-code-or-line)
1821 ("C-e" . mwim-end-of-code-or-line)
1822 ("<home>" . mwim-beginning-of-line-or-code)
1823 ("<end>" . mwim-end-of-line-or-code)))
1828 #+begin_src emacs-lisp
1829 (use-package projectile
1831 :bind-keymap ("C-c p" . projectile-command-map)
1835 (defun my-projectile-invalidate-cache (&rest _args)
1836 ;; ignore the args to `magit-checkout'
1837 (projectile-invalidate-cache nil))
1839 (eval-after-load 'magit-branch
1841 (advice-add 'magit-checkout
1842 :after #'my-projectile-invalidate-cache)
1843 (advice-add 'magit-branch-and-checkout
1844 :after #'my-projectile-invalidate-cache))))
1847 ** [[https://github.com/Wilfred/helpful][helpful]]
1849 #+begin_src emacs-lisp
1850 (use-package helpful
1854 "h h" '(:ignore t :wk "helpful")
1855 "h h c" 'helpful-command
1856 "h h f" 'helpful-callable ; helpful-function
1857 "h h v" 'helpful-variable
1858 "h h k" 'helpful-key
1859 "h h p" 'helpful-at-point))
1862 ** [[https://github.com/knu/shell-toggle.el][shell-toggle]]
1864 #+begin_src emacs-lisp
1865 (use-package shell-toggle
1867 :general (amin--leader-keys "a s e" 'amin/shell-toggle)
1868 :bind ("C-c e" . amin/shell-toggle)
1870 (defun amin/shell-toggle (make-cd)
1871 "Toggle between the shell buffer and whatever buffer you are editing.
1872 With a prefix argument MAKE-CD also insert a \"cd DIR\" command
1873 into the shell, where DIR is the directory of the current buffer.
1875 When called in the shell buffer returns you to the buffer you were editing
1876 before calling this the first time.
1878 Options: `shell-toggle-goto-eob'"
1880 ;; Try to decide on one of three possibilities:
1881 ;; If not in shell-buffer, switch to it.
1882 ;; If in shell-buffer, return to state before going to the shell-buffer
1883 (if (eq (current-buffer) shell-toggle-shell-buffer)
1884 (shell-toggle-buffer-return-from-shell)
1886 (shell-toggle-buffer-goto-shell make-cd)
1887 (if shell-toggle-full-screen-window-only (delete-other-windows)))))
1889 ;; override to split horizontally instead
1890 (defun shell-toggle-buffer-switch-to-other-window ()
1891 "Switch to other window.
1892 If the current window is the only window in the current frame,
1893 create a new window and switch to it.
1895 \(This is less intrusive to the current window configuration than
1896 `switch-buffer-other-window')"
1897 (let ((this-window (selected-window)))
1899 ;; If we did not switch window then we only have one window and need to
1900 ;; create a new one.
1901 (if (eq this-window (selected-window))
1903 (split-window-horizontally)
1904 (other-window 1)))))
1907 (shell-toggle-launch-shell 'shell-toggle-eshell))
1910 ** [[https://github.com/EricCrosson/unkillable-scratch][unkillable-scratch]]
1912 Make =*scratch*= and =*Messages*= unkillable.
1914 #+begin_src emacs-lisp
1915 (use-package unkillable-scratch
1918 (unkillable-scratch 1)
1920 (unkillable-scratch-behavior 'do-nothing)
1921 (unkillable-buffers '("^\\*scratch\\*$" "^\\*Messages\\*$")))
1924 ** [[https://github.com/davep/boxquote.el][boxquote.el]]
1928 | make pretty boxed quotes like this
1932 #+begin_src emacs-lisp
1933 (use-package boxquote
1936 (:prefix-map amin--boxquote-prefix-map
1938 ("b" . boxquote-buffer)
1939 ("B" . boxquote-insert-buffer)
1940 ("d" . boxquote-defun)
1941 ("F" . boxquote-insert-file)
1942 ("hf" . boxquote-describe-function)
1943 ("hk" . boxquote-describe-key)
1944 ("hv" . boxquote-describe-variable)
1945 ("hw" . boxquote-where-is)
1946 ("k" . boxquote-kill)
1947 ("p" . boxquote-paragraph)
1948 ("q" . boxquote-boxquote)
1949 ("r" . boxquote-region)
1950 ("s" . boxquote-shell-command)
1951 ("t" . boxquote-text)
1952 ("T" . boxquote-title)
1953 ("u" . boxquote-unbox)
1954 ("U" . boxquote-unbox-region)
1955 ("y" . boxquote-yank)
1956 ("M-q" . boxquote-fill-paragraph)
1957 ("M-w" . boxquote-kill-ring-save)))
1960 Also see [[https://www.emacswiki.org/emacs/rebox2][rebox2]].
1962 ** COMMENT [[https://github.com/DarthFennec/highlight-indent-guides][highlight-indent-guides]] :ARCHIVE:
1964 #+begin_src emacs-lisp
1965 (use-package highlight-indent-guides
1967 :hook ((prog-mode . highlight-indent-guides-mode)
1968 ;; (org-mode . highlight-indent-guides-mode)
1971 (setq highlight-indent-guides-character ?\|)
1972 (setq highlight-indent-guides-auto-enabled nil)
1973 (setq highlight-indent-guides-method 'character)
1974 (setq highlight-indent-guides-responsive 'top)
1975 (set-face-foreground 'highlight-indent-guides-character-face "gainsboro")
1976 (set-face-foreground 'highlight-indent-guides-top-character-face "grey40")) ; grey13 is nice too
1981 #+begin_src emacs-lisp
1982 (use-package pdf-tools
1984 :magic ("%PDF" . pdf-view-mode)
1986 (setq pdf-view-resize-factor 1.05)
1989 (:map pdf-view-mode-map
1990 ("C-s" . isearch-forward)
1991 ("C-r" . isearch-backward)
1992 ("j" . pdf-view-next-line-or-next-page)
1993 ("k" . pdf-view-previous-line-or-previous-page)
1994 ("h" . image-backward-hscroll)
1995 ("l" . image-forward-hscroll)))
2000 #+begin_src emacs-lisp
2006 #+begin_src emacs-lisp
2010 (typo-global-mode 1)
2011 :hook (text-mode . typo-mode))
2016 #+begin_src emacs-lisp
2017 (use-package hl-todo
2020 (global-hl-todo-mode))
2025 #+begin_src emacs-lisp
2026 (use-package shrink-path
2029 (setq eshell-prompt-regexp "\\(.*\n\\)*λ "
2030 eshell-prompt-function #'+eshell/prompt)
2032 (defun +eshell/prompt ()
2033 (let ((base/dir (shrink-path-prompt default-directory)))
2034 (concat (propertize (car base/dir)
2035 'face 'font-lock-comment-face)
2036 (propertize (cdr base/dir)
2037 'face 'font-lock-constant-face)
2038 (propertize (+eshell--current-git-branch)
2039 'face 'font-lock-function-name-face)
2041 (propertize "λ" 'face 'eshell-prompt-face)
2042 ;; needed for the input text to not have prompt face
2043 (propertize " " 'face 'default))))
2045 (defun +eshell--current-git-branch ()
2046 (let ((branch (car (loop for match in (split-string (shell-command-to-string "git branch") "\n")
2047 when (string-match "^\*" match)
2049 (if (not (eq branch nil))
2050 (concat " " (substring branch 2))
2054 ** COMMENT slack :ARCHIVE:
2056 Hopefully temporary.
2058 #+begin_src emacs-lisp
2060 :commands (slack-start)
2062 (eval-when-compile ; silence the byte-compiler
2063 (defvar url-http-data nil)
2064 (defvar url-http-extra-headers nil)
2065 (defvar url-http-method nil)
2066 (defvar url-callback-function nil)
2067 (defvar url-callback-arguments nil)
2068 (defvar oauth--token-data nil))
2069 (setq slack-buffer-emojify t
2070 slack-prefer-current-team t)
2072 (slack-register-team
2075 :client-id uw-apv-client-id
2076 :client-secret uw-apv-client-secret
2078 :subscribed-channels '(general)
2079 :full-and-display-names t)
2080 (slack-register-team
2083 :client-id watform-client-id
2084 :client-secret watform-client-secret
2085 :token watform-token
2086 :subscribed-channels '(general)
2087 :full-and-display-names t)
2088 (add-to-list 'swiper-font-lock-exclude 'slack-message-buffer-mode t)
2089 (setq lui-time-stamp-format "[%Y-%m-%d %H:%M:%S]"
2090 lui-time-stamp-only-when-changed-p t
2091 lui-time-stamp-position 'right)
2093 (("C-c s s" . slack-start)
2094 ("C-c s u" . slack-select-unread-rooms)
2095 ("C-c s b" . slack-select-rooms)
2096 ("C-c s t" . slack-change-current-team)
2097 ("C-c s c" . slack-ws-close)
2099 ("M-p" . slack-buffer-goto-prev-message)
2100 ("M-n" . slack-buffer-goto-next-message)
2101 ("C-c e" . slack-message-edit)
2102 ("C-c k" . slack-message-delete)
2103 ("C-c C-k" . slack-channel-leave)
2104 ("C-c r a" . slack-message-add-reaction)
2105 ("C-c r r" . slack-message-remove-reaction)
2106 ("C-c r s" . slack-message-show-reaction-users)
2107 ("C-c p l" . slack-room-pins-list)
2108 ("C-c p a" . slack-message-pins-add)
2109 ("C-c p r" . slack-message-pins-remove)
2110 ("@" . slack-message-embed-mention)
2111 ("#" . slack-message-embed-channel)))
2116 (setq alert-default-style 'notifier))
2119 ** COMMENT magithub :ARCHIVE:
2121 For when I /have to/ use GH.
2123 #+begin_src emacs-lisp
2124 (use-package magithub
2127 (magithub-feature-autoinject t)
2128 (setq magithub-clone-default-directory "~/src/git"))
2131 ** [[https://github.com/peterwvj/eshell-up][eshell-up]]
2133 #+begin_src emacs-lisp
2134 (use-package eshell-up
2140 #+begin_src emacs-lisp
2141 (use-package multi-term
2143 :general (amin--leader-keys
2145 "a s p" 'multi-term-dedicated-toggle)
2146 :bind ("C-c C-j" . term-line-mode)
2148 (setq multi-term-program "/bin/screen"
2149 ;; TODO: add separate bindings for connecting to existing
2150 ;; session vs. always creating a new one
2151 multi-term-dedicated-select-after-open-p t
2152 multi-term-dedicated-window-height 20
2153 multi-term-dedicated-max-window-height 30
2155 '(("C-c C-c" . term-interrupt-subjob)
2156 ("C-c C-e" . term-send-esc)
2158 ("C-y" . term-paste)
2159 ("M-f" . term-send-forward-word)
2160 ("M-b" . term-send-backward-word)
2161 ("M-p" . term-send-up)
2162 ("M-n" . term-send-down)
2163 ("<C-backspace>" . term-send-backward-kill-word)
2164 ("<M-DEL>" . term-send-backward-kill-word)
2165 ("M-d" . term-send-delete-word)
2166 ("M-," . term-send-raw)
2167 ("M-." . comint-dynamic-complete))
2168 term-unbind-key-alist
2169 '("C-z" "C-x" "C-c" "C-h" "C-y" "<ESC>")))
2174 #+begin_src emacs-lisp
2175 (defvar amin-maildir (expand-file-name "~/mail/"))
2177 (add-to-list 'recentf-exclude amin-maildir))
2182 #+begin_src emacs-lisp
2184 amin-gnus-init-file (no-littering-expand-etc-file-name "gnus")
2185 mail-user-agent 'gnus-user-agent
2186 read-mail-command 'gnus)
2192 "M" 'gnus-unplugged)
2193 :bind (("s-m" . gnus)
2194 ("s-M" . gnus-unplugged))
2197 gnus-select-method '(nnnil "")
2198 gnus-secondary-select-methods
2200 (nnimap-stream plain)
2201 (nnimap-address "127.0.0.1")
2202 (nnimap-server-port 143)
2203 (nnimap-authenticator plain)
2204 (nnimap-user "amin@aminb.org"))
2206 (nnimap-stream plain)
2207 (nnimap-address "127.0.0.1")
2208 (nnimap-server-port 143)
2209 (nnimap-authenticator plain)
2210 (nnimap-user "abandali@uwaterloo.ca")))
2211 gnus-message-archive-group "nnimap+amin:Sent"
2215 gnus-large-newsgroup 50
2216 gnus-home-directory (no-littering-expand-var-file-name "gnus/")
2217 gnus-directory (concat gnus-home-directory "news/")
2218 message-directory (concat gnus-home-directory "mail/")
2219 nndraft-directory (concat gnus-home-directory "drafts/")
2220 gnus-save-newsrc-file nil
2221 gnus-read-newsrc-file nil
2222 gnus-interactive-exit nil
2223 gnus-gcc-mark-as-read t))
2225 (use-package gnus-art
2228 gnus-visible-headers
2229 (concat gnus-visible-headers "\\|^List-Id:\\|^X-RT-Originator:\\|^User-Agent:")
2230 gnus-sorted-header-list
2231 '("^From:" "^Subject:" "^Summary:" "^Keywords:"
2232 "^Followup-To:" "^To:" "^Cc:" "X-RT-Originator"
2233 "^Newsgroups:" "List-Id:" "^Organization:"
2234 "^User-Agent:" "^Date:")
2235 ;; local-lapsed article dates
2236 ;; from https://www.emacswiki.org/emacs/GnusFormatting#toc11
2237 gnus-article-date-headers '(user-defined)
2238 gnus-article-time-format
2240 (let* ((date (format-time-string "%a, %d %b %Y %T %z" time))
2241 (local (article-make-date-line date 'local))
2242 (combined-lapsed (article-make-date-line date
2245 (string-match " (.+" combined-lapsed)
2246 (match-string 0 combined-lapsed))))
2247 (concat local lapsed))))
2249 :map gnus-article-mode-map
2250 ("r" . gnus-article-reply-with-original)
2251 ("R" . gnus-article-wide-reply-with-original)
2252 ("M-L" . org-store-link)))
2254 (use-package gnus-sum
2255 :bind (:map gnus-summary-mode-map
2256 :prefix-map amin--gnus-summary-prefix-map
2258 ("r" . gnus-summary-reply)
2259 ("w" . gnus-summary-wide-reply)
2260 ("v" . gnus-summary-show-raw-article))
2263 :map gnus-summary-mode-map
2264 ("r" . gnus-summary-reply-with-original)
2265 ("R" . gnus-summary-wide-reply-with-original)
2266 ("M-L" . org-store-link))
2267 :hook (gnus-summary-mode . amin--no-mouse-autoselect-window))
2269 (use-package gnus-msg
2271 (setq gnus-posting-styles
2273 (address "amin@aminb.org")
2274 (body "\nBest,\namin\n")
2275 (eval (setq amin--message-cite-say-hi t)))
2277 (address "bandali@gnu.org"))
2278 ((header "subject" "ThankCRM")
2279 (to "webmasters-comment@gnu.org")
2280 (body "\nAdded to 2018supporters.html.\n\nMoving to campaigns.\n\n-amin\n")
2281 (eval (setq amin--message-cite-say-hi nil)))
2282 ("nnimap\\+uwaterloo:.*"
2283 (address "abandali@uwaterloo.ca")
2284 (gcc "\"nnimap+uwaterloo:Sent Items\"")))))
2286 (use-package gnus-topic
2287 :hook (gnus-group-mode . gnus-topic-mode))
2289 (use-package gnus-agent
2291 (setq gnus-agent-synchronize-flags 'ask)
2292 :hook (gnus-group-mode . gnus-agent-mode))
2294 (use-package gnus-group
2296 (setq gnus-permanently-visible-groups "\\((INBOX\\|gnu$\\)"))
2298 (use-package mm-decode
2300 (setq mm-discouraged-alternatives '("text/html" "text/richtext")))
2305 #+begin_src emacs-lisp
2306 (use-package sendmail
2308 (setq sendmail-program "/usr/bin/msmtp"
2309 ;; message-sendmail-extra-arguments '("-v" "-d")
2310 mail-specify-envelope-from t
2311 mail-envelope-from 'header))
2316 #+begin_src emacs-lisp
2317 (use-package message
2319 (defconst amin--message-cite-style-format "On %Y-%m-%d %l:%M %p, %N wrote:")
2320 (defconst message-cite-style-bandali
2321 '((message-cite-function 'message-cite-original)
2322 (message-citation-line-function 'message-insert-formatted-citation-line)
2323 (message-cite-reply-position 'traditional)
2324 (message-yank-prefix "> ")
2325 (message-yank-cited-prefix ">")
2326 (message-yank-empty-prefix ">")
2327 (message-citation-line-format
2328 (if amin--message-cite-say-hi
2329 (concat "Hi %F,\n\n" amin--message-cite-style-format)
2330 amin--message-cite-style-format)))
2331 "Citation style based on Mozilla Thunderbird's. Use with message-cite-style.")
2332 (setq message-cite-style 'message-cite-style-bandali
2333 message-kill-buffer-on-exit t
2334 message-send-mail-function 'message-send-mail-with-sendmail
2335 message-sendmail-envelope-from 'header
2336 message-dont-reply-to-names
2337 "\\(\\(.*@aminb\\.org\\)\\|\\(amin@bandali\\.me\\)\\|\\(\\(aminb?\\|mab\\|bandali\\)@gnu\\.org\\)\\|\\(\\(m\\|a\\(min\\.\\)?\\)bandali@uwaterloo\\.ca\\)\\)"
2338 message-user-fqdn "aminb.org")
2339 :hook (;; (message-setup . mml-secure-message-sign-pgpmime)
2340 (message-mode . flyspell-mode)
2341 (message-mode . (lambda ()
2342 ;; (setq fill-column 65
2343 ;; message-fill-column 65)
2344 (make-local-variable 'company-idle-delay)
2345 (setq company-idle-delay 0.2))))
2347 ;; (message-header-subject ((t (:foreground "#111" :weight semi-bold))))
2348 ;; (message-header-to ((t (:foreground "#111" :weight normal))))
2349 ;; (message-header-cc ((t (:foreground "#333" :weight normal))))
2353 (setq mml-secure-openpgp-encrypt-to-self t
2354 mml-secure-openpgp-sign-with-sender t))
2359 Convenient footnotes in =message-mode=.
2361 #+begin_src emacs-lisp
2362 (use-package footnote
2365 (:map message-mode-map
2366 :prefix-map amin--footnote-prefix-map
2368 ("a" . footnote-add-footnote)
2369 ("b" . footnote-back-to-message)
2370 ("c" . footnote-cycle-style)
2371 ("d" . footnote-delete-footnote)
2372 ("g" . footnote-goto-footnote)
2373 ("r" . footnote-renumber-footnotes)
2374 ("s" . footnote-set-style))
2376 (setq footnote-start-tag ""
2378 footnote-style 'unicode))
2383 Manually install bbdb (=lisp/bbdb= copied from an ELPA-based setup),
2384 because installing it from source on Emacs 27 using the following
2385 submodule configuration for some reason doesn’t work and results in
2386 very strange errors when using any of the functions.
2388 #+begin_src conf :tangle no
2391 url = https://git.savannah.nongnu.org/git/bbdb.git
2394 build-step = ./autogen.sh
2395 build-step = ./configure
2397 build-step = make install
2400 I tried using =borg-elpa= instead of doing it like this, but it added
2401 2 seconds to my startup time, which is unacceptable to me.
2403 #+begin_src emacs-lisp
2405 :load-path "lisp/bbdb"
2407 (load (expand-file-name "lisp/bbdb/bbdb-autoloads.el" user-emacs-directory))
2408 ;; (bbdb-mua-auto-update-init 'message)
2409 (setq bbdb-mua-auto-update-p 'query
2410 bbdb-complete-mail nil)
2411 (bbdb-initialize 'gnus 'message))
2414 ** COMMENT message-x
2416 #+begin_src emacs-lisp
2417 (use-package message-x
2419 (message-x-completion-alist
2421 (("\\([rR]esent-\\|[rR]eply-\\)?[tT]o:\\|[bB]?[cC][cC]:" . gnus-harvest-find-address)
2424 (quote message-newgroups-header-regexp))
2425 message-newgroups-header-regexp message-newsgroups-header-regexp)
2426 . message-expand-group)))))
2429 ** COMMENT gnus-harvest
2431 #+begin_src emacs-lisp
2432 (use-package gnus-harvest
2433 :commands gnus-harvest-install
2436 (if (featurep 'message-x)
2437 (gnus-harvest-install 'message-x)
2438 (gnus-harvest-install)))
2442 ** [[https://ox-hugo.scripter.co][ox-hugo]]
2444 #+begin_src emacs-lisp
2445 (use-package ox-hugo
2448 (use-package ox-hugo-auto-export
2449 :load-path "lib/ox-hugo")
2452 * Post initialization
2454 :CUSTOM_ID: post-initialization
2457 Display how long it took to load the init file.
2459 #+begin_src emacs-lisp
2460 (message "Loading %s...done (%.3fs)" user-init-file
2461 (float-time (time-subtract (current-time)
2462 amin--before-user-init-time)))
2470 #+begin_src emacs-lisp :comments none
2471 ;;; init.el ends here
2474 * COMMENT Local Variables :ARCHIVE:
2476 # eval: (add-hook 'after-save-hook #'amin/async-babel-tangle 'append 'local)