Skip to main content

Buffer

Struct Buffer 

Source
pub struct Buffer {
    pub rope: Rope,
    pub path: Option<String>,
    pub dirty: bool,
    pub epoch: u64,
    pub readonly: bool,
    pub name: Option<String>,
    pub history: History,
    pub replaying: bool,
}
Expand description

A text buffer. Positions are UTF-8 byte offsets, everywhere (0001 §5.1).

Fields§

§rope: Rope§path: Option<String>§dirty: bool§epoch: u64

Monotonic edit counter; async readers (git gutter) diff lazily.

§readonly: bool

Read-only views (git surfaces): motions/yank work, edits refuse.

§name: Option<String>

Display name for virtual buffers (statusline shows “[scratch]” otherwise): “git log”, “commit 1a2b3c”, …

§history: History

Undo history (helix-style revision tree). Readonly buffers never record (their content is owned by jobs, not the user).

§replaying: bool

Suppresses recording while applying undo/redo ops.

Implementations§

Source§

impl Buffer

Source

pub fn from_text(text: &str) -> Self

Source

pub fn open(path: &str) -> Result<Self>

Open a file; a missing file is a new empty buffer with that path (vim semantics — :w creates it). Real I/O errors still error.

Source

pub fn save(&mut self) -> Result<()>

Source

pub fn len_bytes(&self) -> usize

Source

pub fn len_lines(&self) -> usize

Source

pub fn last_content_line(&self) -> usize

Last content line index — a trailing newline’s phantom empty line doesn’t count (vim’s G lands on real text).

Source

pub fn line_start(&self, line: usize) -> usize

Byte offset of the first char of line (0-indexed).

Source

pub fn line_end(&self, line: usize) -> usize

Byte offset one past the last content char of line (excludes \n).

Source

pub fn line_of(&self, offset: usize) -> usize

Source

pub fn col_of(&self, offset: usize) -> usize

Column (in bytes) of offset within its line.

Source

pub fn byte(&self, offset: usize) -> u8

Source

pub fn byte_at(&self, offset: usize) -> Option<u8>

Source

pub fn clamp_boundary(&self, offset: usize) -> usize

Clamp a byte offset to a char boundary (prototype is ASCII-honest; the grapheme policy in 0001 §5.9 hardens this when text goes wide).

Source

pub fn slice_string(&self, range: Range) -> String

Slice as String — for register/paste paths, never for per-frame render.

Source

pub fn apply_history(&mut self, ops: Vec<Edit>)

Apply history edits (undo/redo replay — never recorded).

Source

pub fn replace_all(&mut self, text: &str)

Replace the whole contents (virtual buffers filling from jobs).

Source

pub fn delete(&mut self, range: Range) -> String

Returns the deleted text (register payoff).

Source

pub fn insert(&mut self, at: usize, text: &str)

Source

pub fn line_text(&self, line: usize) -> String

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.