Skip to main content

Module indent_blocks

Module indent_blocks 

Source
Expand description

Indent blocks — the shared answer to “what block is this line in”.

IndentUnit answers how wide is one level. This module answers where do the levels begin and end, and it has two consumers that must not disagree:

  • Indentation guides — a guide is a block’s column drawn down the block’s extent (docs/dev/architecture/indent-guides.md).
  • foldmethod=indent — a fold is a block’s extent (lattice-host/src/folds.rs).

They are two views of one question, and a user who folds a block and sees a different extent than the one that was just highlighted has been told two different things by the same editor. So the walk lives here, once, and both call it.

Nothing here reads config or touches a rope: line_indents projects lines to LineIndent, and indent_blocks is a pure function of that projection. That is what lets the subtle cases — blank runs, closer inclusion, multi-level jumps, tabs — be argued against a unit test rather than against a screenshot.

Structs§

IndentBlock
One indent guide: a display column, and the inclusive line range it spans.
IndentRegion
A contiguous region of indented lines: everything between an opener and its closer.
LineIndent
One line’s contribution to the block walk.
LineShape
The only three facts the indent-guide builder needs about a line, in a Copy struct so it can be produced without materialising the line’s text.

Functions§

indent_blocks
Expand every region into one guide per grid column it spans.
indent_regions
Walk lines and emit every indent region, ordered by opener line.
is_closer_line
Whether line is a pure closing-bracket line.
line_indents
Project lines to the walk’s input.