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/nix/utils.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

25 lines
638 B
Nix

with builtins;
let
genericHeadlineRegexp = "(\\*+)[[:space:]].+";
prependOptionalStars = n: rest:
if n == 0
then rest
else prependOptionalStars (n - 1) ("\\*?" + rest);
in
rec {
dropWhile = import ./dropWhile.nix;
splitListWith = import ./splitWith.nix;
isHeadline = s: substring 0 1 s == "*";
getHeadlineLevel = headline:
stringLength (head (match genericHeadlineRegexp headline));
makeSubtreeEndRegexp = outlineLevel:
prependOptionalStars (outlineLevel - 1) "\\*[[:space:]].+";
dropTillSubtreeEnd = level:
dropWhile (s: !(isHeadline s && match (makeSubtreeEndRegexp level) s != null));
}