Expand description
The text-reflow engine — re-break a range of lines to textwidth.
Design: docs/dev/architecture/text-reflow.md §4.
Sequencing: docs/dev/operations/slice-plans/text-reflow.md (this is
RF.1).
A pure function of (lines, textwidth, comment leader, indent). No
I/O, no syntax tree, no config lookup — the host resolves the options
and hands the values down, exactly as it does for the indent unit.
§Why it lives in lattice-grammar
Heuristic #6: it carves out no dependency surface, so it earns no
crate. The operator that drives it (crate::builtins) reads
crate::GrammarEnv, which already carries comment_syntax (N.1.6)
and indent (IN.0); the host’s insert path (RF.3) calls the same
module and already depends on this crate.
lattice-format was the other candidate and is the wrong one: that
crate is process spawning, timeouts and diff-derived edits — a
different mechanism that happens to share the word “format”.
§What it is not
Not a reformatter. It moves line breaks and normalises interior whitespace within a paragraph, and touches nothing else — no reindentation of code, no reordering, no syntax awareness.
Structs§
- Auto
Wrap Break - Where auto-wrap should break the line being typed on, and what the carried remainder needs in front of it.
- Paragraph
- One paragraph found inside a reflow range.
- Prefix
- The fixed prefix every line of a paragraph carries: indentation plus
any comment leader, e.g.
" /// "or"# "or just" ". - Reflow
Config - Everything the engine needs that it cannot derive from the text.
Functions§
- auto_
wrap_ break - Decide whether the line the cursor sits on should break, and where (§9).
- display_
width - Display width of
sin terminal columns. - fill
- Reflow one already-identified paragraph into output lines.
- line_
is_ comment - Whether
linereads as a comment, by its leading marker alone. - paragraphs
- Split
linesinto paragraphs (§4.1). - reflow_
range - Reflow a whole range: paragraphs found, fillable ones filled, everything else carried through.