org-mode’s literate programming (Babel) functionality is amazing. The limitation in my case is me, not the tool. The power and abstraction just aren’t something that you think about it for a document. While I suppose that is the whole point of LP, it does just take time for it to sink in, and experience. That said, this example is nice.
Clearly generating a headline is something you may do once, and probably not very often, so would perhaps be more likely just use a macro definition. When I see how simple this is though, the idea of using macros really goes out the window because this is far easier and simpler and much more powerful. Here is a simple example:
This:
* Code
#+name: hname
#+header: :exports none
#+begin_src emacs-lisp
"Hello, world."
#+end_src
* call_hname()[:results raw]
Produces this:
1 Code
══════
2 Hello, world.
═══════════════