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 T4c" :size 16)
 51      doom-variable-pitch-font (font-spec :family "Triplicate T4c" :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
171#+BEGIN_SRC emacs-lisp
172(defalias 'mu4e~start 'mu4e--start)
173(defalias 'mu4e~stop 'mu4e--stop)
174(defalias 'mu4e~check-requirements 'mu4e--check-requirements)
175(defalias 'mu4e~proc-sentinel 'mu4e--server-sentinel)
176(defalias 'mu4e~proc-start 'mu4e--server-start)
177(defalias 'mu4e~proc-eat-sexp-from-buf 'mu4e--server-eat-sexp-from-buf)
178(defalias 'mu4e~pong-handler 'mu4e--pong-handler)
179(defalias 'mu4e~main-view 'mu4e--main-view)
180(defalias 'mu4e~main-view-real 'mu4e--main-view-real)
181(defalias 'mu4e~main-view-real-1 'mu4e--main-view-real-1)
182(defalias 'mu4e~main-menu 'mu4e--main-menu)
183(defalias 'mu4e~main-action-str 'mu4e--main-action-str)
184(defalias 'mu4e~main-redraw-buffer 'mu4e--main-redraw-buffer)
185(defalias 'mu4e~proc-move 'mu4e--server-move)
186(defalias 'mu4e~mark-check-target 'mu4e--mark-check-target)
187(defalias 'mu4e~maildirs-with-query 'mu4e--maildirs-with-query)
188(defalias 'mu4e~longest-of-maildirs-and-bookmarks 'mu4e--longest-of-maildirs-and-bookmarks)
189(defalias 'mu4e~update-timer 'mu4e--update-timer)
190(defalias 'mu4e~proc-remove 'mu4e--server-remove)
191#+END_SRC
192
193Load encrypted config
194
195#+INCLUDE: "~/.doom.d/extra/mu4e-config.el" src emacs-lisp
196
197* Other environments
198
199Use ~mail-mode~ for syntax highlighting and bindings in neomutt compositions
200#+BEGIN_SRC emacs-lisp
201(add-to-list 'auto-mode-alist '("/tmp/neomutt-*" . mail-mode))
202#+END_SRC
203
204Always use =pdflatex= when compiling LaTeX documents. I don't really have any use
205for DVIs.
206#+BEGIN_SRC emacs-lisp
207(setq TeX-PDF-mode t)
208#+END_SRC
209
210** Music
211I've taken to charting my guitar music out with [[https://www.chordpro.org][ChordPro]]. [[https://github.com/sciurius/chordpro-mode][Chordpro mode]] just
212adds a major mode for syntax highlighting and some keybinds.
213#+BEGIN_SRC emacs-lisp
214(setq auto-mode-alist (cons '("\\.cho$" . chordpro-mode) auto-mode-alist))
215(autoload 'chordpro-mode "chordpro-mode")
216#+END_SRC
217
218I use [[https://lilypond.org/][LilyPond]] for writing standard sheet music. When you install the package,
219it comes with some elisp files that Emacs needs to load and configure.
220#+BEGIN_SRC emacs-lisp
221(require 'lilypond-mode)
222(add-to-list 'auto-mode-alist '("\\.ly$" . LilyPond-mode))
223;; Set PDF viewer to zathura, my personal preference
224(setq LilyPond-pdf-command "zathura")
225#+END_SRC
226
227** General prose settings
228Define prose modes for enabling prose-related niceties
229#+BEGIN_SRC emacs-lisp
230(defvar prose-modes
231  '(gfm-mode
232    git-commit-mode
233    markdown-mode
234    message-mode
235    mail-mode
236    org-mode
237    text-mode))
238(defvar prose-mode-hooks
239  (mapcar (lambda (mode) (intern (format "%s-hook" mode)))
240          prose-modes))
241#+END_SRC
242
243Enable spell-checking for all prose-related modes
244#+BEGIN_SRC emacs-lisp
245(use-package flyspell
246  :config
247  (dolist (hook prose-mode-hooks)
248    (add-hook hook 'flyspell-mode)))
249#+END_SRC
250
251Wrap prose paragraphs automatically
252#+BEGIN_SRC emacs-lisp
253(dolist (hook prose-mode-hooks)
254  (add-hook hook 'turn-on-auto-fill))
255#+END_SRC
256
257- Associate ~.md~ files with GitHub-flavoured Markdown
258- Use ~pandoc~ to render the results
259- Apply syntax highlighting in code blocks
260#+BEGIN_SRC emacs-lisp
261(use-package markdown-mode
262  :commands gfm-mode
263  :mode (("\\.md$" . gfm-mode))
264  :config
265  (custom-set-faces
266   '(markdown-pre-face ((t nil))))
267  (setq markdown-command "pandoc --standalone --mathjax --from=markdown"
268        markdown-fontify-code-blocks-natively t))
269  #+END_SRC
270
271Add a path both to the ~$PATH~ variable and to Emacs' exec-path
272#+BEGIN_SRC emacs-lisp
273(defun amo/append-to-path (path)
274  (setenv "PATH" (concat (getenv "PATH") ":" path))
275  (add-to-list 'exec-path path))
276#+END_SRC
277
278Look for various executables
279#+BEGIN_SRC emacs-lisp
280(amo/append-to-path "/usr/local/bin")
281(amo/append-to-path "~/.local/bin")
282#+END_SRC
283
284** Python settings
285#+BEGIN_SRC emacs-lisp
286(add-hook 'python-mode-hook 'auto-virtualenv-set-virtualenv)
287#+END_SRC
288
289** Go settings
290#+BEGIN_SRC emacs-lisp
291(gofmt-before-save)
292(setq lsp-go-use-placeholders nil)
293(setq lsp-go-link-target "godocs.io")
294(setq lsp-go-use-gofumpt t)
295;;(setq lsp-go-build-flags ["mage"])
296#+END_SRC
297
298** SuperCollider
299#+BEGIN_SRC emacs-lisp
300(require 'sclang)
301(add-hook 'sclang-mode-hook 'sclang-extensions-mode)
302#+END_SRC
303
304** TidalCycles
305#+BEGIN_SRC emacs-lisp
306(setq tidal-boot-script-path "/usr/share/x86_64-linux-ghc-9.0.2/tidal-1.7.10/BootTidal.hs")
307#+END_SRC
308
309** Tree-sitter
310#+BEGIN_SRC emacs-lisp
311(global-tree-sitter-mode)
312(add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode)
313#+END_SRC
314
315** Editor metrics
316[[https://github.com/wakatime/wakatime-mode][wakatime-mode]] connected to self-hosted [[https://wakapi.dev/][Wakapi]] instance to get interesting stats
317about the time I spend in an editor
318
319#+BEGIN_SRC emacs-lisp
320(global-wakatime-mode)
321(setq wakatime-cli-path "/usr/bin/wakatime")
322#+END_SRC
323
324* Custom bindings
325Following established Doom conventions, bind ~SPC g p~ to
326~magit-push-current-to-upstream~
327
328#+BEGIN_SRC emacs-lisp
329(map! :leader :desc "Push upstream" "g p" #'magit-push-current-to-upstream)
330#+END_SRC