The other day I wrote about Kaushal Modi’s post on Advice Combinators. Modi has another post that uses that information but the post is interesting in its own right. The problem is to fold (or collapse) headings having a certain property. His use case for this involves the file of his blog posts. Take a look at his post for the details.
The method Modi employs is pretty simple. He loops through all the headings with org-map-entries
calling outline-hide-subtree
whenever the property EXPORT-FILE-NAME
is set. All that is handled by the single call to org-map-entries
so it’s easy. Modi makes another pass also collapsing subtrees that are Footnotes or COMMENTS. That’s even easier being a simple re-search-forward
.
Since Ctrl+c Tab does something similar in plain Org-mode, Modi decided to call his function with the binding Ctrl+u Ctrl+c Tab. He accomplished that by advising the Ctrl+c Tab function using the :before-until
combinator.
To be sure, collapsing only certain headings isn’t something most of us most to do very often but it’s nice to see how to do it as well as see a nice application of an advice combinator.