BufferExt

Trait BufferExt 

Source
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§

Source

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_lines fails.
  • The requested index is out of range (no line returned).
Source

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_indexing is 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.

Source

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.

Source

fn get_channel(&self) -> Option<u32>

Source

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.

Source

fn get_pid(&self) -> Result<String>

Retrieves the process ID associated with the buffer.

§Errors
  • If the buffer name cannot be retrieved.
  • If the buffer is a terminal but the name format is invalid.
  • If the Neovim getpid function call fails.

Provided Methods§

Source

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.
Source

fn is_terminal(&self) -> bool

Source

fn send_command(&self, cmd: &str) -> Option<()>

Implementors§

Source§

impl BufferExt for Buffer

Source§

impl BufferExt for MockBuffer

Source§

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.