TL;DR: Using a persistent library of babel stored in one file can be a simple 3-step setup:
- Create an
- Add a line
(org-babel-lob-ingest "~/.emacs.d/library-of-babel.org") to your Emacs conf.
- Collect useful functions in that file, they will be read during emacs startup.
The Library-Of-Babel-file is where e.g. the
aggregatebycol1 block from @mutbuerger would be saved to.
Another simple example use-case would be having a code-block, that generates
table data with a header row, but does not mark the headerrow with an
This is not tragic for simple display, but may make further automated processing more involved.
The solution here could be using a small code-block for post-processing from somewhere on the internet:
#+begin_src emacs-lisp :var tbl=""
(cons (car tbl) (cons 'hline (cdr tbl)))
This will simply pipe through the data while splicing in an
'hline as a second row.
To use this block later in other org files, simply add a
:post-processing stanza to your data-generating org source block:
#+BEGIN_SRC elisp :post addhdr(*this*)
'(("Header1" "Column2" "Three")("R1C1V" "2" "C3R1")("4" "5" "6"))
| Header1 | Column2 | Three |
| R1C1V | 2 | C3R1 |
| 4 | 5 | 6 |
You can also easily give pre-existing tables to functions in your LOB:
| h1 | h2 |
| dh1r1 | dh2r1 |
| dh1r2 | dh2r2 |
In my library I have chapters to organize different types of functionality: Data-Generation, Filtering, PrettyPrinting, ...
Just remember to
ingest again after adding new blocks.
org-babel-library-of-babel. When looking for source blocks, org-babel looks in the current file as well as the list stored in the above variable. The answer by @mutbuerger describes the details very well I think.