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{{- 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#+BEGIN_SRC emacs-lisp
170(use-package helm-bibtex
171  :custom
172  (helm-bibtex-bibliography '("~/Documents/citations.bib"))
173  (reftex-default-bibliography '("~/Documents/citations.bib"))
174  (bibtex-completion-pdf-field "file")
175  :hook (Tex . (lambda () (define-key Tex-mode-map "\C-ch" 'helm-bibtex))))
176(use-package org-ref
177  :custom
178  (org-ref-default-bibliography "~/Documents/citations.bib"))
179(defun org-export-latex-no-toc (depth)
180  (when depth
181    (format "%% Org-mode is exporting headings to %s levels.\n"
182            depth)))
183(setq org-export-latex-format-toc-function 'org-export-latex-no-toc)
184(add-to-list 'org-latex-classes
185             '("apa6"
186               "\\documentclass{apa6}"
187               ("\\section{%s}" . "\\section*{%s}")
188               ("\\subsection{%s}" . "\\subsection*{%s}")
189               ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
190               ("\\paragraph{%s}" . "\\paragraph*{%s}")
191               ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
192(setq org-latex-pdf-process
193      '("latexmk -pdflatex='pdflatex -interaction nonstopmode' -pdf -bibtex -f %f"))
194#+END_SRC
195
196* Email configuration
197
198Attempt to load encrypted config (doesn't work for some reason)
199
200#+INCLUDE: "~/.doom.d/extra/mu4e-config.el" src emacs-lisp
201
202* Other environments
203
204Use ~mail-mode~ for syntax highlighting and bindings in neomutt compositions
205#+BEGIN_SRC emacs-lisp
206(add-to-list 'auto-mode-alist '("/tmp/neomutt-*" . mail-mode))
207#+END_SRC
208
209Always use =pdflatex= when compiling LaTeX documents. I don't really have any use
210for DVIs.
211#+BEGIN_SRC emacs-lisp
212(setq TeX-PDF-mode t)
213#+END_SRC
214
215** Music
216I've taken to charting my guitar music out with [[https://www.chordpro.org][ChordPro]]. [[https://github.com/sciurius/chordpro-mode][Chordpro mode]] just
217adds a major mode for syntax highlighting and some keybinds.
218#+BEGIN_SRC emacs-lisp
219(setq auto-mode-alist (cons '("\\.cho$" . chordpro-mode) auto-mode-alist))
220(autoload 'chordpro-mode "chordpro-mode")
221#+END_SRC
222
223I use [[https://lilypond.org/][LilyPond]] for writing standard sheet music. When you install the package,
224it comes with some elisp files that Emacs needs to load and configure.
225#+BEGIN_SRC emacs-lisp
226(require 'lilypond-mode)
227(add-to-list 'auto-mode-alist '("\\.ly$" . LilyPond-mode))
228;; Set PDF viewer to zathura, my personal preference
229(setq LilyPond-pdf-command "zathura")
230#+END_SRC
231
232** General prose settings
233Define prose modes for enabling prose-related niceties
234#+BEGIN_SRC emacs-lisp
235(defvar prose-modes
236  '(gfm-mode
237    git-commit-mode
238    markdown-mode
239    message-mode
240    mail-mode
241    org-mode
242    text-mode))
243(defvar prose-mode-hooks
244  (mapcar (lambda (mode) (intern (format "%s-hook" mode)))
245          prose-modes))
246#+END_SRC
247
248Enable spell-checking for all prose-related modes
249#+BEGIN_SRC emacs-lisp
250(use-package flyspell
251  :config
252  (dolist (hook prose-mode-hooks)
253    (add-hook hook 'flyspell-mode)))
254#+END_SRC
255
256Wrap prose paragraphs automatically
257#+BEGIN_SRC emacs-lisp
258(dolist (hook prose-mode-hooks)
259  (add-hook hook 'turn-on-auto-fill))
260#+END_SRC
261
262- Associate ~.md~ files with GitHub-flavoured Markdown
263- Use ~pandoc~ to render the results
264- Apply syntax highlighting in code blocks
265#+BEGIN_SRC emacs-lisp
266(use-package markdown-mode
267  :commands gfm-mode
268  :mode (("\\.md$" . gfm-mode))
269  :config
270  (custom-set-faces
271   '(markdown-pre-face ((t nil))))
272  (setq markdown-command "pandoc --standalone --mathjax --from=markdown"
273        markdown-fontify-code-blocks-natively t))
274  #+END_SRC
275
276Add a path both to the ~$PATH~ variable and to Emacs' exec-path
277#+BEGIN_SRC emacs-lisp
278(defun amo/append-to-path (path)
279  (setenv "PATH" (concat (getenv "PATH") ":" path))
280  (add-to-list 'exec-path path))
281#+END_SRC
282
283Look for various executables
284#+BEGIN_SRC emacs-lisp
285(amo/append-to-path "/usr/local/bin")
286(amo/append-to-path "~/.local/bin")
287#+END_SRC
288
289** Python settings
290#+BEGIN_SRC emacs-lisp
291(add-hook 'python-mode-hook 'auto-virtualenv-set-virtualenv)
292#+END_SRC
293
294** Go settings
295#+BEGIN_SRC emacs-lisp
296(gofmt-before-save)
297(setq lsp-go-use-placeholders nil)
298(setq lsp-go-link-target "godocs.io")
299(setq lsp-go-use-gofumpt t)
300;;(setq lsp-go-build-flags ["mage"])
301#+END_SRC
302
303** SuperCollider
304#+BEGIN_SRC emacs-lisp
305(require 'sclang)
306(add-hook 'sclang-mode-hook 'sclang-extensions-mode)
307#+END_SRC
308
309** TidalCycles
310#+BEGIN_SRC emacs-lisp
311(setq tidal-boot-script-path "/usr/share/x86_64-linux-ghc-9.0.2/tidal-1.7.10/BootTidal.hs")
312#+END_SRC
313
314** Tree-sitter
315#+BEGIN_SRC emacs-lisp
316(global-tree-sitter-mode)
317(add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode)
318#+END_SRC
319
320** Editor metrics
321[[https://github.com/wakatime/wakatime-mode][wakatime-mode]] connected to self-hosted [[https://wakapi.dev/][Wakapi]] instance to get interesting stats
322about the time I spend in an editor
323
324#+BEGIN_SRC emacs-lisp
325(global-wakatime-mode)
326(setq wakatime-cli-path "/usr/bin/wakatime")
327#+END_SRC
328
329** Magit
330
331Use git flow in magit status buffers
332#+BEGIN_SRC emacs-lisp
333(add-hook 'magit-mode-hook 'turn-on-magit-gitflow)
334#+END_SRC
335
336* Custom bindings
337Following established Doom conventions, bind ~SPC g p~ to
338~magit-push-current-to-upstream~
339
340#+BEGIN_SRC emacs-lisp
341(map! :leader :desc "Push upstream" "g p" #'magit-push-current-to-upstream)
342#+END_SRC
343
344* Copilot
345#+BEGIN_SRC emacs-lisp
346(use-package! copilot
347  :hook (prog-mode . copilot-mode)
348  :bind (("C-TAB" . 'copilot-accept-completion-by-word)
349         ("C-<tab>" . 'copilot-accept-completion-by-word)
350         :map copilot-completion-map
351         ("<tab>" . 'copilot-accept-completion)
352         ("TAB" . 'copilot-accept-completion)))
353#+END_SRC