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: boolRead-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
impl Buffer
pub fn prepare_save( &self, target: Option<PathBuf>, force: bool, ) -> Result<SaveRequest>
Sourcepub fn accept_save(&mut self, receipt: SaveReceipt) -> bool
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.
Sourcepub fn acknowledge_saved_revision(&mut self, revision: BufferRevision) -> bool
pub fn acknowledge_saved_revision(&mut self, revision: BufferRevision) -> bool
Pure acknowledgment for an externally owned save. The caller validates document/request identity; no local filesystem path is created or changed.
Source§impl Buffer
impl Buffer
pub fn prepare_line_layout( &self, line: LineIndex, tab: usize, cancelled: impl Fn() -> bool, ) -> Option<PreparedLineLayout>
pub fn install_line_layouts( &mut self, revision: BufferRevision, layouts: &[PreparedLineLayout], ) -> bool
pub fn layout_checkpoint( &self, line: LineIndex, origin: DisplayColumn, tab: usize, ) -> Option<LayoutCheckpoint>
pub fn try_cell_col_with_tab( &self, offset: usize, tab: usize, ) -> Option<DisplayColumn>
Source§impl Buffer
impl Buffer
pub fn edit(&mut self) -> UserEdit<'_>
pub fn system_edit(&mut self) -> SystemEdit<'_>
pub fn changes(&self) -> &[Change]
pub fn clear_changes(&mut self)
pub fn begin_undo_group(&mut self)
pub fn commit_undo_group(&mut self)
Sourcepub fn prepare_replacements(
&self,
base: BufferRevision,
replacements: Vec<Replacement>,
) -> Result<PreparedReplacements, EditError>
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.
pub fn apply_prepared( &mut self, prepared: PreparedReplacements, undo_open: bool, ) -> Result<BufferRevision, EditError>
Source§impl Buffer
impl Buffer
pub fn undo(&mut self) -> Result<Option<HistoryMove>, EditError>
pub fn redo(&mut self) -> Result<Option<HistoryMove>, EditError>
pub fn restore_revision( &mut self, revision: usize, ) -> Result<Option<HistoryMove>, EditError>
Source§impl Buffer
impl Buffer
pub fn text(&self) -> &Rope
pub fn snapshot(&self) -> Rope
pub fn history(&self) -> &History
pub fn revision(&self) -> BufferRevision
pub fn file_identity(&self) -> Option<&Path>
pub fn restore_history(&mut self, history: History) -> Result<(), HistoryError>
pub fn from_text(text: &str) -> Self
Sourcepub fn from_snapshot(rope: Rope) -> Self
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.
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self>
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.
Sourcepub fn cell_col_with_tab(
&self,
offset: impl Into<ByteOffset>,
tab: usize,
) -> DisplayColumn
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.
pub fn len_bytes(&self) -> usize
pub fn len_lines(&self) -> usize
Sourcepub fn last_content_line(&self) -> usize
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).
Sourcepub fn line_start(&self, line: impl Into<LineIndex>) -> usize
pub fn line_start(&self, line: impl Into<LineIndex>) -> usize
Byte offset of the first char of line (0-indexed).
Sourcepub fn line_end(&self, line: impl Into<LineIndex>) -> usize
pub fn line_end(&self, line: impl Into<LineIndex>) -> usize
Byte offset one past the last content char (excludes LF or CRLF).
pub fn line_of(&self, offset: impl Into<ByteOffset>) -> usize
Sourcepub fn col_of(&self, offset: impl Into<ByteOffset>) -> usize
pub fn col_of(&self, offset: impl Into<ByteOffset>) -> usize
Column (in bytes) of offset within its line.
Sourcepub fn byte(&self, offset: impl Into<ByteOffset>) -> u8
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.
pub fn byte_at(&self, offset: impl Into<ByteOffset>) -> Option<u8>
Sourcepub fn is_boundary(&self, offset: impl Into<ByteOffset>) -> bool
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.)
Sourcepub fn clamp_boundary(&self, offset: impl Into<ByteOffset>) -> usize
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).
Sourcepub fn ceil_boundary(&self, offset: impl Into<ByteOffset>) -> usize
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.
Sourcepub fn slice_string(&self, range: Range) -> String
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).