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: u8shiftwidth — 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: boolexpandtab — render indentation as spaces rather than tabs.
tabstop: u8tabstop — display columns a literal tab advances to.
Clamped to at least 1 at use.
Implementations§
Source§impl IndentUnit
impl IndentUnit
Sourcepub fn new(width: u8, expand_tabs: bool, tabstop: u8) -> Self
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.
Sourcepub fn step(&self) -> u16
pub fn step(&self) -> u16
shiftwidth, floored at 1. See Self::width.
Sourcepub fn tab_width(&self) -> u16
pub fn tab_width(&self) -> u16
tabstop, floored at 1. See Self::tabstop.
Sourcepub fn indent_len(line: &str) -> usize
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.
Sourcepub fn columns_of(&self, line: &str) -> u16
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.
Sourcepub fn render(&self, columns: u16) -> String
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.
Sourcepub fn shift(&self, columns: u16, levels: i32) -> u16
pub fn shift(&self, columns: u16, levels: i32) -> u16
columns shifted by levels indent steps, clamped at zero.
Sourcepub fn is_blank(line: &str) -> bool
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.
Sourcepub fn reindented_prefix(
&self,
line: &str,
levels: i32,
) -> Option<(usize, String)>
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
impl Clone for IndentUnit
Source§fn clone(&self) -> IndentUnit
fn clone(&self) -> IndentUnit
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for IndentUnit
Source§impl Debug for IndentUnit
impl Debug for IndentUnit
Source§impl Default for IndentUnit
impl Default for IndentUnit
impl Eq for IndentUnit
Source§impl PartialEq for IndentUnit
impl PartialEq for IndentUnit
impl StructuralPartialEq for IndentUnit
Auto Trait Implementations§
impl Freeze for IndentUnit
impl RefUnwindSafe for IndentUnit
impl Send for IndentUnit
impl Sync for IndentUnit
impl Unpin for IndentUnit
impl UnsafeUnpin for IndentUnit
impl UnwindSafe for IndentUnit
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.