Expand description
Basic Org-mode operations: headline structure editing and lightweight export.
This is a pragmatic subset of Org (https://orgmode.org/), not a complete implementation. The structural helpers operate on the whole buffer text plus a 0-based cursor line and return the rewritten text (and, where the cursor should follow a moved subtree, its new line). The exporters turn Org markup into Markdown or a small standalone HTML document.
All functions are pure so they can be unit-tested without a live editor.
Functions§
- agenda
- Compile an agenda from
(filename, content)Org documents:DEADLINE:andSCHEDULED:planning lines grouped by date, plusTODOheadlines that have no date. Returns an Org document (open it in a buffer). Pure and testable. - clock_
in - An Org clock-in line for the timestamp
now(e.g.2024-08-23 Fri 10:00). - clock_
out - Close the most recent open
CLOCK:entry intextwith end timestampnow, appending the=> H:MMduration. Returns the rewritten text, orNoneif there is no open clock entry. - cycle_
todo - Cycle the TODO state of the headline at
line: none →TODO→DONE→ none.Noneiflineis not a headline. - demote
- Demote (deeper, more stars) every headline in the subtree at
line. - headline_
level - The number of leading
*of a headline (followed by a space), orNonefor a non-headline line. - move_
subtree_ down - Move the subtree at
linedown past its next sibling, returning the new text and the subtree’s new starting line.Noneif there is no following sibling. - move_
subtree_ up - Move the subtree at
lineup past its previous sibling, returning the new text and the subtree’s new starting line.Noneif there is no prior sibling. - promote
- Promote (shallower, fewer stars) every headline in the subtree at
line. No-op returningNoneif not on a headline or any headline is already level 1. - subtree_
range - The
[start, end)line range of the subtree rooted atline— the headline plus every following line until the next headline of the same or higher level (a smaller or equal star count).Noneiflineis not a headline. - time_
report - Build a time-tracking report from
content: sum each headline’sCLOCK:durations (the=> H:MMtotals Org writes) into a table with a grand total. Pure and testable. - to_html
- Convert Org text to a small standalone HTML document (a pragmatic subset: headlines, paragraphs, and bullet lists).
- to_
markdown - Convert Org text to Markdown (a pragmatic, line-oriented mapping).
- toggle_
checkbox - Toggle a list checkbox on the line at
line:[ ]⇄[x](treating[-]and[X]as checked).Noneif the line has no checkbox. - update_
statistics - Recompute every checkbox parent state and every statistics cookie in
text, matching Org’s behavior: