Skip to main content

Crate vix_org

Crate vix_org 

Source
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: and SCHEDULED: planning lines grouped by date, plus TODO headlines 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 in text with end timestamp now, appending the => H:MM duration. Returns the rewritten text, or None if there is no open clock entry.
cycle_todo
Cycle the TODO state of the headline at line: none → TODODONE → none. None if line is 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), or None for a non-headline line.
move_subtree_down
Move the subtree at line down past its next sibling, returning the new text and the subtree’s new starting line. None if there is no following sibling.
move_subtree_up
Move the subtree at line up past its previous sibling, returning the new text and the subtree’s new starting line. None if there is no prior sibling.
promote
Promote (shallower, fewer stars) every headline in the subtree at line. No-op returning None if not on a headline or any headline is already level 1.
subtree_range
The [start, end) line range of the subtree rooted at line — the headline plus every following line until the next headline of the same or higher level (a smaller or equal star count). None if line is not a headline.
time_report
Build a time-tracking report from content: sum each headline’s CLOCK: durations (the => H:MM totals 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). None if the line has no checkbox.
update_statistics
Recompute every checkbox parent state and every statistics cookie in text, matching Org’s behavior: