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 A Code" :size 16)
51 doom-variable-pitch-font (font-spec :family "Triplicate A Code" :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{{- if eq .theme_variant "dark"}}
59(setq doom-theme 'doom-dracula)
60{{- end }}
61{{- if eq .theme_variant "light"}}
62(setq doom-theme 'doom-one-light)
63{{- end }}
64#+END_SRC
65
66This determines the style of line numbers in effect. Disable line numbers by
67setting it this to ~nil~. For relative line numbers, set this to ~relative~.
68#+BEGIN_SRC emacs-lisp
69(setq display-line-numbers-type t)
70#+END_SRC
71
72Keep point in about the centre of the screen
73#+BEGIN_SRC emacs-lisp
74(use-package smooth-scrolling
75 :ensure t
76 :config
77 (smooth-scrolling-mode 1)
78 (setq smooth-scroll-margin 20))
79#+END_SRC
80
81Use fancy lambdas
82#+BEGIN_SRC emacs-lisp
83(global-prettify-symbols-mode t)
84#+END_SRC
85
86When splitting windows, I want to switch to the new one immediately. By default,
87you have to press a few bindings. This makes that automatic.
88#+BEGIN_SRC emacs-lisp
89(defun amo/split-window-below-and-switch ()
90 "Split the window horizontally, then switch to the new pane."
91 (interactive)
92 (split-window-below)
93 (balance-windows)
94 (other-window 1))
95(defun amo/split-window-right-and-switch ()
96 "Split the window vertically, then switch to the new pane."
97 (interactive)
98 (split-window-right)
99 (balance-windows)
100 (other-window 1))
101(global-set-key (kbd "C-x 2") 'amo/split-window-below-and-switch)
102(global-set-key (kbd "C-x 3") 'amo/split-window-right-and-switch)
103#+END_SRC
104
105** LSP Settings
106#+BEGIN_SRC emacs-lisp
107(setq lsp-ui-doc-max-height 13)
108(setq lsp-ui-doc-show-with-cursor t)
109#+END_SRC
110
111* Org Mode settings
112If you use ~org~ and don't want your org files in the default location below,
113change ~org-directory~. It must be set before org loads!
114#+BEGIN_SRC emacs-lisp
115(setq org-directory "~/Org/")
116#+END_SRC
117
118Prettify bullets
119#+BEGIN_SRC emacs-lisp
120(use-package org-bullets
121 :init
122 (add-hook 'org-mode-hook 'org-bullets-mode))
123#+END_SRC
124
125Replace ellipsis with downward-pointing arrow
126#+BEGIN_SRC emacs-lisp
127(setq org-ellipsis " ⤵")
128#+END_SRC
129
130Format Org text and hide markers
131#+BEGIN_SRC emacs-lisp
132(setq org-hide-emphasis-markers t)
133#+END_SRC
134
135Prevent Emacs from indenting Org headers
136#+BEGIN_SRC emacs-lisp
137(setq org-adapt-indentation nil)
138#+END_SRC
139
140Allow export to Markdown and Beamer (for presentations).
141#+BEGIN_SRC emacs-lisp
142(require 'ox-md)
143(require 'ox-beamer)
144#+END_SRC
145
146Don't ask before evaluating code blocks
147#+BEGIN_SRC emacs-lisp
148(setq org-confirm-babel-evaluate nil)
149#+END_SRC
150
151Use =htmlize= to ensure that exported code blocks use syntax highlighting.
152#+BEGIN_SRC emacs-lisp
153(use-package htmlize)
154#+END_SRC
155
156Translate regular old straight quotes to typographically-correct curly quotes
157when exporting.
158#+BEGIN_SRC emacs-lisp
159(setq org-export-with-smart-quotes t)
160#+END_SRC
161
162Add ~ox-hugo~ for exporting ~blog.org~ files to Hugo-compatible markdown
163#+BEGIN_SRC emacs-lisp
164(use-package ox-hugo
165 :ensure t
166 :after ox)
167#+END_SRC
168
169* Email configuration
170
171Attempt to load encrypted config (doesn't work for some reason)
172
173#+INCLUDE: "~/.doom.d/extra/mu4e-config.el" src emacs-lisp
174
175* Other environments
176
177Use ~mail-mode~ for syntax highlighting and bindings in neomutt compositions
178#+BEGIN_SRC emacs-lisp
179(add-to-list 'auto-mode-alist '("/tmp/neomutt-*" . mail-mode))
180#+END_SRC
181
182Always use =pdflatex= when compiling LaTeX documents. I don't really have any use
183for DVIs.
184#+BEGIN_SRC emacs-lisp
185(setq TeX-PDF-mode t)
186#+END_SRC
187
188** Music
189I've taken to charting my guitar music out with [[https://www.chordpro.org][ChordPro]]. [[https://github.com/sciurius/chordpro-mode][Chordpro mode]] just
190adds a major mode for syntax highlighting and some keybinds.
191#+BEGIN_SRC emacs-lisp
192(setq auto-mode-alist (cons '("\\.cho$" . chordpro-mode) auto-mode-alist))
193(autoload 'chordpro-mode "chordpro-mode")
194#+END_SRC
195
196I use [[https://lilypond.org/][LilyPond]] for writing standard sheet music. When you install the package,
197it comes with some elisp files that Emacs needs to load and configure.
198#+BEGIN_SRC emacs-lisp
199(require 'lilypond-mode)
200(add-to-list 'auto-mode-alist '("\\.ly$" . LilyPond-mode))
201;; Set PDF viewer to zathura, my personal preference
202(setq LilyPond-pdf-command "zathura")
203#+END_SRC
204
205** General prose settings
206Define prose modes for enabling prose-related niceties
207#+BEGIN_SRC emacs-lisp
208(defvar prose-modes
209 '(gfm-mode
210 git-commit-mode
211 markdown-mode
212 message-mode
213 mail-mode
214 org-mode
215 text-mode))
216(defvar prose-mode-hooks
217 (mapcar (lambda (mode) (intern (format "%s-hook" mode)))
218 prose-modes))
219#+END_SRC
220
221Enable spell-checking for all prose-related modes
222#+BEGIN_SRC emacs-lisp
223(use-package flyspell
224 :config
225 (dolist (hook prose-mode-hooks)
226 (add-hook hook 'flyspell-mode)))
227#+END_SRC
228
229Wrap prose paragraphs automatically
230#+BEGIN_SRC emacs-lisp
231(dolist (hook prose-mode-hooks)
232 (add-hook hook 'turn-on-auto-fill))
233#+END_SRC
234
235- Associate ~.md~ files with GitHub-flavoured Markdown
236- Use ~pandoc~ to render the results
237- Apply syntax highlighting in code blocks
238#+BEGIN_SRC emacs-lisp
239(use-package markdown-mode
240 :commands gfm-mode
241 :mode (("\\.md$" . gfm-mode))
242 :config
243 (custom-set-faces
244 '(markdown-pre-face ((t nil))))
245 (setq markdown-command "pandoc --standalone --mathjax --from=markdown"
246 markdown-fontify-code-blocks-natively t))
247 #+END_SRC
248
249Add a path both to the ~$PATH~ variable and to Emacs' exec-path
250#+BEGIN_SRC emacs-lisp
251(defun amo/append-to-path (path)
252 (setenv "PATH" (concat (getenv "PATH") ":" path))
253 (add-to-list 'exec-path path))
254#+END_SRC
255
256Look for various executables
257#+BEGIN_SRC emacs-lisp
258(amo/append-to-path "/usr/local/bin")
259(amo/append-to-path "~/.local/bin")
260#+END_SRC
261
262** Python settings
263#+BEGIN_SRC emacs-lisp
264(add-hook 'python-mode-hook 'auto-virtualenv-set-virtualenv)
265#+END_SRC
266
267** Go settings
268#+BEGIN_SRC emacs-lisp
269(gofmt-before-save)
270(setq lsp-go-use-placeholders nil)
271(setq lsp-go-link-target "godocs.io")
272(setq lsp-go-use-gofumpt t)
273;;(setq lsp-go-build-flags ["mage"])
274#+END_SRC
275
276** SuperCollider
277#+BEGIN_SRC emacs-lisp
278(require 'sclang)
279(add-hook 'sclang-mode-hook 'sclang-extensions-mode)
280#+END_SRC
281
282** TidalCycles
283#+BEGIN_SRC emacs-lisp
284(setq tidal-boot-script-path "/usr/share/x86_64-linux-ghc-9.0.2/tidal-1.7.10/BootTidal.hs")
285#+END_SRC
286
287** Tree-sitter
288#+BEGIN_SRC emacs-lisp
289(global-tree-sitter-mode)
290(add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode)
291#+END_SRC
292
293** Editor metrics
294[[https://github.com/wakatime/wakatime-mode][wakatime-mode]] connected to self-hosted [[https://wakapi.dev/][Wakapi]] instance to get interesting stats
295about the time I spend in an editor
296
297#+BEGIN_SRC emacs-lisp
298(global-wakatime-mode)
299(setq wakatime-cli-path "/usr/bin/wakatime")
300#+END_SRC
301
302* Custom bindings
303Following established Doom conventions, bind ~SPC g p~ to
304~magit-push-current-to-upstream~
305
306#+BEGIN_SRC emacs-lisp
307(map! :leader :desc "Push upstream" "g p" #'magit-push-current-to-upstream)
308#+END_SRC