Literate Programming my Emacs Config

Inspired by Sacha Chua, I decided to move my Emacs configuration into an Org Mode file. This lets me organize things nicely and keep notes…

Literate Programming my Emacs Config

Inspired by Sacha Chua, I decided to move my Emacs configuration into an Org Mode file. This lets me organize things nicely and keep notes about my progress, as I’m still learning a lot.

I use Spacemacs and keep all of my customizations in ~/.spacemacs.d/ so that ~/.emacs.d/ can belong entirely to the Spacemacs installation. My init.el file had grown a bit unwieldy, so I was looking forward to the opportunity to tidy things up.

First, I created a new file named jack.org, and copied all of my customizations into it. Then I wrapped each section in a SRC block so I could “tangle” it using Babel. Then I added Org headings around each section and rearranged the sections so they made sense, at least to me. Here’s a snippet…

*** Custom Agenda Commands
#+BEGIN_SRC emacs-lisp :tangle yes
(setq org-agenda-custom-commands
(append '(("c" "Waiting for Client" tags-todo "Client")
("w" "Waiting" todo "WAIT" nil)
("p" "Active Projects" tags "project/-DONE-CANC" nil)
("Q" tags "questions")
("b" tags "bought")
("l" tags "Links")
("v" tags-todo "Events"))))
#+END_SRC
*** Capture Templates
#+BEGIN_SRC emacs-lisp :tangle yes
(setq org-capture-templates
'(("t" "Todo" entry
(file+headline "~/org/todo.org" "Inbox")
"* TODO %? \n %i\n")
(with-eval-after-load 'org-capture
(add-hook 'org-capture-mode-hook 'evil-insert-state))
#+END_SRC

Now, whenever I update something in jack.org I just press C-c C-v t and all of the SRC blocks are rendered out to a file named jack.el

Spacemacs’ init.el file contains things I don’t know how to move, so I kept that file in place and I simply load my customizations into the appropriate section, like this…

(defun dotspacemacs/user-config ()
"Configuration function for user codeThis function is called at the very end of Spacemacs initialization afterlayers configuration.This is the place where most of your configurations should be done. Unless it is explicitly specified that a variable should be set before a package is loaded, you should place your code here."
(load "~/Dropbox/Sync/dotfiles/spacemacs.d/jack.el")
)

I don’t know if that was the best way of doing things, but it worked. Having my entire configuration as an Org Mode file is pretty nice. I’m finding it to be much easier to manage and it’s made me less nervous about cluttering things up in the future.

I’ve uploaded a copy of my configuration for anyone interested.


Originally published at baty.net on December 27, 2016.