github twitter linkedin hacker news goodreads angel list email pgp key rss
Fold Anything with Emacs Yafolding

I capture my notes on books that I read as org files and publish that as my bookshelf. My script grabs a lot of metadata from goodreads.com and inserts it into the org file as Hugofront matter”. The layout specifies how this structured metadata is to be rendered for the web as static html files.

This is great because the data is structured and it is all there and I can pick and choose what I want to display and do other interesting things with it. But the problem is, having a huge json formatted data sitting at the top of the org file is distracting while I take notes on the book.

This isn’t a code file, so there isn’t a code folding function available unlike, say, when I’m editing a Python file. I can’t delimit the metadata into an org-mode code block and handle as code either because Hugo won’t understand that.

Since it’s Emacs, of course there is a solution for this: yafolding

There are several folding extensions available actually… hence the name “yafolding”, which stands for “yet another folding extension”. But yafolding is really cool because it can fold by indentation depth. So it works on any text.

I mapped yafolding-toggle-all to the key chord z. with:

(key-chord-define-global "z." 'yafolding-toggle-all)

and I’m really happy to fold the long metadata into just a {...} at will by hitting z and . together and take notes on books without any distractions.