Efficiently untangling Elisp from .org files

Many people keep their Emacs config in and org-mode file because it’s
easier to manage.

However, we need to extract the Elisp parts out of the org file and
evaluate them somehow. org-mode has a built-in command for this:
(org-babel-load-file "config.org"). However, this is an org-mode
command, and org-mode is huge. So your init.el needs to load a good
amount of org-mode just to get the elisp out of it.
But to be able to do this you’d
need to load a good amount of the org-mode file.

I wanted to have something better. Something that is flexible and
gives me a quicker startup time.

My method is to do the following:

If the config.org is newer than config.el, then efficiently
extract all eligible Elisp source code blocks from the .org
file and write them into the .el file. Even when done efficiently,
this is relatively slow. But it almost never happens.

then load the config.el file. This is quite fast.

I wrote two words in bold:

efficiently: to un-tangle the source-code blocks I could have
used (org-babel-tangle nil "config.el"). But it opens and
closes the target file for every single source code blocks. You
can hear the churn if you still use spinning rust (a hard disk).
My code fixes this.

eligible: we all know than org-tangle honors “:tangle no”. But
it doesn’t care for the todo-state of a section. I wrote my code
so that it will skip over items marked as “CANCELED”. It’s just
nicer to mark one section with “CANCELED” — compared to change
everyone of it’s five source-code blocks with :tangle no.

The tangling

First I define a function that — when the point is at some source-code block —
goes back to the section header and checks if there entry has been canceled: