Skip to main content

IndentUnit

Struct IndentUnit 

Source
pub struct IndentUnit {
    pub width: u8,
    pub expand_tabs: bool,
    pub tabstop: u8,
}
Expand description

One level of indentation, resolved for a specific buffer.

width is shiftwidth — columns per indent level. tabstop is the display width of a literal tab byte. They are deliberately separate: conflating them means “change my indent size” silently reflows every file containing a hard tab, including content the user never edited.

Fields§

§width: u8

shiftwidth — columns added or removed per indent level. Clamped to at least 1 at use; a zero-width level would make > a no-op and columns → levels a division by zero.

§expand_tabs: bool

expandtab — render indentation as spaces rather than tabs.

§tabstop: u8

tabstop — display columns a literal tab advances to. Clamped to at least 1 at use.

Implementations§

Source§

impl IndentUnit

Source

pub fn new(width: u8, expand_tabs: bool, tabstop: u8) -> Self

Build a unit from raw option values: shiftwidth, expandtab, tabstop. Zero widths are stored as given and floored to 1 by Self::step / Self::tab_width.

Source

pub fn step(&self) -> u16

shiftwidth, floored at 1. See Self::width.

Source

pub fn tab_width(&self) -> u16

tabstop, floored at 1. See Self::tabstop.

Source

pub fn indent_len(line: &str) -> usize

Byte length of line’s leading whitespace run.

Whitespace here is space and tab only — not \r, and not Unicode space separators. A line that is entirely whitespace returns its full length.

Source

pub fn columns_of(&self, line: &str) -> u16

Display columns occupied by line’s leading whitespace.

A tab advances to the next multiple of tabstop, which is why this cannot be a byte count: "\t" and " " are the same indent at tabstop=4 and must compare equal.

Source

pub fn render(&self, columns: u16) -> String

The whitespace string that renders as columns display columns.

With expandtab off this is tabs plus a space remainder, which is what vim produces and what keeps shiftwidth values that are not multiples of tabstop representable.

Source

pub fn shift(&self, columns: u16, levels: i32) -> u16

columns shifted by levels indent steps, clamped at zero.

Source

pub fn is_blank(line: &str) -> bool

Whether line has no non-whitespace content.

Blank lines are skipped by > / <: vim does not indent them, and doing so leaves trailing whitespace on lines the user never typed into.

Source

pub fn reindented_prefix( &self, line: &str, levels: i32, ) -> Option<(usize, String)>

The replacement leading-whitespace for line shifted by levels, or None when nothing should change.

None covers both “blank line” and “the rendered result is byte-identical to what is already there” — the second matters because emitting a no-op edit still costs an undo entry and a render invalidation.

Trait Implementations§

Source§

impl Clone for IndentUnit

Source§

fn clone(&self) -> IndentUnit

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 Copy for IndentUnit

Source§

impl Debug for IndentUnit

Source§

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

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

impl Default for IndentUnit

Source§

fn default() -> Self

Matches the registered option defaults (shiftwidth=4, expandtab, tabstop=4) so a context that never resolved config behaves like an unconfigured buffer rather than like something arbitrary.

Source§

impl Eq for IndentUnit

Source§

impl PartialEq for IndentUnit

Source§

fn eq(&self, other: &IndentUnit) -> 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 IndentUnit

Auto Trait Implementations§

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.

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.