Skip to main content

hjkl_engine/
abbrev.rs

1//! Engine-owned abbreviation types.
2
3/// A single abbreviation entry (insert-mode or cmdline-mode, recursive or noremap).
4///
5/// Mode flags: `insert` = expand in Insert mode, `cmdline` = expand in Cmdline mode.
6/// `noremap` stores whether the definition was made with `noreabbrev`; expansion
7/// is always literal text regardless of this flag, but it is preserved for future use.
8///
9/// NOTE: Abbreviations are currently per-editor (global in vim would share across
10/// buffers; per-editor is equivalent for single-buffer use and is acceptable for
11/// now — cross-buffer global behaviour is a follow-up).
12#[derive(Debug, Clone)]
13pub struct Abbrev {
14    pub lhs: String,
15    pub rhs: String,
16    pub insert: bool,
17    pub cmdline: bool,
18    pub noremap: bool,
19}
20
21/// Trigger kind for abbreviation expansion.
22#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23pub enum AbbrevTrigger {
24    /// A non-keyword character was typed (e.g. space, punctuation).
25    NonKeyword(char),
26    /// `<C-]>` was pressed — expand without inserting any character.
27    CtrlBracket,
28    /// `<CR>` (Enter) was pressed.
29    Cr,
30    /// `<Esc>` was pressed to leave insert mode.
31    Esc,
32}
33
34/// Classify a vim abbreviation lhs into its type.
35///
36/// - **Full**: every char in `lhs` is a keyword char (full-id).
37/// - **End**: the last char is a keyword char, at least one other is not (end-id).
38/// - **None**: the last char is a non-keyword char (non-id).
39#[derive(Debug, Clone, Copy, PartialEq, Eq)]
40pub enum AbbrevKind {
41    /// All keyword chars (full-id).
42    Full,
43    /// Last char keyword, others include non-keyword (end-id).
44    End,
45    /// Last char is non-keyword (non-id).
46    NonKw,
47}