Skip to main content

Buffer

Struct Buffer 

Source
pub struct Buffer {
    pub path: Option<PathBuf>,
    pub dirty: bool,
    pub readonly: bool,
    pub name: Option<String>,
    /* private fields */
}
Expand description

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

Fields§

§path: Option<PathBuf>

Filesystem identity (0021 §3: Unix filenames aren’t UTF-8 — a String path makes the filesystem model a UI model). Display via to_string_lossy at the edge only.

§dirty: bool§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”, …

Implementations§

Source§

impl Buffer

Source

pub fn prepare_save( &self, target: Option<PathBuf>, force: bool, ) -> Result<SaveRequest>

Source

pub fn accept_save(&mut self, receipt: SaveReceipt) -> bool

A write of an older snapshot may update the on-disk baseline, never clear dirty text or rename an edited document. Caller also checks request identity.

Source§

impl Buffer

Source

pub fn seed(&self) -> BufferSeed

Source§

impl Buffer

Source

pub fn prepare_line_layout( &self, line: LineIndex, tab: usize, cancelled: impl Fn() -> bool, ) -> Option<PreparedLineLayout>

Source

pub fn install_line_layouts( &mut self, revision: BufferRevision, layouts: &[PreparedLineLayout], ) -> bool

Source

pub fn layout_checkpoint( &self, line: LineIndex, origin: DisplayColumn, tab: usize, ) -> Option<LayoutCheckpoint>

Source

pub fn try_cell_col_with_tab( &self, offset: usize, tab: usize, ) -> Option<DisplayColumn>

Source§

impl Buffer

Source

pub fn edit(&mut self) -> UserEdit<'_>

Source

pub fn system_edit(&mut self) -> SystemEdit<'_>

Source

pub fn changes(&self) -> &[Change]

Source

pub fn clear_changes(&mut self)

Source

pub fn begin_undo_group(&mut self)

Source

pub fn commit_undo_group(&mut self)

Source

pub fn prepare_replacements( &self, base: BufferRevision, replacements: Vec<Replacement>, ) -> Result<PreparedReplacements, EditError>

All replacements refer to one pre-edit snapshot. Validate the whole batch before opening history or touching text; reversed application preserves coordinates.

Source

pub fn apply_prepared( &mut self, prepared: PreparedReplacements, undo_open: bool, ) -> Result<BufferRevision, EditError>

Source§

impl Buffer

Source

pub fn undo(&mut self) -> Result<Option<HistoryMove>, EditError>

Source

pub fn redo(&mut self) -> Result<Option<HistoryMove>, EditError>

Source

pub fn restore_revision( &mut self, revision: usize, ) -> Result<Option<HistoryMove>, EditError>

Source§

impl Buffer

Source

pub fn text(&self) -> &Rope

Source

pub fn snapshot(&self) -> Rope

Source

pub fn history(&self) -> &History

Source

pub fn revision(&self) -> BufferRevision

Source

pub fn file_identity(&self) -> Option<&Path>

Source

pub fn restore_history(&mut self, history: History) -> Result<(), HistoryError>

Source

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

Source

pub fn from_snapshot(rope: Rope) -> Self

A cheap independent reader over immutable rope structure. No text copy, disk identity, or history is inherited from the publishing document.

Source

pub fn open(path: impl AsRef<Path>) -> 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 cell_col_with_tab( &self, offset: impl Into<ByteOffset>, tab: usize, ) -> DisplayColumn

Display CELL of an offset within its line (0017/R6): cursor placement and overlays need terminal cells, not byte columns — wide chars and tabs make the difference. Streams through the containing cluster only: no whole-line String, no layout vector, no u16 saturation.

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: impl Into<LineIndex>) -> usize

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

Source

pub fn line_end(&self, line: impl Into<LineIndex>) -> usize

Byte offset one past the last content char (excludes LF or CRLF).

Source

pub fn line_of(&self, offset: impl Into<ByteOffset>) -> usize

Source

pub fn col_of(&self, offset: impl Into<ByteOffset>) -> usize

Column (in bytes) of offset within its line.

Source

pub fn byte(&self, offset: impl Into<ByteOffset>) -> u8

Byte at a position. An empty rope reads as NUL: every classifier treats NUL as a boundary, and the alternative (a panic) is how the second review found this (0015). byte_at when absence itself matters.

Source

pub fn byte_at(&self, offset: impl Into<ByteOffset>) -> Option<u8>

Source

pub fn is_boundary(&self, offset: impl Into<ByteOffset>) -> bool

Is offset a UTF-8 char boundary? ropey’s try_byte_to_char maps a mid-char byte to its containing char without complaint — only the byte↔char roundtrip actually detects boundaries. (The pre-0.3.9 clamp trusted it and never clamped anything.)

Source

pub fn clamp_boundary(&self, offset: impl Into<ByteOffset>) -> usize

Clamp a byte offset down to a char boundary (the grapheme policy in 0001 §5.9 hardens this further when text goes wide).

Source

pub fn ceil_boundary(&self, offset: impl Into<ByteOffset>) -> usize

Smallest char boundary >= offset. Byte arithmetic on a cursor (cursor + 1 in x/a/r/~) lands inside a multibyte char; deleting or inserting there panics ropey. Round up, never down — a deletion that rounds down eats the previous char’s tail.

Source

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

Slice as String — for register/paste paths, never for per-frame render. Stale ranges clamp (fuzz-driven cascades hand these around).

Source

pub fn line_text(&self, line: impl Into<LineIndex>) -> String

Source§

impl Buffer

Source

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

(line, col) of a byte offset, as tree-sitter Points.

Source§

impl Buffer

Source

pub fn trace_id(&self) -> BufferTraceId

Auto Trait Implementations§

§

impl !Freeze for Buffer

§

impl !RefUnwindSafe for Buffer

§

impl !Sync for Buffer

§

impl Send for Buffer

§

impl Unpin for Buffer

§

impl UnsafeUnpin for Buffer

§

impl UnwindSafe for Buffer

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.