Endless Parentheses

Ramblings on productivity and technical subjects.

profile for Malabarba on Stack Exchange

init.org Without org-mode

About the Blog post series

When I decided to share my limited wisdom, I realized I’d need something better than a 4-year-old, thrown together, init file. The words “init dot org” had crossed my ears through one of Sacha Chua’s previous videos; however, due to 63m of water above my head, internet searches weren’t quite operating at top efficiency.

Without a second thought, and armed with nothing but its name (init.org), I took to writing —I thought at the moment— the simplest way of implementing such a feature.

;;; init.el
(defvar endless/init.org-message-depth 3
  "What depth of init.org headers to message at startup.")

  (insert-file "~/.emacs.d/init.org")
  (goto-char (point-min))
  (search-forward "\n* init.el")
  (while (not (eobp))
    (forward-line 1)
     ;; Report Headers
       (format "\\*\\{2,%s\\} +.*$" 
      (message "%s" (match-string 0)))
     ;; Evaluate Code Blocks
     ((looking-at "^#\\+BEGIN_SRC +emacs-lisp *$")
      (let ((l (match-end 0)))
        (search-forward "\n#+END_SRC")
        (eval-region l (match-beginning 0))))
     ;; Finish on the next level-1 header
     ((looking-at "^\\* ")
      (goto-char (point-max))))))

Once back within the range of cell towers, a quick search revealed it could have been slightly shorter.

(require 'org)
 (expand-file-name "emacs-init.org"

Nonetheless, I stuck with my guns and kept the first version. Primarily for stubbornness, but also a few other reasons:

Fine grained control
I can choose exactly what gets evaluated. In this case, anything inside the init.el header. This is important because this blog is my init file, and I don’t want to evaluate everything I post.
Lots of messaging
It calls message on each header it finds (up to a configurable level). Whenever something goes wrong, forget about restarting with --debug-init, the messages buffer tells me exactly where it happened.
It doesn’t (require 'org)
This might sound silly, but that inconspicuous line forms one of the most time-consuming statements you could possibly write. I’d challenge anyone to find a 14-character statement that takes longer than that (other than an empty loop or a sleep command, of course).
comments powered by Disqus