pub struct Buffer {
pub rope: Rope,
pub path: Option<String>,
pub dirty: bool,
pub epoch: u64,
pub readonly: bool,
pub name: Option<String>,
}Expand description
A text buffer. Positions are UTF-8 byte offsets, everywhere (0001 §5.1).
Fields§
§rope: Rope§path: Option<String>§dirty: bool§epoch: u64Monotonic edit counter; async readers (git gutter) diff lazily.
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 from_text(text: &str) -> Self
Sourcepub fn open(path: &str) -> Result<Self>
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.
pub fn save(&mut self) -> Result<()>
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: usize) -> usize
pub fn line_start(&self, line: usize) -> usize
Byte offset of the first char of line (0-indexed).
Sourcepub fn line_end(&self, line: usize) -> usize
pub fn line_end(&self, line: usize) -> usize
Byte offset one past the last content char of line (excludes \n).
pub fn line_of(&self, offset: usize) -> usize
pub fn byte(&self, offset: usize) -> u8
pub fn byte_at(&self, offset: usize) -> Option<u8>
Sourcepub fn clamp_boundary(&self, offset: usize) -> usize
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).
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.
Sourcepub fn replace_all(&mut self, text: &str)
pub fn replace_all(&mut self, text: &str)
Replace the whole contents (virtual buffers filling from jobs).