1
0
Fork 0
mirror of https://github.com/emacs-twist/org-babel.git synced 2024-12-14 11:07:30 +00:00
A pure Nix implementation of org-babel-tangle
Find a file
Akira Komamura 8b1e46093f tests: Add flake.nix to run nix flake check against it
Ensure that the derivation does not have IFD.
2022-12-01 18:54:03 +09:00
.github/workflows test: Add tests for parameter parsing 2022-02-06 00:57:04 +09:00
nix Add todo 2022-02-06 00:55:05 +09:00
test tests: Add flake.nix to run nix flake check against it 2022-12-01 18:54:03 +09:00
flake.lock Initial commit 2021-12-03 22:44:34 +09:00
flake.nix Use overlays.default rather than overlay as the flake output 2022-12-01 17:41:04 +09:00
LICENSE docs: Add license 2021-12-03 22:45:03 +09:00
README.org docs(readme): Fix the default languages 2022-02-09 14:24:45 +09:00

nix-org-babel

This is an implementation of org-babel-tangle in Nix. Given an Org string, it extracts the contents of source blocks of a particular language.

Rationale

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.

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:

  let
    tangle = lib.tangleOrgBabel {
      languages = [ "emacs-lisp" ];
    };
  in
  # Return a string
  tangle (builtins.readFile ./config.org)

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:

  # Write to a file
  let
    pkgs = import nixpkgs {
      inherit system;
      overlays = [
        org-babel.overlay
      ];
    };
  in
  pkgs.tangleOrgBabelFile "init.el" ./config.org {
    languages = [ "emacs-lisp" ];
  }

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:

  {
    languages = [ "emacs-lisp" "elisp" ];
  }

Default: [ "emacs-lisp" "elisp" ]

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.

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:

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.