Skip to main content

Module model

Module model 

Source
Expand description

A pipe table as table-mode sees it: where it starts and ends, which cell the caret is in, and how to render it back (TB.1).

layout is the unattended half of this — it reformats every table in a document at content-build time, for lattice-help. This is the interactive half, and the two differ in three ways that all come from the same fact: the user pointed at this table.

  1. A separator row is not required. layout’s recogniser demands one, and is right to: it walks whole documents unattended, and prose like use `a | b` must not become a one-column table. Nothing here runs unattended — you put the caret on the line and pressed a key — so demanding a separator would refuse to align exactly the org tables that do not have one, which is most of them.

  2. The separator style is preserved, not chosen. Org writes |---+---| and markdown writes |---|---|; both are tables, and an align that rewrote one into the other would edit a file’s dialect because you asked it to line up some columns.

    That is why there is no table.dialect option and no seam for a major to declare one: the table says which dialect it is. An option would be a second source for a fact already in the buffer, and the two can disagree — a +-joined table in a markdown file would be rewritten by a correct-looking option. Reading the file cannot be wrong about the file.

  3. The caret has to land somewhere. Alignment rewrites every row, so the byte offset the caret sat at is meaningless afterwards; the mode tracks the cell and re-derives an offset in the rendered line.

Width is measured by unicode-width, through layout’s own helpers — shared rather than re-derived, because a second measurement that disagreed would align tables one way in help pages and another way under the caret.

Structs§

Table
A table lifted out of a buffer: its line span, its rows, and the indentation its first line carried.

Enums§

Row
One line of a table, parsed.

Functions§

is_table_line
True when line is part of a table: a | after optional indent.
parse_row
Parse one line into a row.