config.org

  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 "Valkyrie T4" :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 'rose-pine-moon)
 59#+END_SRC
 60
 61This determines the style of line numbers in effect. Disable line numbers by
 62setting it this to ~nil~. For relative line numbers, set this to ~relative~.
 63#+BEGIN_SRC emacs-lisp
 64(setq display-line-numbers-type t)
 65#+END_SRC
 66
 67Keep point in about the centre of the screen
 68#+BEGIN_SRC emacs-lisp
 69(use-package smooth-scrolling
 70  :ensure t
 71  :config
 72  (smooth-scrolling-mode 1)
 73  (setq smooth-scroll-margin 20))
 74#+END_SRC
 75
 76Use fancy lambdas
 77#+BEGIN_SRC emacs-lisp
 78(global-prettify-symbols-mode t)
 79#+END_SRC
 80
 81When splitting windows, I want to switch to the new one immediately. By default,
 82you have to press a few bindings. This makes that automatic.
 83#+BEGIN_SRC emacs-lisp
 84(defun amo/split-window-below-and-switch ()
 85  "Split the window horizontally, then switch to the new pane."
 86  (interactive)
 87  (split-window-below)
 88  (balance-windows)
 89  (other-window 1))
 90(defun amo/split-window-right-and-switch ()
 91  "Split the window vertically, then switch to the new pane."
 92  (interactive)
 93  (split-window-right)
 94  (balance-windows)
 95  (other-window 1))
 96(global-set-key (kbd "C-x 2") 'amo/split-window-below-and-switch)
 97(global-set-key (kbd "C-x 3") 'amo/split-window-right-and-switch)
 98#+END_SRC
 99
100
101* Org Mode settings
102If you use ~org~ and don't want your org files in the default location below,
103change ~org-directory~. It must be set before org loads!
104#+BEGIN_SRC emacs-lisp
105(setq org-directory "~/Org/")
106#+END_SRC
107
108Prettify bullets
109#+BEGIN_SRC emacs-lisp
110(use-package org-bullets
111  :init
112  (add-hook 'org-mode-hook 'org-bullets-mode))
113#+END_SRC
114
115Replace ellipsis with downward-pointing arrow
116#+BEGIN_SRC emacs-lisp
117(setq org-ellipsis "")
118#+END_SRC
119
120Format Org text and hide markers
121#+BEGIN_SRC emacs-lisp
122(setq org-hide-emphasis-markers t)
123#+END_SRC
124
125Prevent Emacs from indenting Org headers
126#+BEGIN_SRC emacs-lisp
127(setq org-adapt-indentation nil)
128#+END_SRC
129
130Allow export to Markdown and Beamer (for presentations).
131#+BEGIN_SRC emacs-lisp
132(require 'ox-md)
133(require 'ox-beamer)
134#+END_SRC
135
136Don't ask before evaluating code blocks
137#+BEGIN_SRC emacs-lisp
138(setq org-confirm-babel-evaluate nil)
139#+END_SRC
140
141Use =htmlize= to ensure that exported code blocks use syntax highlighting.
142#+BEGIN_SRC emacs-lisp
143(use-package htmlize)
144#+END_SRC
145
146Translate regular old straight quotes to typographically-correct curly quotes
147when exporting.
148#+BEGIN_SRC emacs-lisp
149(setq org-export-with-smart-quotes t)
150#+END_SRC
151
152Add ~ox-hugo~ for exporting ~blog.org~ files to Hugo-compatible markdown
153#+BEGIN_SRC emacs-lisp
154(use-package ox-hugo
155  :ensure t
156  :after ox)
157#+END_SRC
158
159* Other environments
160
161Use ~mail-mode~ for syntax highlighting and bindings in neomutt compositions
162#+BEGIN_SRC emacs-lisp
163(add-to-list 'auto-mode-alist '("/tmp/neomutt-*" . mail-mode))
164#+END_SRC
165
166Always use =pdflatex= when compiling LaTeX documents. I don't really have any use
167for DVIs.
168#+BEGIN_SRC emacs-lisp
169(setq TeX-PDF-mode t)
170#+END_SRC
171
172** Music
173I've taken to charting my guitar music out with [[https://www.chordpro.org][ChordPro]]. [[https://github.com/sciurius/chordpro-mode][Chordpro mode]] just
174adds a major mode for syntax highlighting and some keybinds.
175#+BEGIN_SRC emacs-lisp
176(setq auto-mode-alist (cons '("\\.cho$" . chordpro-mode) auto-mode-alist))
177(autoload 'chordpro-mode "chordpro-mode")
178#+END_SRC
179
180I use [[https://lilypond.org/][LilyPond]] for writing standard sheet music. When you install the package,
181it comes with some elisp files that Emacs needs to load and configure.
182#+BEGIN_SRC emacs-lisp
183(require 'lilypond-mode)
184(add-to-list 'auto-mode-alist '("\\.ly$" . LilyPond-mode))
185;; Set PDF viewer to zathura, my personal preference
186(setq LilyPond-pdf-command "zathura")
187#+END_SRC
188
189** General prose settings
190Define prose modes for enabling prose-related niceties
191#+BEGIN_SRC emacs-lisp
192(defvar prose-modes
193  '(gfm-mode
194    git-commit-mode
195    markdown-mode
196    message-mode
197    mail-mode
198    org-mode
199    text-mode))
200(defvar prose-mode-hooks
201  (mapcar (lambda (mode) (intern (format "%s-hook" mode)))
202          prose-modes))
203#+END_SRC
204
205Enable spell-checking for all prose-related modes
206#+BEGIN_SRC emacs-lisp
207(use-package flyspell
208  :config
209  (dolist (hook prose-mode-hooks)
210    (add-hook hook 'flyspell-mode)))
211#+END_SRC
212
213Wrap prose paragraphs automatically
214#+BEGIN_SRC emacs-lisp
215(dolist (hook prose-mode-hooks)
216  (add-hook hook 'turn-on-auto-fill))
217#+END_SRC
218
219- Associate ~.md~ files with GitHub-flavoured Markdown
220- Use ~pandoc~ to render the results
221- Apply syntax highlighting in code blocks
222#+BEGIN_SRC emacs-lisp
223(use-package markdown-mode
224  :commands gfm-mode
225  :mode (("\\.md$" . gfm-mode))
226  :config
227  (custom-set-faces
228   '(markdown-pre-face ((t nil))))
229  (setq markdown-command "pandoc --standalone --mathjax --from=markdown"
230        markdown-fontify-code-blocks-natively t))
231  #+END_SRC
232
233Add a path both to the ~$PATH~ variable and to Emacs' exec-path
234#+BEGIN_SRC emacs-lisp
235(defun amo/append-to-path (path)
236  (setenv "PATH" (concat (getenv "PATH") ":" path))
237  (add-to-list 'exec-path path))
238#+END_SRC
239
240Look for various executables
241#+BEGIN_SRC emacs-lisp
242(amo/append-to-path "/usr/local/bin")
243(amo/append-to-path "~/.local/bin")
244#+END_SRC
245
246** Python settings
247#+BEGIN_SRC emacs-lisp
248(add-hook 'python-mode-hook 'auto-virtualenv-set-virtualenv)
249#+END_SRC
250
251* Custom bindings
252Following established Doom conventions, bind ~SPC g p~ to
253~magit-push-current-to-upstream~
254
255#+BEGIN_SRC emacs-lisp
256(map! :leader :desc "Push upstream" "g p" #'magit-push-current-to-upstream)
257#+END_SRC