hjkl_engine/lib.rs
1//! Vim-mode editor engine built on top of [`hjkl_buffer`].
2//!
3//! Exposes an [`Editor`] you can drop into a ratatui layout, a command
4//! grammar that covers the bulk of vim's normal / insert / visual /
5//! visual-line / visual-block modes, text-object operators, dot-repeat,
6//! and ex-command handling (`:s/foo/bar/g`, `:w`, `:q`, `:noh`, ...).
7//! Rendering goes through `hjkl_buffer::BufferView`; selection / gutter
8//! highlights are painted in the same single-pass as text.
9//!
10//! Imported wholesale from sqeel-vim with full git history. The trait
11//! extraction (Selection / SelectionSet / Buffer + Host sub-traits per
12//! [`SPEC.md`][spec]) lands progressively under [`crate::types`]. Pre-1.0
13//! churn — the public surface may change in patch bumps.
14//!
15//! [spec]: https://github.com/kryptic-sh/hjkl/blob/main/crates/hjkl-engine/SPEC.md
16//!
17//! The legacy public surface is intentionally narrow:
18//!
19//! - [`Editor`] — the editor widget.
20//! - [`KeybindingMode`] / [`VimMode`] — mode enums used by host apps.
21//! - [`ex::run`] / [`ex::ExEffect`] — drive ex-mode commands.
22
23mod buf_helpers;
24mod buffer_impl;
25mod editor;
26mod input;
27pub mod motions;
28mod registers;
29pub mod search;
30pub mod types;
31mod viewport_math;
32mod vim;
33
34pub use editor::{Editor, LspIntent};
35pub use input::{Input, Key};
36pub use registers::{Registers, Slot};
37
38pub use buffer_impl::{BufferFoldProvider, BufferFoldProviderMut};
39pub use types::{
40 Attrs, Buffer, BufferEdit, BufferId, Color, Cursor, CursorShape, DefaultHost, Edit,
41 EditorSnapshot, EngineError, FoldOp, FoldProvider, Highlight, HighlightKind, Host,
42 Input as PlannedInput, Mode, Modifiers, MouseEvent, MouseKind, NoopFoldProvider, OptionValue,
43 Options, Pos, Query, RenderFrame, Search, Selection, SelectionKind, SelectionSet, SnapshotMode,
44 SpecialKey, Style, Viewport, WrapMode,
45};
46pub use vim::SearchPrompt;
47
48// 0.0.32 dropped the `#[deprecated]` re-export aliases introduced at
49// 0.0.31 (`SpecBuffer`, `SpecBufferEdit`, `EditOp`, `PlannedViewport`).
50// Consumers must use the canonical names: `Buffer`, `BufferEdit`,
51// `Edit`, `Viewport`.
52
53/// Which keyboard discipline the editor uses. Currently vim-only, but
54/// kept as an enum so future emacs / plain bindings can slot in without
55/// touching the public signature.
56#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
57pub enum KeybindingMode {
58 #[default]
59 Vim,
60}
61
62#[cfg(feature = "serde")]
63impl serde::Serialize for KeybindingMode {
64 fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
65 s.serialize_str("vim")
66 }
67}
68
69#[cfg(feature = "serde")]
70impl<'de> serde::Deserialize<'de> for KeybindingMode {
71 fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
72 let _ = String::deserialize(d)?;
73 Ok(KeybindingMode::Vim)
74 }
75}
76
77/// Coarse vim-mode a host app can display in its status line.
78#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
79pub enum VimMode {
80 #[default]
81 Normal,
82 Insert,
83 Visual,
84 VisualLine,
85 VisualBlock,
86}