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/raxod502/straight.el][straight.el]]. Over the years, I've taken inspiration from
14 configurations of many different people. Some of the configurations
15 that I can remember 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 =straight.el=. I also used Borg for a
32 few months, but decided to try =straight.el= which allows direct use
33 of the various package archives.
37 To use this config for your Emacs, first you need to clone this repo,
38 then tangle =init.org= into =init.el=, and optionally byte-compile
41 First, clone the repository and =cd= into it:
43 #+begin_src sh :tangle no
44 git clone https://git.sr.ht/~bandali/dotfiles ~/.emacs.d
48 Then, decide if you would like to use a byte-compiled init file, and
49 set the following variable accordingly:
51 #+begin_src emacs-lisp
52 (defvar a/byte-compiled-init t
53 "If non-nil, byte-(re)compile init.el on successful tangles.")
56 Now, first tangle =init.org=, and only if you chose to have a
57 byte-compiled init, build init as well:
59 #+begin_src sh :tangle no
64 If you'd like to use a byte-compiled init, it's important that it be
65 recompiled whenever =init.el= is generated from an updated =init.org=.
66 Not only does my setup automatically and asynchronously tangle
67 =init.org= to =init.el= every time you edit and save =init.org= in GNU
68 Emacs, it will also invoke =make build-init= if you set
69 =a/byte-compiled-init= to =t= above, so you wouldn't have to worry
70 about manually tangling and compiling your init file whenever you
71 change it. Results of byte-compilation are kept in a =*compilation*=
72 buffer, which will be automatically displayed when compilation fails.
74 * Contents :toc_1:noexport:
78 - [[#initial-setup][Initial setup]]
80 - [[#borg-essentials][Borg's =layer/essentials=]]
81 - [[#editing][Editing]]
82 - [[#syntax-spell-checking][Syntax and spell checking]]
83 - [[#programming-modes][Programming modes]]
84 - [[#emacs-enhancements][Emacs enhancements]]
86 - [[#blogging][Blogging]]
87 - [[#post-initialization][Post initialization]]
97 #+begin_src emacs-lisp :comments none
98 ;;; init.el --- Amin Bandali's Emacs config -*- lexical-binding: t; eval: (view-mode 1) -*-
101 Enable =view-mode=, which both makes the file read-only (as a reminder
102 that =init.el= is an auto-generated file, not supposed to be edited),
103 and provides some convenient key bindings for browsing through the
108 #+begin_src emacs-lisp :comments none
109 ;; Copyright (C) 2018 Amin Bandali <bandali@gnu.org>
111 ;; This program is free software: you can redistribute it and/or modify
112 ;; it under the terms of the GNU General Public License as published by
113 ;; the Free Software Foundation, either version 3 of the License, or
114 ;; (at your option) any later version.
116 ;; This program is distributed in the hope that it will be useful,
117 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
118 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
119 ;; GNU General Public License for more details.
121 ;; You should have received a copy of the GNU General Public License
122 ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
127 #+begin_src emacs-lisp :comments none
130 ;; Emacs configuration of Amin Bandali, computer scientist, functional
131 ;; programmer, and free software advocate.
133 ;; THIS FILE IS AUTO-GENERATED FROM `init.org'.
138 :CUSTOM_ID: initial-setup
141 ** Emacs initialization
143 I'd like to do a couple of measurements of Emacs' startup time. First,
144 let's see how long Emacs takes to start up, before even loading
145 =init.el=, i.e. =user-init-file=:
147 #+begin_src emacs-lisp
148 (defvar a/before-user-init-time (current-time)
149 "Value of `current-time' when Emacs begins loading `user-init-file'.")
150 (message "Loading Emacs...done (%.3fs)"
151 (float-time (time-subtract a/before-user-init-time
155 Also, temporarily increase ~gc-cons-threshhold~ and
156 ~gc-cons-percentage~ during startup to reduce garbage collection
157 frequency. Clearing the ~file-name-handler-alist~ seems to help reduce
158 startup time as well.
160 #+begin_src emacs-lisp
161 (defvar a/gc-cons-threshold gc-cons-threshold)
162 (defvar a/gc-cons-percentage gc-cons-percentage)
163 (defvar a/file-name-handler-alist file-name-handler-alist)
164 (setq gc-cons-threshold (* 400 1024 1024) ; 400 MiB
165 gc-cons-percentage 0.6
166 file-name-handler-alist nil
167 ;; sidesteps a bug when profiling with esup
168 esup-child-profile-require-level 0)
171 Of course, we'd like to set them back to their defaults once we're
174 #+begin_src emacs-lisp
178 (setq gc-cons-threshold a/gc-cons-threshold
179 gc-cons-percentage a/gc-cons-percentage
180 file-name-handler-alist a/file-name-handler-alist)))
183 Increase the number of lines kept in message logs (the =*Messages*=
186 #+begin_src emacs-lisp
187 (setq message-log-max 20000)
190 Optionally, we could suppress some byte compiler warnings like below,
191 but for now I've decided to keep them enabled. See documentation for
192 ~byte-compile-warnings~ for more details.
194 #+begin_src emacs-lisp
195 ;; (setq byte-compile-warnings
196 ;; '(not free-vars unresolved noruntime lexical make-local))
201 #+begin_src emacs-lisp
202 (setq user-full-name "Amin Bandali"
203 user-mail-address "amin@aminb.org")
206 ** Package management
210 I can do all my package management things with =straight.el=, and
211 don't need Emacs' built-in =package.el=. Emacs 27 lets us disable
212 =package.el= in the =early-init-file= (see [[https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=24acb31c04b4048b85311d794e600ecd7ce60d3b][here]]).
214 #+begin_src emacs-lisp :tangle early-init.el
215 (setq package-enable-at-startup nil)
218 But since Emacs 27 isn't out yet (Emacs 26 is just around the corner
219 right now), and even when released it'll be long before most distros
220 ship in their repos, I'll still put the old workaround with the
221 commented call to ~package-initialize~ here anyway.
223 #+begin_src emacs-lisp :tangle no
224 (setq package-enable-at-startup nil)
225 ;; (package-initialize)
228 Update: the above is not necessary, since =straight.el= automatically
229 does that (and more). See =straight-package-neutering-mode=.
234 Next-generation, purely functional package manager for the Emacs
238 =straight.el= allows me to have a fully reproducible Emacs setup.
240 #+begin_src emacs-lisp
241 ;; Main engine start...
243 (setq straight-repository-branch "develop"
244 straight-check-for-modifications '(check-on-save find-when-checking))
246 (defun a/bootstrap-straight ()
247 (defvar bootstrap-version)
248 (let ((bootstrap-file
249 (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
250 (bootstrap-version 5))
251 (unless (file-exists-p bootstrap-file)
253 (url-retrieve-synchronously
254 "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
255 'silent 'inhibit-cookies)
256 (goto-char (point-max))
257 (eval-print-last-sexp)))
258 (load bootstrap-file nil 'nomessage)))
260 ;; Solid rocket booster ignition...
262 (defun a/build-init ()
263 (a/bootstrap-straight)
264 (byte-compile-file "init.el"))
266 (a/bootstrap-straight)
270 (setq straight-use-package-by-default t)
273 Since we enable =straight.el='s =straight-use-package-by-default=
274 integration, we will define a =use-feature= for plain ole
275 =use-package= without any of the =straight.el= stuff.
277 #+begin_src emacs-lisp
278 (defmacro use-feature (name &rest args)
279 "Like `use-package', but with `straight-use-package-by-default' disabled."
280 (declare (indent defun))
289 A use-package declaration for simplifying your .emacs
292 [[https://github.com/jwiegley/use-package][use-package]] is an awesome utility for managing and configuring
293 packages (in our case especially the latter) in a neatly organized way
294 and without compromising on performance.
296 #+begin_src emacs-lisp
297 (straight-use-package 'use-package)
298 (if nil ; set to t when need to debug init
300 (setq use-package-verbose t
301 use-package-expand-minimally nil
302 use-package-compute-statistics t
304 (require 'use-package))
305 (setq use-package-verbose nil
306 use-package-expand-minimally t))
308 (setq use-package-always-defer t)
314 Browse the Emacsmirror package database
317 Epkg provides access to a local copy of the [[https://emacsmirror.net][Emacsmirror]] package
318 database, low-level functions for querying the database, and a
319 =package.el=-like user interface for browsing the available packages.
321 #+begin_src emacs-lisp
324 :commands (epkg-list-packages epkg-describe-package)
326 (("C-c P e d" . epkg-describe-package)
327 ("C-c P e p" . epkg-list-packages))
329 (setq epkg-repository "~/.emacs.d/straight/repos/epkgs/")
330 (eval-when-compile (defvar ivy-initial-inputs-alist))
331 (with-eval-after-load 'ivy
333 'ivy-initial-inputs-alist '(epkg-describe-package . "^") t)))
336 ** No littering in =~/.emacs.d=
339 Help keeping ~/.emacs.d clean
342 By default, even for Emacs' built-in packages, the configuration files
343 and persistent data are all over the place. Use =no-littering= to help
346 #+begin_src emacs-lisp
347 (use-package no-littering
351 (add-to-list 'savehist-additional-variables 'kill-ring)
353 (setq auto-save-file-name-transforms
354 `((".*" ,(no-littering-expand-var-file-name "auto-save/") t))))
357 ** Custom file (=custom.el=)
359 I'm not planning on using the custom file much, but even so, I
360 definitely don't want it mixing with =init.el=. So, here; let's give
361 it it's own file. While at it, treat themes as safe.
363 #+begin_src emacs-lisp
367 (setq custom-file (no-littering-expand-etc-file-name "custom.el"))
368 (when (file-exists-p custom-file)
370 (setf custom-safe-themes t))
375 Load the secrets file if it exists, otherwise show a warning.
377 #+begin_src emacs-lisp
379 (load (no-littering-expand-etc-file-name "secrets")))
382 ** Better =$PATH= handling
384 Let's use [[https://github.com/purcell/exec-path-from-shell][exec-path-from-shell]] to make Emacs use the =$PATH= as set up
387 #+begin_src emacs-lisp
388 (use-package exec-path-from-shell
391 (setq exec-path-from-shell-arguments nil
392 exec-path-from-shell-check-startup-files nil)
394 (exec-path-from-shell-initialize)
395 ;; while we're at it, let's fix access to our running ssh-agent
396 (exec-path-from-shell-copy-env "SSH_AGENT_PID")
397 (exec-path-from-shell-copy-env "SSH_AUTH_SOCK"))
400 ** COMMENT Only one custom theme at a time
402 #+begin_src emacs-lisp
403 (defadvice load-theme (before clear-previous-themes activate)
404 "Clear existing theme settings instead of layering them"
405 (mapc #'disable-theme custom-enabled-themes))
410 Start server if not already running. Alternatively, can be done by
411 issuing =emacs --daemon= in the terminal, which can be automated with
412 a systemd service or using =brew services start emacs= on macOS. I use
413 Emacs as my window manager (via EXWM), so I always start Emacs on
414 login; so starting the server from inside Emacs is good enough for me.
416 See [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Server.html#Emacs-Server][Using Emacs as a Server]].
418 #+begin_src emacs-lisp
421 :config (or (server-running-p) (server-mode)))
424 ** COMMENT Unicode support
426 Font stack with better unicode support, around =Ubuntu Mono= and
429 #+begin_src emacs-lisp
430 (dolist (ft (fontset-list))
434 (font-spec :name "Source Code Pro" :size 14))
438 (font-spec :name "DejaVu Sans Mono")
445 ;; :name "Symbola monospacified for DejaVu Sans Mono")
451 ;; (font-spec :name "DejaVu Sans Mono")
457 (font-spec :name "DejaVu Sans Mono" :size 14)
462 ** Gentler font resizing
464 #+begin_src emacs-lisp
465 (setq text-scale-mode-step 1.05)
468 ** Focus follows mouse
470 I’d like focus to follow the mouse when I move the cursor from one
473 #+begin_src emacs-lisp
474 (setq mouse-autoselect-window t)
477 Let’s define a function to conveniently disable this for certain
478 buffers and/or modes.
480 #+begin_src emacs-lisp
481 (defun a/no-mouse-autoselect-window ()
482 (make-local-variable 'mouse-autoselect-window)
483 (setq mouse-autoselect-window nil))
488 #+begin_src emacs-lisp
495 Convenience macro for =setq='ing multiple variables to the same value:
497 #+begin_src emacs-lisp
498 (defmacro a/setq-every (value &rest vars)
499 "Set all the variables from VARS to value VALUE."
500 (declare (indent defun) (debug t))
501 `(progn ,@(mapcar (lambda (x) (list 'setq x value)) vars)))
504 The following process-related stuff from [[https://github.com/alezost/emacs-config][alezost's emacs-config]].
506 #+begin_src emacs-lisp
507 (defun a/start-process (program &rest args)
508 "Same as `start-process', but doesn't bother about name and buffer."
509 (let ((process-name (concat program "_process"))
510 (buffer-name (generate-new-buffer-name
511 (concat program "_output"))))
512 (apply #'start-process
513 process-name buffer-name program args)))
515 (defun a/dired-start-process (program &optional args)
516 "Open current file with a PROGRAM."
517 ;; Shell command looks like this: "program [ARGS]... FILE" (ARGS can
518 ;; be nil, so remove it).
519 (apply #'a/start-process
521 (remove nil (list args (dired-get-file-for-visit)))))
531 *** Time and battery in mode-line
533 Enable displaying time and battery in the mode-line, since I'm not
534 using the Xfce panel anymore. Also, I don't need to see the load
535 average on a regular basis, so disable that.
537 Note: using =i3status= on sway at the moment, so disabling this.
539 #+begin_src emacs-lisp :tangle no
542 (setq display-time-default-load-average nil)
548 (display-battery-mode))
553 Might want to set the fringe to a smaller value, especially if using
554 EXWM. I'm fine with the default for now.
556 #+begin_src emacs-lisp
557 ;; (fringe-mode '(3 . 1))
561 *** Disable disabled commands
563 Emacs disables some commands by default that could persumably be
564 confusing for novice users. Let's disable that.
566 #+begin_src emacs-lisp
567 (setq disabled-command-function nil)
572 Save what I copy into clipboard from other applications into Emacs'
573 kill-ring, which would allow me to still be able to easily access it
574 in case I kill (cut or copy) something else inside Emacs before
575 yanking (pasting) what I'd originally intended to.
577 #+begin_src emacs-lisp
578 (setq save-interprogram-paste-before-kill t)
583 #+begin_src emacs-lisp
584 (setq enable-recursive-minibuffers t
585 resize-mini-windows t)
588 *** Lazy-person-friendly yes/no prompts
590 Lazy people would prefer to type fewer keystrokes, especially for yes
591 or no questions. I'm lazy.
593 #+begin_src emacs-lisp
594 (defalias 'yes-or-no-p #'y-or-n-p)
597 *** Startup screen and =*scratch*=
599 Firstly, let Emacs know that I'd like to have =*scratch*= as my
602 #+begin_src emacs-lisp
603 (setq initial-buffer-choice t)
606 Now let's customize the =*scratch*= buffer a bit. First off, I don't
607 need the default hint.
609 #+begin_src emacs-lisp
610 (setq initial-scratch-message nil)
613 Also, let's use Text mode as the major mode, in case I want to
614 customize it (=*scratch*='s default major mode, Fundamental mode,
615 can't really be customized).
617 #+begin_src emacs-lisp
618 (setq initial-major-mode 'text-mode)
621 Inhibit the buffer list when more than 2 files are loaded.
623 #+begin_src emacs-lisp
624 (setq inhibit-startup-buffer-menu t)
627 I don't really need to see the startup screen or echo area message
630 #+begin_src emacs-lisp
631 (advice-add #'display-startup-echo-area-message :override #'ignore)
632 (setq inhibit-startup-screen t
633 inhibit-startup-echo-area-message user-login-name)
636 *** More useful frame titles
638 Show either the file name or the buffer name (in case the buffer isn't
639 visiting a file). Borrowed from Emacs Prelude.
641 #+begin_src emacs-lisp
642 (setq frame-title-format
643 '("" invocation-name " - "
644 (:eval (if (buffer-file-name)
645 (abbreviate-file-name (buffer-file-name))
651 Emacs' default backup settings aren't that great. Let's use more
652 sensible options. See documentation for the ~make-backup-file~
655 #+begin_src emacs-lisp
656 (setq backup-by-copying t
658 delete-old-versions t)
663 Enable automatic reloading of changed buffers and files.
665 #+begin_src emacs-lisp
666 (global-auto-revert-mode 1)
667 (setq auto-revert-verbose nil
668 global-auto-revert-non-file-buffers nil)
671 *** Always use space for indentation
673 #+begin_src emacs-lisp
676 require-final-newline t
682 Enable =winner-mode=.
684 #+begin_src emacs-lisp
688 *** Don’t display =*compilation*= on success
690 Based on https://stackoverflow.com/a/17788551, with changes to use
691 =cl-letf= instead of the now obsolete =flet=.
693 #+begin_src emacs-lisp
694 (with-eval-after-load 'compile
695 (defun a/compilation-finish-function (buffer outstr)
696 (unless (string-match "finished" outstr)
697 (switch-to-buffer-other-window buffer))
700 (setq compilation-finish-functions #'a/compilation-finish-function)
704 (defadvice compilation-start
705 (around inhibit-display
706 (command &optional mode name-function highlight-regexp))
707 (if (not (string-match "^\\(find\\|grep\\)" command))
708 (cl-letf (((symbol-function 'display-buffer) #'ignore))
709 (save-window-excursion ad-do-it))
711 (ad-activate 'compilation-start))
714 *** Search for non-ASCII characters
716 I’d like non-ASCII characters such as ‘’“”«»‹›áⓐ𝒶 to be selected when
717 I search for their ASCII counterpart. Shoutout to [[http://endlessparentheses.com/new-in-emacs-25-1-easily-search-non-ascii-characters.html][endlessparentheses]]
720 #+begin_src emacs-lisp
721 (setq search-default-mode #'char-fold-to-regexp)
723 ;; uncomment to extend this behaviour to query-replace
724 ;; (setq replace-char-fold t)
729 #+begin_src emacs-lisp
730 (setq-default cursor-type 'bar)
733 *** Allow scrolling in Isearch
735 #+begin_src emacs-lisp
736 (setq isearch-allow-scroll t)
741 #+begin_src emacs-lisp
745 ("C-c e b" . eval-buffer)
746 ("C-c e r" . eval-region)
748 ("C-c F m" . make-frame-command)
749 ("C-c F d" . delete-frame)
750 ("C-c F D" . delete-other-frames)
752 ("C-c o" . other-window)
754 ("C-c Q" . save-buffers-kill-terminal)
756 ("C-S-h C" . describe-char)
757 ("C-S-h F" . describe-face)
759 ("C-x K" . kill-this-buffer)
761 ("s-p" . beginning-of-buffer)
762 ("s-n" . end-of-buffer))
767 The packages in this section are absolutely essential to my everyday
768 workflow, and they play key roles in how I do my computing. They
769 immensely enhance the Emacs experience for me; both using Emacs, and
772 *** [[https://github.com/emacscollective/auto-compile][auto-compile]]
774 #+begin_src emacs-lisp
775 (use-package auto-compile
778 (auto-compile-on-load-mode)
779 (auto-compile-on-save-mode)
780 (setq auto-compile-display-buffer nil
781 auto-compile-mode-line-counter t
782 auto-compile-source-recreate-deletes-dest t
783 auto-compile-toggle-deletes-nonlib-dest t
784 auto-compile-update-autoloads t)
785 (add-hook 'auto-compile-inhibit-compile-hook
786 'auto-compile-inhibit-compile-detached-git-head))
789 *** [[https://orgmode.org/][Org]]
792 Org mode is for keeping notes, maintaining TODO lists, planning
793 projects, and authoring documents with a fast and effective plain-text
797 In short, my favourite way of life.
799 First, we have to resort to a [[https://github.com/raxod502/straight.el#installing-org-with-straightel][hack]] to be able to use the correct
800 latest version of Org from upstream.
802 #+begin_src emacs-lisp
805 (defun org-git-version ()
806 "The Git version of org-mode.
807 Inserted by installing org-mode or when a release is made."
809 (let ((git-repo (expand-file-name
810 "straight/repos/org/" user-emacs-directory)))
817 (defun org-release ()
818 "The release version of org-mode.
819 Inserted by installing org-mode or when a release is made."
821 (let ((git-repo (expand-file-name
822 "straight/repos/org/" user-emacs-directory)))
824 (string-remove-prefix
831 (provide 'org-version)
834 We will use the =org-plus-contrib= package to get the whole deal:
836 #+begin_src emacs-lisp
837 (straight-use-package 'org-plus-contrib)
840 And here's where my actual Org configurations begin:
842 #+begin_src emacs-lisp
846 (setq org-src-tab-acts-natively t
847 org-src-preserve-indentation nil
848 org-edit-src-content-indentation 0
849 org-email-link-description-format "Email %c: %s" ; %.30s
850 org-highlight-latex-and-related '(entities)
851 org-use-speed-commands t
852 org-startup-folded 'content
853 org-catch-invisible-edits 'show-and-error
855 (add-to-list 'org-structure-template-alist '("L" . "src emacs-lisp") t)
856 :bind (:map org-mode-map ("M-L" . org-insert-last-stored-link))
857 :hook ((org-mode . org-indent-mode)
858 (org-mode . auto-fill-mode)
859 (org-mode . flyspell-mode))
861 (org-latex-packages-alist '(("" "listings") ("" "color")))
863 '(org-block-begin-line ((t (:foreground "#5a5b5a" :background "#1d1f21"))))
864 '(org-block ((t (:background "#1d1f21"))))
865 '(org-latex-and-related ((t (:foreground "#b294bb")))))
867 (use-feature ox-latex
870 (setq org-latex-listings 'listings
871 ;; org-latex-prefer-user-labels t
873 (add-to-list 'org-latex-classes
874 '("IEEEtran" "\\documentclass[11pt]{IEEEtran}"
875 ("\\section{%s}" . "\\section*{%s}")
876 ("\\subsection{%s}" . "\\subsection*{%s}")
877 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
878 ("\\paragraph{%s}" . "\\paragraph*{%s}")
879 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
881 (require 'ox-beamer))
884 **** asynchronous tangle
886 =a/async-babel-tangle= is a function closely inspired by [[https://github.com/dieggsy/dotfiles/tree/cc10edf7701958eff1cd94d4081da544d882a28c/emacs.d#dotfiles][dieggsy's
887 d/async-babel-tangle]] which uses [[https://github.com/jwiegley/emacs-async][async]] to asynchronously tangle an org
890 #+begin_src emacs-lisp
891 (with-eval-after-load 'org
892 (defvar a/show-async-tangle-results nil
893 "Keep *emacs* async buffers around for later inspection.")
895 (defvar a/show-async-tangle-time nil
896 "Show the time spent tangling the file.")
898 (defvar a/async-tangle-post-compile
899 (when a/byte-compiled-init "make build-init")
900 "If non-nil, pass to `compile' after successful tangle.")
902 ;; TODO: look into why directly byte-compiling init.el causes a
903 ;; number of problems, including magit-status not loading (busy
905 (defvar a/async-tangle-byte-recompile nil
906 "If non-nil, byte-recompile the file on successful tangle.")
908 (defun a/async-babel-tangle ()
909 "Tangle org file asynchronously."
911 (let* ((file-tangle-start-time (current-time))
912 (file (buffer-file-name))
913 (file-nodir (file-name-nondirectory file))
914 ;; (async-quiet-switch "-q")
915 (file-noext (file-name-sans-extension file)))
919 (org-babel-tangle-file ,file))
920 (unless a/show-async-tangle-results
924 ;; (setq byte-compile-warnings '(not noruntime unresolved))
925 (message "Tangled %s%s"
927 (if a/show-async-tangle-time
929 (float-time (time-subtract (current-time)
930 ',file-tangle-start-time)))
932 (when a/async-tangle-post-compile
933 (compile a/async-tangle-post-compile))
934 (when a/async-tangle-byte-recompile
935 (byte-recompile-file (concat ,file-noext ".el"))))
936 (message "Tangling %s failed" ,file-nodir))))))))
939 'safe-local-variable-values
940 '(eval add-hook 'after-save-hook #'a/async-babel-tangle 'append 'local))
943 *** [[https://magit.vc/][Magit]]
946 It's Magit! A Git porcelain inside Emacs.
949 Not just how I do git, but /the/ way to do git.
951 #+begin_src emacs-lisp
954 :bind (("C-x g" . magit-status)
955 ("s-g s" . magit-status)
956 ("s-g l" . magit-log-buffer-file))
958 (magit-add-section-hook 'magit-status-sections-hook
959 'magit-insert-modules
960 'magit-insert-stashes
963 magit-repository-directories '(("~/.emacs.d/" . 0)
965 (nconc magit-section-initial-visibility-alist
966 '(([unpulled status] . show)
967 ([unpushed status] . show)))
968 :custom-face (magit-diff-file-heading ((t (:weight normal)))))
973 Recently opened files.
975 #+begin_src emacs-lisp
979 (add-to-list 'recentf-exclude "^/\\(?:ssh\\|su\\|sudo\\)?:")
980 (setq recentf-max-saved-items 40))
986 A smart M-x enhancement for Emacs.
989 Mostly because =counsel= needs it to remember history.
991 #+begin_src emacs-lisp
995 *** [[https://github.com/abo-abo/swiper][Ivy]] (and friends)
998 Ivy - a generic completion frontend for Emacs, Swiper - isearch with
999 an overview, and more. Oh, man!
1002 There's no way I could top that, so I won't attempt to.
1006 #+begin_src emacs-lisp
1010 (:map ivy-minibuffer-map
1011 ([escape] . keyboard-escape-quit)
1012 ([S-up] . ivy-previous-history-element)
1013 ([S-down] . ivy-next-history-element)
1014 ("DEL" . ivy-backward-delete-char))
1019 ;; (ivy-minibuffer-match-face-2 ((t (:background "#e99ce8" :weight semi-bold))))
1020 ;; (ivy-minibuffer-match-face-3 ((t (:background "#bbbbff" :weight semi-bold))))
1021 ;; (ivy-minibuffer-match-face-4 ((t (:background "#ffbbff" :weight semi-bold))))
1027 #+begin_src emacs-lisp
1030 :bind (("C-s" . swiper)
1032 ("C-S-s" . isearch-forward)))
1037 #+begin_src emacs-lisp
1038 (use-package counsel
1040 :bind (([remap execute-extended-command] . counsel-M-x)
1041 ([remap find-file] . counsel-find-file)
1042 ("s-r" . counsel-recentf)
1043 ("C-c x" . counsel-M-x)
1044 ("C-c f ." . counsel-find-file)
1045 :map minibuffer-local-map
1046 ("C-r" . counsel-minibuffer-history))
1049 (defalias 'locate #'counsel-locate))
1054 #+begin_src emacs-lisp
1058 :bind ("C-c a s e" . eshell)
1060 (eval-when-compile (defvar eshell-prompt-regexp))
1061 (defun a/eshell-quit-or-delete-char (arg)
1063 (if (and (eolp) (looking-back eshell-prompt-regexp nil))
1064 (eshell-life-is-too-much)
1067 (defun a/eshell-clear ()
1069 (let ((inhibit-read-only t))
1071 (eshell-send-input))
1073 (defun a/eshell-setup ()
1074 (make-local-variable 'company-idle-delay)
1075 (defvar company-idle-delay)
1076 (setq company-idle-delay nil)
1077 (bind-keys :map eshell-mode-map
1078 ("C-d" . a/eshell-quit-or-delete-char)
1079 ("C-S-l" . a/eshell-clear)
1080 ("M-r" . counsel-esh-history)
1081 ([tab] . company-complete)))
1083 :hook (eshell-mode . a/eshell-setup)
1085 (eshell-hist-ignoredups t)
1086 (eshell-input-filter 'eshell-input-filter-initial-space))
1091 #+begin_src emacs-lisp
1092 (use-feature ibuffer
1094 (("C-x C-b" . ibuffer-other-window)
1095 :map ibuffer-mode-map
1096 ("P" . ibuffer-backward-filter-group)
1097 ("N" . ibuffer-forward-filter-group)
1098 ("M-p" . ibuffer-do-print)
1099 ("M-n" . ibuffer-do-shell-command-pipe-replace))
1101 ;; Use human readable Size column instead of original one
1102 (define-ibuffer-column size-h
1103 (:name "Size" :inline t)
1105 ((> (buffer-size) 1000000) (format "%7.1fM" (/ (buffer-size) 1000000.0)))
1106 ((> (buffer-size) 100000) (format "%7.0fk" (/ (buffer-size) 1000.0)))
1107 ((> (buffer-size) 1000) (format "%7.1fk" (/ (buffer-size) 1000.0)))
1108 (t (format "%8d" (buffer-size)))))
1110 (ibuffer-saved-filter-groups
1112 ("dired" (mode . dired-mode))
1113 ("org" (mode . org-mode))
1116 (mode . gnus-group-mode)
1117 (mode . gnus-summary-mode)
1118 (mode . gnus-article-mode)
1119 ;; not really, but...
1120 (mode . message-mode)))
1129 (mode . eshell-mode)
1131 (mode . term-mode)))
1134 (mode . python-mode)
1137 (mode . emacs-lisp-mode)
1138 (mode . scheme-mode)
1139 (mode . haskell-mode)
1140 (mode . lean-mode)))
1143 (name . "^\\*scratch\\*$")
1144 (name . "^\\*Messages\\*$"))))))
1146 '((mark modified read-only locked " "
1147 (name 18 18 :left :elide)
1149 (size-h 9 -1 :right)
1151 (mode 16 16 :left :elide)
1152 " " filename-and-process)
1156 :hook (ibuffer . (lambda () (ibuffer-switch-to-saved-filter-groups "default"))))
1161 #+begin_src emacs-lisp
1162 (use-feature outline
1163 :hook (prog-mode . outline-minor-mode)
1166 outline-minor-mode-map
1167 ("<s-tab>" . outline-toggle-children)
1168 ("M-p" . outline-previous-visible-heading)
1169 ("M-n" . outline-next-visible-heading)
1170 :prefix-map a/outline-prefix-map
1172 ("TAB" . outline-toggle-children)
1173 ("a" . outline-hide-body)
1174 ("H" . outline-hide-body)
1175 ("S" . outline-show-all)
1176 ("h" . outline-hide-subtree)
1177 ("s" . outline-show-subtree)))
1182 #+begin_src emacs-lisp
1183 (use-feature ls-lisp
1184 :custom (ls-lisp-dirs-first t))
1188 (setq dired-listing-switches "-alh"
1189 ls-lisp-use-insert-directory-program nil)
1191 ;; easily diff 2 marked files
1192 ;; https://oremacs.com/2017/03/18/dired-ediff/
1193 (defun dired-ediff-files ()
1195 (require 'dired-aux)
1196 (defvar ediff-after-quit-hook-internal)
1197 (let ((files (dired-get-marked-files))
1198 (wnd (current-window-configuration)))
1199 (if (<= (length files) 2)
1200 (let ((file1 (car files))
1201 (file2 (if (cdr files)
1205 (dired-dwim-target-directory)))))
1206 (if (file-newer-than-file-p file1 file2)
1207 (ediff-files file2 file1)
1208 (ediff-files file1 file2))
1209 (add-hook 'ediff-after-quit-hook-internal
1211 (setq ediff-after-quit-hook-internal nil)
1212 (set-window-configuration wnd))))
1213 (error "no more than 2 files should be marked"))))
1214 :bind (:map dired-mode-map
1215 ("b" . dired-up-directory)
1216 ("e" . dired-ediff-files)
1217 ("E" . dired-toggle-read-only)
1218 ("\\" . dired-hide-details-mode)
1221 (a/dired-start-process "zathura"))))
1222 :hook (dired-mode . dired-hide-details-mode))
1227 #+begin_src emacs-lisp
1230 (temp-buffer-resize-mode)
1231 (setq help-window-select t))
1236 #+begin_src emacs-lisp
1239 (add-to-list 'tramp-default-proxies-alist '(nil "\\`root\\'" "/ssh:%h:"))
1240 (add-to-list 'tramp-default-proxies-alist '("localhost" nil nil))
1241 (add-to-list 'tramp-default-proxies-alist
1242 (list (regexp-quote (system-name)) nil nil)))
1247 #+begin_src emacs-lisp
1249 :config (dash-enable-font-lock))
1259 Highlight uncommitted changes in the left fringe.
1261 #+begin_src emacs-lisp
1262 (use-package diff-hl
1264 (setq diff-hl-draw-borders nil)
1265 (global-diff-hl-mode)
1266 :hook (magit-post-refresh . diff-hl-magit-post-refresh))
1271 Display Lisp objects at point in the echo area.
1273 #+begin_src emacs-lisp
1275 :when (version< "25" emacs-version)
1276 :config (global-eldoc-mode))
1281 Highlight matching parens.
1283 #+begin_src emacs-lisp
1286 :config (show-paren-mode))
1289 ** simple (for column numbers)
1291 #+begin_src emacs-lisp
1293 :config (column-number-mode))
1298 Save minibuffer history.
1300 #+begin_src emacs-lisp
1301 (use-feature savehist
1302 :config (savehist-mode))
1307 Automatically save place in each file.
1309 #+begin_src emacs-lisp
1310 (use-feature saveplace
1311 :when (version< "25" emacs-version)
1312 :config (save-place-mode))
1317 #+begin_src emacs-lisp
1318 (use-feature prog-mode
1319 :config (global-prettify-symbols-mode)
1320 (defun indicate-buffer-boundaries-left ()
1321 (setq indicate-buffer-boundaries 'left))
1322 (add-hook 'prog-mode-hook #'indicate-buffer-boundaries-left))
1327 #+begin_src emacs-lisp
1328 (use-feature text-mode
1329 :hook ((text-mode . indicate-buffer-boundaries-left)
1330 (text-mode . abbrev-mode)))
1335 #+begin_src emacs-lisp
1336 (use-package company
1339 (:map company-active-map
1340 ([tab] . company-complete-common-or-cycle)
1341 ([escape] . company-abort))
1343 (company-minimum-prefix-length 1)
1344 (company-selection-wrap-around t)
1345 (company-dabbrev-char-regexp "\\sw\\|\\s_\\|[-_]")
1346 (company-dabbrev-downcase nil)
1347 (company-dabbrev-ignore-case nil)
1349 (global-company-mode t))
1354 #+begin_src emacs-lisp
1355 (use-package flycheck
1357 :hook (prog-mode . flycheck-mode)
1359 (:map flycheck-mode-map
1360 ("M-P" . flycheck-previous-error)
1361 ("M-N" . flycheck-next-error))
1363 ;; Use the load-path from running Emacs when checking elisp files
1364 (setq flycheck-emacs-lisp-load-path 'inherit)
1366 ;; Only flycheck when I actually save the buffer
1367 (setq flycheck-check-syntax-automatically '(mode-enabled save)))
1369 ;; http://endlessparentheses.com/ispell-and-apostrophes.html
1373 ;; ’ can be part of a word
1374 (setq ispell-local-dictionary-alist
1375 `((nil "[[:alpha:]]" "[^[:alpha:]]"
1376 "['\x2019]" nil ("-B") nil utf-8)))
1377 ;; don't send ’ to the subprocess
1378 (defun endless/replace-apostrophe (args)
1379 (cons (replace-regexp-in-string
1382 (advice-add #'ispell-send-string :filter-args
1383 #'endless/replace-apostrophe)
1385 ;; convert ' back to ’ from the subprocess
1386 (defun endless/replace-quote (args)
1387 (if (not (derived-mode-p 'org-mode))
1389 (cons (replace-regexp-in-string
1392 (advice-add #'ispell-parse-output :filter-args
1393 #'endless/replace-quote))
1398 :CUSTOM_ID: programming-modes
1403 #+begin_src emacs-lisp
1404 (use-feature lisp-mode
1406 (add-hook 'emacs-lisp-mode-hook 'outline-minor-mode)
1407 (add-hook 'emacs-lisp-mode-hook 'reveal-mode)
1408 (defun indent-spaces-mode ()
1409 (setq indent-tabs-mode nil))
1410 (add-hook 'lisp-interaction-mode-hook #'indent-spaces-mode))
1413 ** [[http://alloytools.org][Alloy]] (with [[https://github.com/dwwmmn/alloy-mode][alloy-mode]])
1415 #+begin_src emacs-lisp
1416 (use-package alloy-mode
1417 :straight (:host github :repo "dwwmmn/alloy-mode")
1418 :config (setq alloy-basic-offset 2))
1421 ** [[https://coq.inria.fr][Coq]] (with [[https://github.com/ProofGeneral/PG][Proof General]])
1423 #+begin_src emacs-lisp
1424 (use-package proof-site ; Proof General
1425 :straight proof-general)
1428 ** [[https://leanprover.github.io][Lean]] (with [[https://github.com/leanprover/lean-mode][lean-mode]])
1430 #+begin_src emacs-lisp
1431 (eval-when-compile (defvar lean-mode-map))
1432 (use-package lean-mode
1434 :bind (:map lean-mode-map
1435 ("S-SPC" . company-complete))
1437 (require 'lean-input)
1438 (setq default-input-method "Lean"
1439 lean-input-tweak-all '(lean-input-compose
1440 (lean-input-prepend "/")
1441 (lean-input-nonempty))
1442 lean-input-user-translations '(("/" "/")))
1448 *** [[https://github.com/haskell/haskell-mode][haskell-mode]]
1450 #+begin_src emacs-lisp
1451 (use-package haskell-mode
1453 (setq haskell-indentation-layout-offset 4
1454 haskell-indentation-left-offset 4
1455 flycheck-checker 'haskell-hlint
1456 flycheck-disabled-checkers '(haskell-stack-ghc haskell-ghc)))
1459 *** [[https://github.com/jyp/dante][dante]]
1461 #+begin_src emacs-lisp
1464 :commands dante-mode
1465 :hook (haskell-mode . dante-mode))
1468 *** [[https://github.com/mpickering/hlint-refactor-mode][hlint-refactor]]
1470 Emacs bindings for [[https://github.com/ndmitchell/hlint][hlint]]'s refactor option. This requires the refact
1471 executable from [[https://github.com/mpickering/apply-refact][apply-refact]].
1473 #+begin_src emacs-lisp
1474 (use-package hlint-refactor
1476 :bind (:map hlint-refactor-mode-map
1477 ("C-c l b" . hlint-refactor-refactor-buffer)
1478 ("C-c l r" . hlint-refactor-refactor-at-point))
1479 :hook (haskell-mode . hlint-refactor-mode))
1482 *** [[https://github.com/flycheck/flycheck-haskell][flycheck-haskell]]
1484 #+begin_src emacs-lisp
1485 (use-package flycheck-haskell
1486 :after haskell-mode)
1489 *** [[https://github.com/ndmitchell/hlint/blob/20e116a043f2073c57b17b24ae6364b5e433ba7e/data/hs-lint.el][hs-lint.el]]
1491 :header-args+: :tangle lisp/hs-lint.el :mkdirp yes
1494 Currently using =flycheck-haskell= with the =haskell-hlint= checker
1497 #+begin_src emacs-lisp :tangle no
1498 ;;; hs-lint.el --- minor mode for HLint code checking
1500 ;; Copyright 2009 (C) Alex Ott
1502 ;; Author: Alex Ott <alexott@gmail.com>
1503 ;; Keywords: haskell, lint, HLint
1505 ;; Status: distributed under terms of GPL2 or above
1507 ;; Typical message from HLint looks like:
1509 ;; /Users/ott/projects/lang-exp/haskell/test.hs:52:1: Eta reduce
1511 ;; count1 p l = length (filter p l)
1513 ;; count1 p = length . filter p
1518 (defgroup hs-lint nil
1519 "Run HLint as inferior of Emacs, parse error messages."
1523 (defcustom hs-lint-command "hlint"
1524 "The default hs-lint command for \\[hlint]."
1528 (defcustom hs-lint-save-files t
1529 "Save modified files when run HLint or no (ask user)"
1533 (defcustom hs-lint-replace-with-suggestions nil
1534 "Replace user's code with suggested replacements"
1538 (defcustom hs-lint-replace-without-ask nil
1539 "Replace user's code with suggested replacements automatically"
1543 (defun hs-lint-process-setup ()
1544 "Setup compilation variables and buffer for `hlint'."
1545 (run-hooks 'hs-lint-setup-hook))
1547 ;; regex for replace suggestions
1549 ;; ^\(.*?\):\([0-9]+\):\([0-9]+\): .*
1555 (defvar hs-lint-regex
1556 "^\\(.*?\\):\\([0-9]+\\):\\([0-9]+\\): .*[\n\C-m]Found:[\n\C-m]\\s +\\(.*\\)[\n\C-m]Why not:[\n\C-m]\\s +\\(.*\\)[\n\C-m]"
1557 "Regex for HLint messages")
1559 (defun make-short-string (str maxlen)
1560 (if (< (length str) maxlen)
1562 (concat (substring str 0 (- maxlen 3)) "...")))
1564 (defun hs-lint-replace-suggestions ()
1565 "Perform actual replacement of suggestions"
1566 (goto-char (point-min))
1567 (while (re-search-forward hs-lint-regex nil t)
1568 (let* ((fname (match-string 1))
1569 (fline (string-to-number (match-string 2)))
1570 (old-code (match-string 4))
1571 (new-code (match-string 5))
1572 (msg (concat "Replace '" (make-short-string old-code 30)
1573 "' with '" (make-short-string new-code 30) "'"))
1579 (switch-to-buffer (get-file-buffer fname))
1580 (goto-char (point-min))
1581 (forward-line (1- fline))
1583 (setf bline (point))
1584 (when (or hs-lint-replace-without-ask
1587 (setf eline (point))
1589 (setf old-code (regexp-quote old-code))
1590 (while (string-match "\\\\ " old-code spos)
1591 (setf new-old-code (concat new-old-code
1592 (substring old-code spos (match-beginning 0))
1594 (setf spos (match-end 0)))
1595 (setf new-old-code (concat new-old-code (substring old-code spos)))
1596 (remove-text-properties bline eline '(composition nil))
1597 (when (re-search-forward new-old-code eline t)
1598 (replace-match new-code nil t)))))))
1600 (defun hs-lint-finish-hook (buf msg)
1601 "Function, that is executed at the end of HLint execution"
1602 (if hs-lint-replace-with-suggestions
1603 (hs-lint-replace-suggestions)
1606 (define-compilation-mode hs-lint-mode "HLint"
1607 "Mode for check Haskell source code."
1608 (set (make-local-variable 'compilation-process-setup-function)
1609 'hs-lint-process-setup)
1610 (set (make-local-variable 'compilation-disable-input) t)
1611 (set (make-local-variable 'compilation-scroll-output) nil)
1612 (set (make-local-variable 'compilation-finish-functions)
1613 (list 'hs-lint-finish-hook))
1617 "Run HLint for current buffer with haskell source"
1619 (save-some-buffers hs-lint-save-files)
1620 (compilation-start (concat hs-lint-command " \"" buffer-file-name "\"")
1624 ;;; hs-lint.el ends here
1627 #+begin_src emacs-lisp :tangle no
1628 (use-package hs-lint
1630 :bind (:map haskell-mode-map
1631 ("C-c l l" . hs-lint)))
1638 #+begin_src emacs-lisp
1639 (use-package sgml-mode
1641 (setq sgml-basic-offset 2))
1646 #+begin_src emacs-lisp
1647 (use-package css-mode
1649 (setq css-indent-offset 2))
1654 #+begin_src emacs-lisp
1655 (use-package web-mode
1659 web-mode-code-indent-offset
1660 web-mode-css-indent-offset
1661 web-mode-markup-indent-offset))
1666 #+begin_src emacs-lisp
1667 (use-package emmet-mode
1668 :after (:any web-mode css-mode sgml-mode)
1669 :bind* (("C-)" . emmet-next-edit-point)
1670 ("C-(" . emmet-prev-edit-point))
1672 (unbind-key "C-j" emmet-mode-keymap)
1673 (setq emmet-move-cursor-between-quotes t)
1674 :hook (web-mode css-mode html-mode sgml-mode))
1681 #+begin_src emacs-lisp
1682 (use-package meghanada
1684 (:map meghanada-mode-map
1685 (("C-M-o" . meghanada-optimize-import)
1686 ("C-M-t" . meghanada-import-all)))
1687 :hook (java-mode . meghanada-mode))
1708 #+begin_src emacs-lisp
1709 (use-package treemacs
1710 :config (setq treemacs-never-persist t))
1712 (use-package yasnippet
1714 ;; (yas-global-mode)
1717 (use-package lsp-mode
1718 :init (setq lsp-eldoc-render-all nil
1719 lsp-highlight-symbol-at-point nil)
1724 (use-package company-lsp
1727 (setq company-lsp-cache-candidates t
1728 company-lsp-async t))
1732 (setq lsp-ui-sideline-update-mode 'point))
1734 (use-package lsp-java
1736 (add-hook 'java-mode-hook
1738 (setq-local company-backends (list 'company-lsp))))
1740 (add-hook 'java-mode-hook 'lsp-java-enable)
1741 (add-hook 'java-mode-hook 'flycheck-mode)
1742 (add-hook 'java-mode-hook 'company-mode)
1743 (add-hook 'java-mode-hook 'lsp-ui-mode))
1745 (use-package dap-mode
1751 (use-package dap-java
1754 (use-package lsp-java-treemacs
1760 #+begin_src emacs-lisp
1761 (use-package geiser)
1763 (use-feature geiser-guile
1765 (setq geiser-guile-load-path "~/src/git/guix"))
1770 #+begin_src emacs-lisp
1774 * Emacs enhancements
1776 :CUSTOM_ID: emacs-enhancements
1781 #+begin_src emacs-lisp
1783 :config (setq Man-width 80))
1786 ** [[https://github.com/justbur/emacs-which-key][which-key]]
1789 Emacs package that displays available keybindings in popup
1792 #+begin_src emacs-lisp
1793 (use-package which-key
1796 (which-key-add-key-based-replacements
1797 ;; prefixes for global prefixes and minor modes
1801 "C-c 8 -" "typo/dashes"
1802 "C-c 8 <" "typo/left-brackets"
1803 "C-c 8 >" "typo/right-brackets"
1805 "C-x a" "abbrev/expand"
1806 "C-x r" "rectangle/register/bookmark"
1807 "C-x v" "version control"
1808 ;; prefixes for my personal bindings
1809 "C-c a" "applications"
1811 "C-c P" "package-management"
1812 "C-c P e" "package-management/epkg"
1813 "C-c P s" "package-management/straight.el"
1814 "C-c c" "compile-and-comments"
1819 "C-c m" "multiple-cursors"
1820 "C-c p" "projectile"
1821 "C-c p s" "projectile/search"
1822 "C-c p x" "projectile/execute"
1823 "C-c p 4" "projectile/other-window"
1829 ;; prefixes for major modes
1830 (which-key-add-major-mode-key-based-replacements 'message-mode
1832 (which-key-add-major-mode-key-based-replacements 'org-mode
1833 "C-c C-v" "org-babel")
1834 (which-key-add-major-mode-key-based-replacements 'web-mode
1835 "C-c C-a" "web/attributes"
1836 "C-c C-b" "web/blocks"
1838 "C-c C-e" "web/element"
1839 "C-c C-t" "web/tags")
1846 #+begin_src emacs-lisp
1847 (add-to-list 'custom-theme-load-path "~/.emacs.d/lisp")
1848 (load-theme 'tangomod t)
1853 #+begin_src emacs-lisp
1854 (use-package smart-mode-line
1855 :commands (sml/apply-theme)
1863 #+begin_src emacs-lisp
1864 (use-package doom-themes)
1867 ** theme helper functions
1869 #+begin_src emacs-lisp
1870 (defvar a/org-mode-font-lock-keywords
1871 '(("[ \t]*\\(#\\+\\(BEGIN\\|END\\|begin\\|end\\)_\\(\\S-+\\)\\)[ \t]*\\([^\n:]*\\)"
1872 (1 '(:foreground "#5a5b5a" :background "#292b2b") t) ; directive
1873 (3 '(:foreground "#81a2be" :background "#292b2b") t) ; kind
1874 (4 '(:foreground "#c5c8c6") t)))) ; title
1876 (defun a/lights-on ()
1877 "Enable my favourite light theme."
1879 (mapc #'disable-theme custom-enabled-themes)
1880 (load-theme 'tangomod t)
1881 (sml/apply-theme 'automatic)
1882 (font-lock-remove-keywords
1883 'org-mode a/org-mode-font-lock-keywords))
1885 (defun a/lights-off ()
1888 (mapc #'disable-theme custom-enabled-themes)
1889 (load-theme 'doom-tomorrow-night t)
1890 (sml/apply-theme 'automatic)
1891 (font-lock-add-keywords
1892 'org-mode a/org-mode-font-lock-keywords t))
1895 ("s-t d" . a/lights-off)
1896 ("s-t l" . a/lights-on))
1899 ** [[https://github.com/bbatsov/crux][crux]]
1901 #+begin_src emacs-lisp
1902 (use-package crux ; results in Waiting for git... [2 times]
1904 :bind (("C-c b k" . crux-kill-other-buffers)
1905 ("C-c d" . crux-duplicate-current-line-or-region)
1906 ("C-c D" . crux-duplicate-and-comment-current-line-or-region)
1907 ("C-c f c" . crux-copy-file-preserve-attributes)
1908 ("C-c f d" . crux-delete-file-and-buffer)
1909 ("C-c f r" . crux-rename-file-and-buffer)
1910 ("C-c j" . crux-top-join-line)
1911 ("C-S-j" . crux-top-join-line)))
1914 ** [[https://github.com/alezost/mwim.el][mwim]]
1916 #+begin_src emacs-lisp
1918 :bind (("C-a" . mwim-beginning-of-code-or-line)
1919 ("C-e" . mwim-end-of-code-or-line)
1920 ("<home>" . mwim-beginning-of-line-or-code)
1921 ("<end>" . mwim-end-of-line-or-code)))
1926 #+begin_src emacs-lisp
1927 (use-package projectile
1928 :bind-keymap ("C-c p" . projectile-command-map)
1932 (defun my-projectile-invalidate-cache (&rest _args)
1933 ;; ignore the args to `magit-checkout'
1934 (projectile-invalidate-cache nil))
1936 (eval-after-load 'magit-branch
1938 (advice-add 'magit-checkout
1939 :after #'my-projectile-invalidate-cache)
1940 (advice-add 'magit-branch-and-checkout
1941 :after #'my-projectile-invalidate-cache)))
1942 :custom (projectile-completion-system 'ivy))
1945 ** [[https://github.com/Wilfred/helpful][helpful]]
1947 #+begin_src emacs-lisp
1948 (use-package helpful
1951 (("C-S-h c" . helpful-command)
1952 ("C-S-h f" . helpful-callable) ; helpful-function
1953 ("C-S-h v" . helpful-variable)
1954 ("C-S-h k" . helpful-key)
1955 ("C-S-h p" . helpful-at-point)))
1958 ** [[https://github.com/EricCrosson/unkillable-scratch][unkillable-scratch]]
1960 Make =*scratch*= and =*Messages*= unkillable.
1962 #+begin_src emacs-lisp
1963 (use-package unkillable-scratch
1966 (unkillable-scratch 1)
1968 (unkillable-buffers '("^\\*scratch\\*$" "^\\*Messages\\*$")))
1971 ** [[https://github.com/davep/boxquote.el][boxquote.el]]
1975 | make pretty boxed quotes like this
1979 #+begin_src emacs-lisp
1980 (use-package boxquote
1983 (:prefix-map a/boxquote-prefix-map
1985 ("b" . boxquote-buffer)
1986 ("B" . boxquote-insert-buffer)
1987 ("d" . boxquote-defun)
1988 ("F" . boxquote-insert-file)
1989 ("hf" . boxquote-describe-function)
1990 ("hk" . boxquote-describe-key)
1991 ("hv" . boxquote-describe-variable)
1992 ("hw" . boxquote-where-is)
1993 ("k" . boxquote-kill)
1994 ("p" . boxquote-paragraph)
1995 ("q" . boxquote-boxquote)
1996 ("r" . boxquote-region)
1997 ("s" . boxquote-shell-command)
1998 ("t" . boxquote-text)
1999 ("T" . boxquote-title)
2000 ("u" . boxquote-unbox)
2001 ("U" . boxquote-unbox-region)
2002 ("y" . boxquote-yank)
2003 ("M-q" . boxquote-fill-paragraph)
2004 ("M-w" . boxquote-kill-ring-save)))
2007 Also see [[https://www.emacswiki.org/emacs/rebox2][rebox2]].
2011 #+begin_src emacs-lisp
2012 (use-package orgalist
2014 :hook (message-mode . orgalist-mode))
2019 #+begin_src emacs-lisp
2023 (typo-global-mode 1)
2024 :hook (text-mode . typo-mode))
2029 #+begin_src emacs-lisp
2030 (use-package hl-todo
2033 (global-hl-todo-mode))
2038 #+begin_src emacs-lisp
2039 (use-package shrink-path
2043 (defun +eshell/prompt ()
2044 (let ((base/dir (shrink-path-prompt default-directory)))
2045 (concat (propertize (car base/dir)
2046 'face 'font-lock-comment-face)
2047 (propertize (cdr base/dir)
2048 'face 'font-lock-constant-face)
2049 (propertize (+eshell--current-git-branch)
2050 'face 'font-lock-function-name-face)
2052 (propertize "λ" 'face 'eshell-prompt-face)
2053 ;; needed for the input text to not have prompt face
2054 (propertize " " 'face 'default))))
2056 (defun +eshell--current-git-branch ()
2057 (let ((branch (car (loop for match in (split-string (shell-command-to-string "git branch") "\n")
2058 when (string-match "^\*" match)
2060 (if (not (eq branch nil))
2061 (concat " " (substring branch 2))
2063 (setq eshell-prompt-regexp "\\(.*\n\\)*λ "
2064 eshell-prompt-function #'+eshell/prompt))
2067 ** [[https://github.com/peterwvj/eshell-up][eshell-up]]
2069 #+begin_src emacs-lisp
2070 (use-package eshell-up
2072 :commands eshell-up)
2077 #+begin_src emacs-lisp
2078 (use-package multi-term
2080 :bind (("C-c a s m" . multi-term-dedicated-toggle)
2082 ("C-c C-j" . term-char-mode)
2084 ("C-c C-j" . term-line-mode))
2086 (setq multi-term-program "/bin/screen"
2087 ;; TODO: add separate bindings for connecting to existing
2088 ;; session vs. always creating a new one
2089 multi-term-dedicated-select-after-open-p t
2090 multi-term-dedicated-window-height 20
2091 multi-term-dedicated-max-window-height 30
2093 '(("C-c C-c" . term-interrupt-subjob)
2094 ("C-c C-e" . term-send-esc)
2096 ("C-y" . term-paste)
2097 ("M-f" . term-send-forward-word)
2098 ("M-b" . term-send-backward-word)
2099 ("M-p" . term-send-up)
2100 ("M-n" . term-send-down)
2101 ("<C-backspace>" . term-send-backward-kill-word)
2102 ("<M-DEL>" . term-send-backward-kill-word)
2103 ("M-d" . term-send-delete-word)
2104 ("M-," . term-send-raw)
2105 ("M-." . comint-dynamic-complete))
2106 term-unbind-key-alist
2107 '("C-z" "C-x" "C-c" "C-h" "C-y" "<ESC>")))
2112 #+begin_src emacs-lisp
2113 (use-package page-break-lines
2115 (global-page-break-lines-mode))
2120 #+begin_src emacs-lisp
2121 (use-package expand-region
2122 :bind ("C-=" . er/expand-region))
2127 #+begin_src emacs-lisp
2128 (use-package multiple-cursors
2130 (("C-S-<mouse-1>" . mc/add-cursor-on-click)
2131 (:prefix-map a/mc-prefix-map
2133 ("c" . mc/edit-lines)
2134 ("n" . mc/mark-next-like-this)
2135 ("p" . mc/mark-previous-like-this)
2136 ("a" . mc/mark-all-like-this))))
2144 #+begin_src emacs-lisp
2145 (defvar a/maildir (expand-file-name "~/mail/"))
2146 (with-eval-after-load 'recentf
2147 (add-to-list 'recentf-exclude a/maildir))
2152 #+begin_src emacs-lisp
2154 a/gnus-init-file (no-littering-expand-etc-file-name "gnus")
2155 mail-user-agent 'gnus-user-agent
2156 read-mail-command 'gnus)
2159 :bind (("s-m" . gnus)
2160 ("s-M" . gnus-unplugged))
2163 gnus-select-method '(nnnil "")
2164 gnus-secondary-select-methods
2166 (nnimap-stream plain)
2167 (nnimap-address "127.0.0.1")
2168 (nnimap-server-port 143)
2169 (nnimap-authenticator plain)
2170 (nnimap-user "amin@aminb.org"))
2172 (nnimap-stream plain)
2173 (nnimap-address "127.0.0.1")
2174 (nnimap-server-port 143)
2175 (nnimap-authenticator plain)
2176 (nnimap-user "abandali@uwaterloo.ca")))
2177 gnus-message-archive-group "nnimap+amin:Sent"
2181 gnus-large-newsgroup 50
2182 gnus-home-directory (no-littering-expand-var-file-name "gnus/")
2183 gnus-directory (concat gnus-home-directory "news/")
2184 message-directory (concat gnus-home-directory "mail/")
2185 nndraft-directory (concat gnus-home-directory "drafts/")
2186 gnus-save-newsrc-file nil
2187 gnus-read-newsrc-file nil
2188 gnus-interactive-exit nil
2189 gnus-gcc-mark-as-read t))
2191 (use-feature gnus-art
2194 gnus-visible-headers
2195 (concat gnus-visible-headers "\\|^List-Id:\\|^X-RT-Originator:\\|^User-Agent:")
2196 gnus-sorted-header-list
2197 '("^From:" "^Subject:" "^Summary:" "^Keywords:"
2198 "^Followup-To:" "^To:" "^Cc:" "X-RT-Originator"
2199 "^Newsgroups:" "List-Id:" "^Organization:"
2200 "^User-Agent:" "^Date:")
2201 ;; local-lapsed article dates
2202 ;; from https://www.emacswiki.org/emacs/GnusFormatting#toc11
2203 gnus-article-date-headers '(user-defined)
2204 gnus-article-time-format
2206 (let* ((date (format-time-string "%a, %d %b %Y %T %z" time))
2207 (local (article-make-date-line date 'local))
2208 (combined-lapsed (article-make-date-line date
2211 (string-match " (.+" combined-lapsed)
2212 (match-string 0 combined-lapsed))))
2213 (concat local lapsed))))
2215 :map gnus-article-mode-map
2216 ("r" . gnus-article-reply-with-original)
2217 ("R" . gnus-article-wide-reply-with-original)
2218 ("M-L" . org-store-link)))
2220 (use-feature gnus-sum
2221 :bind (:map gnus-summary-mode-map
2222 :prefix-map a/gnus-summary-prefix-map
2224 ("r" . gnus-summary-reply)
2225 ("w" . gnus-summary-wide-reply)
2226 ("v" . gnus-summary-show-raw-article))
2229 :map gnus-summary-mode-map
2230 ("r" . gnus-summary-reply-with-original)
2231 ("R" . gnus-summary-wide-reply-with-original)
2232 ("M-L" . org-store-link))
2233 :hook (gnus-summary-mode . a/no-mouse-autoselect-window))
2235 (use-feature gnus-msg
2237 (setq gnus-posting-styles
2239 (address "amin@aminb.org")
2240 (body "\nBest,\namin\n")
2241 (eval (setq a/message-cite-say-hi t)))
2243 (address "bandali@gnu.org"))
2244 ((header "subject" "ThankCRM")
2245 (to "webmasters-comment@gnu.org")
2246 (body "\nAdded to 2018supporters.html.\n\nMoving to campaigns.\n\n-amin\n")
2247 (eval (setq a/message-cite-say-hi nil)))
2248 ("nnimap\\+uwaterloo:.*"
2249 (address "abandali@uwaterloo.ca")
2250 (gcc "\"nnimap+uwaterloo:Sent Items\"")))))
2252 (use-feature gnus-topic
2253 :hook (gnus-group-mode . gnus-topic-mode))
2255 (use-feature gnus-agent
2257 (setq gnus-agent-synchronize-flags 'ask)
2258 :hook (gnus-group-mode . gnus-agent-mode))
2260 (use-feature gnus-group
2262 (setq gnus-permanently-visible-groups "\\((INBOX\\|gnu$\\)"))
2264 (use-feature mm-decode
2266 (setq mm-discouraged-alternatives '("text/html" "text/richtext")))
2271 #+begin_src emacs-lisp
2272 (use-feature sendmail
2274 (setq sendmail-program "/usr/bin/msmtp"
2275 ;; message-sendmail-extra-arguments '("-v" "-d")
2276 mail-specify-envelope-from t
2277 mail-envelope-from 'header))
2282 #+begin_src emacs-lisp
2283 (use-feature message
2285 (defconst a/message-cite-style-format "On %Y-%m-%d %l:%M %p, %N wrote:")
2286 (defconst message-cite-style-bandali
2287 '((message-cite-function 'message-cite-original)
2288 (message-citation-line-function 'message-insert-formatted-citation-line)
2289 (message-cite-reply-position 'traditional)
2290 (message-yank-prefix "> ")
2291 (message-yank-cited-prefix ">")
2292 (message-yank-empty-prefix ">")
2293 (message-citation-line-format
2294 (if a/message-cite-say-hi
2295 (concat "Hi %F,\n\n" a/message-cite-style-format)
2296 a/message-cite-style-format)))
2297 "Citation style based on Mozilla Thunderbird's. Use with message-cite-style.")
2298 (setq message-cite-style 'message-cite-style-bandali
2299 message-kill-buffer-on-exit t
2300 message-send-mail-function 'message-send-mail-with-sendmail
2301 message-sendmail-envelope-from 'header
2302 message-dont-reply-to-names
2303 "\\(\\(.*@aminb\\.org\\)\\|\\(amin@bandali\\.me\\)\\|\\(\\(aminb?\\|mab\\|bandali\\)@gnu\\.org\\)\\|\\(\\(m\\|a\\(min\\.\\)?\\)bandali@uwaterloo\\.ca\\)\\)"
2304 message-user-fqdn "aminb.org")
2305 :hook (;; (message-setup . mml-secure-message-sign-pgpmime)
2306 (message-mode . flyspell-mode)
2307 (message-mode . (lambda ()
2308 ;; (setq fill-column 65
2309 ;; message-fill-column 65)
2310 (make-local-variable 'company-idle-delay)
2311 (setq company-idle-delay 0.2))))
2313 ;; (message-header-subject ((t (:foreground "#111" :weight semi-bold))))
2314 ;; (message-header-to ((t (:foreground "#111" :weight normal))))
2315 ;; (message-header-cc ((t (:foreground "#333" :weight normal))))
2318 (with-eval-after-load 'mml-sec
2319 (setq mml-secure-openpgp-encrypt-to-self t
2320 mml-secure-openpgp-sign-with-sender t))
2325 Convenient footnotes in =message-mode=.
2327 #+begin_src emacs-lisp
2328 (use-feature footnote
2331 (:map message-mode-map
2332 :prefix-map a/footnote-prefix-map
2334 ("a" . footnote-add-footnote)
2335 ("b" . footnote-back-to-message)
2336 ("c" . footnote-cycle-style)
2337 ("d" . footnote-delete-footnote)
2338 ("g" . footnote-goto-footnote)
2339 ("r" . footnote-renumber-footnotes)
2340 ("s" . footnote-set-style))
2342 (setq footnote-start-tag ""
2344 footnote-style 'unicode))
2349 #+begin_src emacs-lisp
2351 :straight (:host github :repo "girzel/ebdb")
2354 :bind (:map gnus-group-mode-map ("e" . ebdb))
2356 (setq ebdb-sources (no-littering-expand-var-file-name "ebdb"))
2357 (with-eval-after-load 'swiper
2358 (add-to-list 'swiper-font-lock-exclude 'ebdb-mode t)))
2360 (use-feature ebdb-com
2363 ;; (use-package ebdb-complete
2366 ;; (ebdb-complete-enable))
2368 (use-package company-ebdb
2371 (defun company-ebdb--post-complete (_) nil))
2373 (use-feature ebdb-gnus
2378 (ebdb-gnus-window-configuration
2381 (summary 0.25 point)
2384 (ebdb-gnus 0.3))))))
2386 (use-feature ebdb-mua
2390 ;; :custom (ebdb-mua-pop-up nil)
2393 ;; (use-package ebdb-message
2397 ;; (use-package ebdb-vcard
2401 ** COMMENT message-x
2403 #+begin_src emacs-lisp
2404 (use-package message-x
2406 (message-x-completion-alist
2408 (("\\([rR]esent-\\|[rR]eply-\\)?[tT]o:\\|[bB]?[cC][cC]:" . gnus-harvest-find-address)
2411 (quote message-newgroups-header-regexp))
2412 message-newgroups-header-regexp message-newsgroups-header-regexp)
2413 . message-expand-group)))))
2416 ** COMMENT gnus-harvest
2418 #+begin_src emacs-lisp
2419 (use-package gnus-harvest
2420 :commands gnus-harvest-install
2423 (if (featurep 'message-x)
2424 (gnus-harvest-install 'message-x)
2425 (gnus-harvest-install)))
2430 :CUSTOM_ID: blogging
2433 ** [[https://ox-hugo.scripter.co][ox-hugo]]
2435 #+begin_src emacs-lisp
2436 (use-package ox-hugo
2439 (use-feature ox-hugo-auto-export
2443 * Post initialization
2445 :CUSTOM_ID: post-initialization
2448 Display how long it took to load the init file.
2450 #+begin_src emacs-lisp
2451 (message "Loading %s...done (%.3fs)" user-init-file
2452 (float-time (time-subtract (current-time)
2453 a/before-user-init-time)))
2461 #+begin_src emacs-lisp :comments none
2462 ;;; init.el ends here
2465 * COMMENT Local Variables :ARCHIVE:
2467 # eval: (add-hook 'after-save-hook #'a/async-babel-tangle 'append 'local)
2468 # eval: (when (featurep 'typo (typo-mode -1)))