pub trait BufferExt: Debug {
// Required methods
fn get_line(&self, idx: usize) -> Result<String>;
fn get_lines(
&self,
line_range: RangeInclusive<usize>,
strict_indexing: bool,
) -> Result<Box<dyn SuperIterator<String>>, Error>;
fn get_buf_type(&self) -> Option<String>;
fn get_channel(&self) -> Option<u32>;
fn set_text_at_cursor_pos(&mut self, text: &str);
fn get_pid(&self) -> Result<String>;
// Provided methods
fn get_text_between(
&self,
start: (usize, usize),
end: (usize, usize),
boundary: TextBoundary,
) -> Result<String> { ... }
fn is_terminal(&self) -> bool { ... }
fn send_command(&self, cmd: &str) -> Option<()> { ... }
}Expand description
Extension trait for Buffer to provide extra functionalities.
Provides focused helpers for line fetching and text insertion at the current
cursor position while surfacing Nvim errors via notify_error.
Required Methods§
Sourcefn get_line(&self, idx: usize) -> Result<String>
fn get_line(&self, idx: usize) -> Result<String>
Fetch a single line from a Buffer by 0-based index.
Returns a color_eyre::Result with the line as nvim_oxi::String.
Errors if the line does not exist at idx.
§Errors
- Fetching the line via
nvim_buf_get_linesfails. - The requested index is out of range (no line returned).
Sourcefn get_lines(
&self,
line_range: RangeInclusive<usize>,
strict_indexing: bool,
) -> Result<Box<dyn SuperIterator<String>>, Error>
fn get_lines( &self, line_range: RangeInclusive<usize>, strict_indexing: bool, ) -> Result<Box<dyn SuperIterator<String>>, Error>
Retrieves a range of lines from the buffer.
§Errors
- If
strict_indexingis true and the range is out of bounds. - If the Nvim API call to fetch lines fails.
§Rationale
This is a thin wrapper around nvim_oxi::api::Buffer::get_lines to enable unit testing of the default trait
method BufferExt::get_text_between.
Sourcefn get_buf_type(&self) -> Option<String>
fn get_buf_type(&self) -> Option<String>
Retrieves the buffer type via the buftype option.
Queries Nvim for the buffer type option and returns the value.
Errors are handled internally by notifying Nvim and converting to None.
§Rationale
Errors are notified directly to Nvim because this is the behavior wanted in all cases.
fn get_channel(&self) -> Option<u32>
Sourcefn set_text_at_cursor_pos(&mut self, text: &str)
fn set_text_at_cursor_pos(&mut self, text: &str)
Inserts text at the current cursor position in the active buffer.
Obtains the current CursorPosition, converts the 1-based row to 0-based
for Nvim’s set_text call, and inserts text without replacing existing
content (start_col == end_col). Errors are reported via notify_error.
Silently returns if cursor position cannot be fetched.
Provided Methods§
Sourcefn get_text_between(
&self,
start: (usize, usize),
end: (usize, usize),
boundary: TextBoundary,
) -> Result<String>
fn get_text_between( &self, start: (usize, usize), end: (usize, usize), boundary: TextBoundary, ) -> Result<String>
Get text from a nvim_oxi::api::Buffer.
Retrieves text from the specified start position to end position, respecting the given boundary.
§Errors
- If substring extraction fails due to invalid indices.
fn is_terminal(&self) -> bool
fn send_command(&self, cmd: &str) -> Option<()>
Implementors§
impl BufferExt for Buffer
impl BufferExt for MockBuffer
impl BufferExt for MockBufferExt
Extension trait for Buffer to provide extra functionalities.
Provides focused helpers for line fetching and text insertion at the current
cursor position while surfacing Nvim errors via notify_error.