config.org.tmpl

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