This is an implementation of org-babel-tangle
in Nix. Given an Org string, it extracts the contents of source blocks in a particular language.
talyz/fromElisp provides support for Org, and it is also part of emacs-overlay, which apparently is used by many people for their own configs. However, I wanted to experiment with more advanced features such as excluding archived entries, and I wasn’t sure if I could mix that with their code base. I needed the feature in my own project, and I wanted to put it under my control, so I wrote it from scratch.
Import the flake.
Extracting source blocks from an Org file/stringThis function takes an Org string and returns its source blocks.
Example:
let tangle = lib.tangleOrgBabel { languages = [ "emacs-lisp" ]; }; in # Return a string tangle (builtins.readFile ./config.org)
Arguments:
Similar to tangleOrgBabel
, but this function takes a file as an argument and writes the output to a file.
Example:
# Write to a file let pkgs = import nixpkgs { inherit system; overlays = [ org-babel.overlays.default ]; }; in pkgs.tangleOrgBabelFile "init.el" ./config.org { languages = [ "emacs-lisp" ]; }
Note that this function is provided in the overlay of the flake.
Arguments:
Example:
{ languages = [ "emacs-lisp" "elisp" ]; }
Default: [ "emacs-lisp" "elisp" ]
You can transform the input by specifying processLines
option. It must be a function that takes a list of strings and returns a list of strings.
This library also contains excludeHeadlines
function which can be used to exclude subtrees according to a predicate on the headline text, so you can use it in the option.
Example:
{ # Exclude archived subtrees processLines = excludeHeadlines (matchOrgTag "ARCHIVE"); }
You can use the following predicates from this library:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4