Over at the Emacs reddit, tiktaaliki asks how he can put his init.el file in Org format. As it turns out, I learned some really useful things from the post. First off, the easy answer to that question is to watch Mike Zamansky’s video on org init files. It good for beginners because it’s part of his series on building an Emacs configuration and at the point in the video, the configuration is still pretty simple and you won’t get bogged down in details. I particularly like his simple boot strapper. Once you watch the video, you can take a look at some full-blown examples such as this one from Sacha or this one from Grant Rettke.
Grant has a comment in which he remarks that he prefers to tangle the Org file manually. In it he mentions the function org-babel-demarcate-block
(bound to Ctrl+c Ctrl+v d) that’s a big help in refactoring an existing init.el
into an Org based init. If there’s an active region, org-babel-demarcate-block
will wrap it with BEGIN_SRC, END_SRC tags doing the correct thing if the region is already in a source block. If you call org-babel-demarcate-block
from within a source block with no region, it will split the block at that point into two separate source blocks. If you specify the universal argument, it will also insert a heading between the blocks.
This makes it really easy to quickly break up an existing init.el
into separate Babel source blocks that form the basis of an Org init file. One possible strategy is to take your init.el
and break it up into separate source blocks. Then you can fill in the narrative at your leisure.
Finally, I found a nice use case for narrowing. The documentation for org-babel-demarcate-block
is a bit lacking. In particular, although it takes an argument, the documentation doesn’t say what that argument, ARG
, does. I could have just searched for the symbol arg
but I would have gotten lots of hits. Instead, I simply called narrow-or-widen-dwim, which narrowed to the org-babel-demarcate-block
function and then searched. That got only 3 hits and it was easy to see that when it was non-nil the function inserts a header.
UPDATE org-babel-demarcate-blog
→ org-babel-demarcate-block