Skip to main content

nvrim/
buffer.rs

1//! Buffer text extraction helpers exposed to Lua.
2//!
3//! Provides a dictionary with functions to obtain visual selection lines and classify the word under
4//! cursor (see `token_under_cursor`).
5
6use nvim_oxi::Dictionary;
7
8pub mod token_under_cursor;
9
10/// [`Dictionary`] of buffer text helpers.
11///
12/// Entries:
13/// - `"get_visual_selection"`: wraps [`ytil_noxi::visual_selection::get_lines`] and returns the current visual
14///   selection (inclusive) as lines.
15/// - `"get_selection_for_ex_range"`: returns selected text plus 0-based buffer coordinates for an Ex range.
16/// - `"get_marked_visual_selection"`: returns persisted visual text plus 0-based buffer coordinates.
17/// - `"get_visual_range_command_prefix"`: returns the Ex range prefix for a persisted visual range.
18/// - `"get_token_under_cursor"`: wraps [`crate::buffer::token_under_cursor::get`] and returns a classified token under
19///   the cursor.
20///
21/// Intended for exposure to Lua.
22pub fn dict() -> Dictionary {
23    dict! {
24        "get_marked_visual_selection": fn_from!(ytil_noxi::visual_selection::get_marked),
25        "get_selection_for_ex_range": fn_from!(ytil_noxi::visual_selection::get_for_ex_range),
26        "get_visual_range_command_prefix": fn_from!(ytil_noxi::visual_selection::get_visual_range_command_prefix),
27        "get_visual_selection_lines": fn_from!(ytil_noxi::visual_selection::get_lines),
28        "get_token_under_cursor": fn_from!(token_under_cursor::get),
29    }
30}