1
0
Fork 0
mirror of https://github.com/emacs-twist/org-babel.git synced 2024-12-15 17:50:48 +00:00
org-babel/README.org

87 lines
2.6 KiB
Org Mode
Raw Normal View History

2021-12-03 13:44:39 +00:00
* nix-org-babel
2022-02-05 15:58:42 +00:00
This is an implementation of =org-babel-tangle= in Nix.
2024-08-29 13:58:01 +00:00
Given an Org string, it extracts the contents of source blocks in a particular language.
2022-01-18 18:40:11 +00:00
** Rationale
[[https://github.com/talyz/fromElisp][talyz/fromElisp]] provides support for Org, and it is also part of [[https://github.com/nix-community/emacs-overlay][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 [[https://github.com/akirak/emacs-twist][my own project]], and I wanted to put it under my control, so I wrote it from scratch.
2021-12-11 20:42:02 +00:00
** Usage
Import the flake.
*** Extracting source blocks from an Org file/string
**** tangleOrgBabel function
This function takes an Org string and returns its source blocks.
Example:
#+begin_src nix
let
tangle = lib.tangleOrgBabel {
languages = [ "emacs-lisp" ];
};
in
# Return a string
tangle (builtins.readFile ./config.org)
#+end_src
Arguments:
1. An attribute set of options.
2. An Org input string.
**** tangleOrgBabelFile function
Similar to =tangleOrgBabel=, but this function takes a file as an argument and writes the output to a file.
Example:
#+begin_src nix
# Write to a file
let
pkgs = import nixpkgs {
inherit system;
overlays = [
2024-08-27 17:14:54 +00:00
org-babel.overlays.default
2021-12-11 20:42:02 +00:00
];
};
in
pkgs.tangleOrgBabelFile "init.el" ./config.org {
languages = [ "emacs-lisp" ];
}
#+end_src
Note that this function is provided in the overlay of the flake.
Arguments:
1. A string for the derivation name.
2. An input file path.
3. An attribute set of options.
*** Options
**** Languages
Example:
#+begin_src nix
{
languages = [ "emacs-lisp" "elisp" ];
}
#+end_src
2022-01-02 12:36:40 +00:00
Default: =[ "emacs-lisp" "elisp" ]=
2021-12-11 20:42:02 +00:00
**** Filtering subtrees
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.
2022-01-02 12:36:40 +00:00
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.
2021-12-11 20:42:02 +00:00
Example:
#+begin_src nix
{
# Exclude archived subtrees
2022-01-02 12:36:40 +00:00
processLines = excludeHeadlines (matchOrgTag "ARCHIVE");
2021-12-11 20:42:02 +00:00
}
#+end_src
You can use the following predicates from this library:
2022-01-02 12:36:40 +00:00
- tag :: Returns true if the headline matches a tag given as the argument. The argument must be a string.
- headlineText :: Returns true if the headline matches the text given as the argument. The argument must be a string.