mirror of
https://github.com/emacs-twist/org-babel.git
synced 2024-12-15 17:50:48 +00:00
95e19914cb
These are reusable functions, and I want to avoid duplicate implementations of them.
25 lines
638 B
Nix
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));
|
|
}
|