1
0
Fork 0
mirror of https://github.com/emacs-twist/org-babel.git synced 2025-03-05 08:17:05 +00:00
org-babel/nix/excludeOrgSubtreesOnHeadlines.nix
Akira Komamura 95e19914cb refactor: Extract utility functions into utils library
These are reusable functions, and I want to avoid duplicate implementations
of them.
2022-01-02 16:18:05 +09:00

21 lines
411 B
Nix

# Exclude lines of Org subtrees by a heading predicate
pred:
with builtins;
let
inherit (import ./utils.nix)
dropTillSubtreeEnd
getHeadlineLevel
splitListWith
isHeadline;
go_ = cut:
cut.before
++
(if cut.sep == null
then [ ]
else go (dropTillSubtreeEnd (getHeadlineLevel cut.sep) cut.after));
go = lines: go_ (splitListWith (s: isHeadline s && pred s) lines);
in
go