1#+TITLE: Literate Doom Emacs config
2#+AUTHOR: Amolith
3
4-----
5
6*Note:* you do not need to run ~doom sync~ after modifying this file!
7
8-----
9
10Here are some additional functions/macros that could help configure Doom:
11
12- ~load!~ for loading external ~*.el~ files relative to this one
13- ~use-package!~ for configuring packages
14- ~after!~ for running code after a package has loaded
15- ~add-load-path!~ for adding directories to the ~load-path~, relative to
16 this file. Emacs searches the ~load-path~ when loading packages with
17 ~require~ or ~use-package~.
18- ~map!~ for binding new keys
19
20To get information about any of these functions/macros, move the cursor over the
21highlighted symbol at press ~K~ (non-evil users must press ~C-c c k~). This will
22open documentation for it, including demos of how they're used. ~gd~ (or ~C-c c d~)
23will also jump to their definition for viewing how they're implemented.
24
25First off, enable [[https://www.emacswiki.org/emacs/DynamicBindingVsLexicalBinding][lexical binding]]:
26#+BEGIN_SRC emacs-lisp
27;;; $DOOMDIR/config.el -*- lexical-binding: t; -*-
28#+END_SRC
29
30* Identity configuration
31Some functionality uses this to identify the user, e.g. GPG configuration, email
32clients, file templates and snippets.
33#+BEGIN_SRC emacs-lisp
34(setq user-full-name "Amolith"
35 user-mail-address "amolith@secluded.site")
36#+END_SRC
37
38* UI settings
39Doom exposes five (optional) variables for controlling fonts in Doom. Here
40are the three important ones:
41
42+ ~doom-font~
43+ ~doom-variable-pitch-font~
44+ ~doom-big-font~ — used for ~doom-big-font-mode~; use this for
45 presentations or streaming.
46
47They all accept either a font-spec, font string (~"Input Mono-12"~), or ~xlfd~
48font string. Generally, only these two are needed:
49#+BEGIN_SRC emacs-lisp
50(setq doom-font (font-spec :family "Triplicate T4c" :size 16)
51 doom-variable-pitch-font (font-spec :family "Valkyrie T4" :size 16))
52#+END_SRC
53
54There are two ways to load a theme. Both assume the theme is installed and
55available. Either set ~doom-theme~ or manually load a theme with the ~load-theme~
56function.
57#+BEGIN_SRC emacs-lisp
58(setq doom-theme 'doom-dracula)
59#+END_SRC
60
61This determines the style of line numbers in effect. Disable line numbers by
62setting it this to ~nil~. For relative line numbers, set this to ~relative~.
63#+BEGIN_SRC emacs-lisp
64(setq display-line-numbers-type t)
65#+END_SRC
66
67Keep point in about the centre of the screen
68#+BEGIN_SRC emacs-lisp
69(use-package smooth-scrolling
70 :ensure t
71 :config
72 (smooth-scrolling-mode 1)
73 (setq smooth-scroll-margin 20))
74#+END_SRC
75
76Use fancy lambdas
77#+BEGIN_SRC emacs-lisp
78(global-prettify-symbols-mode t)
79#+END_SRC
80
81When splitting windows, I want to switch to the new one immediately. By default,
82you have to press a few bindings. This makes that automatic.
83#+BEGIN_SRC emacs-lisp
84(defun amo/split-window-below-and-switch ()
85 "Split the window horizontally, then switch to the new pane."
86 (interactive)
87 (split-window-below)
88 (balance-windows)
89 (other-window 1))
90(defun amo/split-window-right-and-switch ()
91 "Split the window vertically, then switch to the new pane."
92 (interactive)
93 (split-window-right)
94 (balance-windows)
95 (other-window 1))
96(global-set-key (kbd "C-x 2") 'amo/split-window-below-and-switch)
97(global-set-key (kbd "C-x 3") 'amo/split-window-right-and-switch)
98#+END_SRC
99
100* Org Mode settings
101If you use ~org~ and don't want your org files in the default location below,
102change ~org-directory~. It must be set before org loads!
103#+BEGIN_SRC emacs-lisp
104(setq org-directory "~/Org/")
105#+END_SRC
106
107Prettify bullets
108#+BEGIN_SRC emacs-lisp
109(use-package org-bullets
110 :init
111 (add-hook 'org-mode-hook 'org-bullets-mode))
112#+END_SRC
113
114Replace ellipsis with downward-pointing arrow
115#+BEGIN_SRC emacs-lisp
116(setq org-ellipsis " ⤵")
117#+END_SRC
118
119Format Org text and hide markers
120#+BEGIN_SRC emacs-lisp
121(setq org-hide-emphasis-markers t)
122#+END_SRC
123
124Prevent Emacs from indenting Org headers
125#+BEGIN_SRC emacs-lisp
126(setq org-adapt-indentation nil)
127#+END_SRC
128
129Allow export to Markdown and Beamer (for presentations).
130#+BEGIN_SRC emacs-lisp
131(require 'ox-md)
132(require 'ox-beamer)
133#+END_SRC
134
135Don't ask before evaluating code blocks
136#+BEGIN_SRC emacs-lisp
137(setq org-confirm-babel-evaluate nil)
138#+END_SRC
139
140Use =htmlize= to ensure that exported code blocks use syntax highlighting.
141#+BEGIN_SRC emacs-lisp
142(use-package htmlize)
143#+END_SRC
144
145Translate regular old straight quotes to typographically-correct curly quotes
146when exporting.
147#+BEGIN_SRC emacs-lisp
148(setq org-export-with-smart-quotes t)
149#+END_SRC
150
151Add ~ox-hugo~ for exporting ~blog.org~ files to Hugo-compatible markdown
152#+BEGIN_SRC emacs-lisp
153(use-package ox-hugo
154 :ensure t
155 :after ox)
156#+END_SRC
157
158* Other environments
159
160Use ~mail-mode~ for syntax highlighting and bindings in neomutt compositions
161#+BEGIN_SRC emacs-lisp
162(add-to-list 'auto-mode-alist '("/tmp/neomutt-*" . mail-mode))
163#+END_SRC
164
165Always use =pdflatex= when compiling LaTeX documents. I don't really have any use
166for DVIs.
167#+BEGIN_SRC emacs-lisp
168(setq TeX-PDF-mode t)
169#+END_SRC
170
171** Music
172I've taken to charting my guitar music out with [[https://www.chordpro.org][ChordPro]]. [[https://github.com/sciurius/chordpro-mode][Chordpro mode]] just
173adds a major mode for syntax highlighting and some keybinds.
174#+BEGIN_SRC emacs-lisp
175(setq auto-mode-alist (cons '("\\.cho$" . chordpro-mode) auto-mode-alist))
176(autoload 'chordpro-mode "chordpro-mode")
177#+END_SRC
178
179I use [[https://lilypond.org/][LilyPond]] for writing standard sheet music. When you install the package,
180it comes with some elisp files that Emacs needs to load and configure.
181#+BEGIN_SRC emacs-lisp
182(require 'lilypond-mode)
183(add-to-list 'auto-mode-alist '("\\.ly$" . LilyPond-mode))
184;; Set PDF viewer to zathura, my personal preference
185(setq LilyPond-pdf-command "zathura")
186#+END_SRC
187
188** General prose settings
189Define prose modes for enabling prose-related niceties
190#+BEGIN_SRC emacs-lisp
191(defvar prose-modes
192 '(gfm-mode
193 git-commit-mode
194 markdown-mode
195 message-mode
196 mail-mode
197 org-mode
198 text-mode))
199(defvar prose-mode-hooks
200 (mapcar (lambda (mode) (intern (format "%s-hook" mode)))
201 prose-modes))
202#+END_SRC
203
204Enable spell-checking for all prose-related modes
205#+BEGIN_SRC emacs-lisp
206(use-package flyspell
207 :config
208 (dolist (hook prose-mode-hooks)
209 (add-hook hook 'flyspell-mode)))
210#+END_SRC
211
212Wrap prose paragraphs automatically
213#+BEGIN_SRC emacs-lisp
214(dolist (hook prose-mode-hooks)
215 (add-hook hook 'turn-on-auto-fill))
216#+END_SRC
217
218- Associate ~.md~ files with GitHub-flavoured Markdown
219- Use ~pandoc~ to render the results
220- Apply syntax highlighting in code blocks
221#+BEGIN_SRC emacs-lisp
222(use-package markdown-mode
223 :commands gfm-mode
224 :mode (("\\.md$" . gfm-mode))
225 :config
226 (custom-set-faces
227 '(markdown-pre-face ((t nil))))
228 (setq markdown-command "pandoc --standalone --mathjax --from=markdown"
229 markdown-fontify-code-blocks-natively t))
230 #+END_SRC
231
232Add a path both to the ~$PATH~ variable and to Emacs' exec-path
233#+BEGIN_SRC emacs-lisp
234(defun amo/append-to-path (path)
235 (setenv "PATH" (concat (getenv "PATH") ":" path))
236 (add-to-list 'exec-path path))
237#+END_SRC
238
239Look for various executables
240#+BEGIN_SRC emacs-lisp
241(amo/append-to-path "/usr/local/bin")
242(amo/append-to-path "~/.local/bin")
243#+END_SRC
244
245** Python settings
246#+BEGIN_SRC emacs-lisp
247(add-hook 'python-mode-hook 'auto-virtualenv-set-virtualenv)
248#+END_SRC
249
250** Go settings
251#+BEGIN_SRC emacs-lisp
252(gofmt-before-save)
253(setq lsp-go-use-placeholders nil)
254(setq lsp-go-link-target "godocs.io")
255(setq lsp-go-use-gofumpt t)
256;;(setq lsp-go-build-flags ["mage"])
257#+END_SRC
258
259** SuperCollider
260#+BEGIN_SRC emacs-lisp
261(require 'sclang)
262(add-hook 'sclang-mode-hook 'sclang-extensions-mode)
263#+END_SRC
264
265** TidalCycles
266#+BEGIN_SRC emacs-lisp
267(setq tidal-boot-script-path "/usr/share/x86_64-linux-ghc-9.0.2/tidal-1.7.10/BootTidal.hs")
268#+END_SRC
269
270** Tree-sitter
271#+BEGIN_SRC emacs-lisp
272(global-tree-sitter-mode)
273(add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode)
274#+END_SRC
275
276** Editor metrics
277[[https://github.com/wakatime/wakatime-mode][wakatime-mode]] connected to self-hosted [[https://wakapi.dev/][Wakapi]] instance to get interesting stats
278about the time I spend in an editor
279
280#+BEGIN_SRC emacs-lisp
281(global-wakatime-mode)
282(setq wakatime-cli-path "/usr/bin/wakatime")
283#+END_SRC
284
285* Custom bindings
286Following established Doom conventions, bind ~SPC g p~ to
287~magit-push-current-to-upstream~
288
289#+BEGIN_SRC emacs-lisp
290(map! :leader :desc "Push upstream" "g p" #'magit-push-current-to-upstream)
291#+END_SRC