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