Bruno Arine

Outlining Emacs init files

Today I learned that commented out Elisp code with ;;; in Emacs are interpreted as headings when you’re in outline-minor-mode. That means that you can create hierarchical headings (e.g. one level is ;;;, two levels is ;;;;), and you can fold each heading with outline-cycle.

Since when I migrated my workflow to Doom Emacs, my custom configuration file grew out of control. One way to handle its content more easily was to separate chunks of the file with comment blocks like this:

;;; ==============================
;;; org-mode related config
;;; ==============================

Then today I stumbled upon Protesilaos’s video, in which he speaks about Emacs’ super convenient outline-minor-mode. He goes on and suggests also that Emacs init files can also be organized via literate programming with Org-mode (i.e. you write one thoroughly descriptive org-file with Elisp code in source blocks, and let Emacs generate the config files for you). However, outlining my Doom Emacs config.el file with triple semi-colons are sufficient for me.

Once I finished creating outline sections for my custom config files, because I’m using Doom Emacs the TAB key was mapped to evil-jump-item, so I had to re-map it if I wanted to fold the headings with it. I also bind consult-outline to SPC m . (the same keybinding for consulting Org-mode outlines).

(map! :map outline-minor-mode-map
      :n "<tab>" #'outline-cycle
      :n "SPC m ." #'consult-outline)

Related Posts