Skip to main content

Table

Struct Table 

Source
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: u32

First line of the table, inclusive.

§last: u32

Last line of the table, inclusive.

§rows: Vec<Row>

Every row, in buffer order — cells and separators alike.

§indent: String

Leading 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

Source

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.

Source

pub fn prev_cell(&self, at: Cell) -> Option<Cell>

The previous cell, wrapping to the END of the previous content row.

Source

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.

Source

pub fn move_column(&self, at: Cell, delta: isize) -> Option<(Table, Cell)>

Swap column at.column with the one delta away, in every row.

Source

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.

Source

pub fn insert_column(&self, at: Cell) -> (Table, Cell)

Insert an empty column to the right of at.column, in every row.

Source

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.

Source

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 |.

Source

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.

Source

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.

Source

pub fn blank_cell(&self, at: Cell) -> Option<(Table, Cell)>

Empty the cell under the caret, leaving the table’s shape alone.

Source

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.

Source

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.

Source

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

Source

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>.

Source

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.

Source

pub fn row_index(&self, line: u32) -> Option<usize>

The row index (into Self::rows) for buffer line line.

Source

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§

Source§

impl Clone for Table

Source§

fn clone(&self) -> Table

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Table

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Table

Source§

impl PartialEq for Table

Source§

fn eq(&self, other: &Table) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more