pub struct Table {
pub first: u32,
pub last: u32,
pub rows: Vec<Row>,
pub indent: String,
}Expand description
A table lifted out of a buffer: its line span, its rows, and the indentation its first line carried.
Fields§
§first: u32First line of the table, inclusive.
last: u32Last line of the table, inclusive.
rows: Vec<Row>Every row, in buffer order — cells and separators alike.
indent: StringLeading whitespace of the first row, reproduced on every rendered line. An indented table stays where the author put it — org tables under a headline routinely are.
Implementations§
Source§impl Table
impl Table
Sourcepub fn next_cell(&self, at: Cell) -> Option<Cell>
pub fn next_cell(&self, at: Cell) -> Option<Cell>
The next cell after at, wrapping to the start of the next content
row and skipping rules — a rule has no cells, so stopping on one
would make <Tab> appear to do nothing every few presses.
None at the last cell of the last row: the caller decides whether
that means “add a row” or “leave the table”, and this function has no
business inventing either.
Sourcepub fn prev_cell(&self, at: Cell) -> Option<Cell>
pub fn prev_cell(&self, at: Cell) -> Option<Cell>
The previous cell, wrapping to the END of the previous content row.
Sourcepub fn move_row(&self, at: Cell, delta: isize) -> Option<(Table, Cell)>
pub fn move_row(&self, at: Cell, delta: isize) -> Option<(Table, Cell)>
Swap the row at at.row with the one delta away, skipping rules.
Rules are skipped rather than swapped through: a rule marks a boundary (a header, a section), and dragging a content row across one changes what the table means, where swapping with the row beyond it does what the user pictured.
Sourcepub fn move_column(&self, at: Cell, delta: isize) -> Option<(Table, Cell)>
pub fn move_column(&self, at: Cell, delta: isize) -> Option<(Table, Cell)>
Swap column at.column with the one delta away, in every row.
Sourcepub fn insert_row(&self, at: Cell) -> (Table, Cell)
pub fn insert_row(&self, at: Cell) -> (Table, Cell)
Insert an empty row below at.row, and put the caret in it.
Below rather than above, matching o — the row you want is almost
always the next one, and O’s peer is a follow-up chord rather than a
guess about which one you meant.
Sourcepub fn insert_column(&self, at: Cell) -> (Table, Cell)
pub fn insert_column(&self, at: Cell) -> (Table, Cell)
Insert an empty column to the right of at.column, in every row.
Sourcepub fn delete_row(&self, at: Cell) -> Option<(Table, Cell)>
pub fn delete_row(&self, at: Cell) -> Option<(Table, Cell)>
Delete the row under the caret.
None when it is the table’s last content row: deleting it would
leave a rule floating with nothing to rule, and the user asked to
delete a row, not the table. dd is right there for that.
Sourcepub fn delete_column(&self, at: Cell) -> Option<(Table, Cell)>
pub fn delete_column(&self, at: Cell) -> Option<(Table, Cell)>
Delete the column under the caret, in every row.
None on the last column, for Self::delete_row’s reason: a table
with no columns is not a table, it is a stack of |.
Sourcepub fn insert_rule(&self, at: Cell, fallback: char) -> (Table, Cell)
pub fn insert_rule(&self, at: Cell, fallback: char) -> (Table, Cell)
Insert a horizontal rule below at.row.
The style is copied from a rule the table already has. Only a table
with none needs fallback, which is the single place the dialect is
not readable off the buffer — see mode::rule_fallback.
Sourcepub fn sort_section(&self, at: Cell, descending: bool) -> Option<(Table, Cell)>
pub fn sort_section(&self, at: Cell, descending: bool) -> Option<(Table, Cell)>
Sort the caret’s section by the column under the caret.
The comparator is chosen from the data, not asked for: numeric when
every non-empty value in the column parses as a number, case-insensitive
lexicographic otherwise. Emacs prompts for a/n/t; a prompt on a
single chord is a question with an obvious answer in nearly every real
table, and getting it wrong is one undo.
Empty cells sort LAST in both directions. An empty cell is the absence of a value rather than a small one, so floating it to the top of a descending sort would bury the rows you asked to see.
Sourcepub fn blank_cell(&self, at: Cell) -> Option<(Table, Cell)>
pub fn blank_cell(&self, at: Cell) -> Option<(Table, Cell)>
Empty the cell under the caret, leaving the table’s shape alone.
Sourcepub fn copy_down(&self, at: Cell) -> Option<(Table, Cell)>
pub fn copy_down(&self, at: Cell) -> Option<(Table, Cell)>
Copy the caret’s field into the row below, and move down with it.
Emacs’ org-table-copy-down (S-<CR>), including the increment: a
value ending in an integer copies down as that integer plus one, which
is what makes it a series filler rather than a duplicator. Q3 →
Q4, 1.2 → 1.3 — the trailing run of digits moves, the rest is
carried verbatim.
Creates the row below when the caret is on the last one, since stopping at the bottom would make the chord fail exactly when you are filling a column downwards.
Sourcepub fn down_cell(&self, at: Cell) -> Option<Cell>
pub fn down_cell(&self, at: Cell) -> Option<Cell>
The cell directly below at, skipping rules — where Insert-mode
<CR> goes.
Distinct from Self::next_cell, which wraps to the start of the next
row: <CR> keeps the COLUMN, because it is how you fill one downwards.
None at the bottom; the caller decides whether that means a new row.
Sourcepub fn transpose(&self, at: Cell) -> Option<(Table, Cell)>
pub fn transpose(&self, at: Cell) -> Option<(Table, Cell)>
Swap the table’s rows and columns.
Rules do not survive, and cannot: a rule separates row groups, and
after a transpose those groups are columns — there is no horizontal
line that means what it meant. Emacs’ org-table-transpose-table-at-point
drops them for the same reason. Dropping them is stated here rather
than discovered in a diff.
Source§impl Table
impl Table
Sourcepub fn at(
line: impl Fn(u32) -> Option<String>,
at: u32,
line_count: u32,
) -> Option<Table>
pub fn at( line: impl Fn(u32) -> Option<String>, at: u32, line_count: u32, ) -> Option<Table>
The table containing at, or None when that line is not one.
line answers for any row index; line_count bounds the walk. Taking
a closure rather than a &Buffer keeps this crate off lattice-core’s
rope and makes the whole model testable on a Vec<&str>.
Sourcepub fn columns(&self) -> usize
pub fn columns(&self) -> usize
How many columns the widest row has. A ragged table is normal mid-edit, and the widest row is what every operation sizes against.
Sourcepub fn row_index(&self, line: u32) -> Option<usize>
pub fn row_index(&self, line: u32) -> Option<usize>
The row index (into Self::rows) for buffer line line.
Sourcepub fn render(&self) -> Vec<String>
pub fn render(&self) -> Vec<String>
Render every row, preserving the separator style the table was found with and the indentation of its first line.
Column widths come from the widest visible cell, floored at 1: a
column of empty cells still has to be wide enough to put the caret in,
and a zero-width column renders || with nowhere to type.
Trait Implementations§
impl Eq for Table
impl StructuralPartialEq for Table
Auto Trait Implementations§
impl Freeze for Table
impl RefUnwindSafe for Table
impl Send for Table
impl Sync for Table
impl Unpin for Table
impl UnsafeUnpin for Table
impl UnwindSafe for Table
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.