hjkl_buffer/lib.rs
1//! # hjkl-buffer
2//!
3//! Rope-backed text buffer with vim-shaped semantics: charwise/linewise/
4//! blockwise selection, motions matching vim edge cases (no `h` wrap, `$`
5//! clamp, sticky col on `j`/`k`), folds, viewport, and search.
6//!
7//! Extracted from `sqeel-buffer` with full git history.
8//!
9//! ## Pre-1.0 stability
10//!
11//! Pre-1.0: signatures may shift between patch versions. The invariants
12//! documented on each type and function are the load-bearing semantics — they
13//! will not silently change without a CHANGELOG entry and a deliberate version
14//! bump.
15//!
16//! ## Why so many invariants?
17//!
18//! Most of them follow from one rule: **the engine layer treats
19//! [`Buffer`] as the source of truth for text content**. Any divergence
20//! between cached state (engine-side selections, undo stacks, search matches)
21//! and the buffer's `lines()` is a bug. The invariants documented on each type
22//! are the contract that lets the engine cache aggressively without risking
23//! that divergence.
24//!
25//! Open issues: <https://github.com/kryptic-sh/hjkl/issues>.
26//!
27//! ## Testing your `Buffer` use
28//!
29//! Property tests are encouraged for any non-trivial caller. The crate ships
30//! its own test suite; reuse [`Buffer::from_str`] to construct fixtures from
31//! inline strings.
32//!
33//! Things worth proving:
34//!
35//! - After any sequence of valid edits + their inverses, the buffer returns to
36//! its original `lines()`.
37//! - For any valid [`Position`] and motion call, the resulting cursor is itself
38//! valid.
39//! - [`Buffer::dirty_gen`] strictly increases across mutations and stays
40//! constant across read-only queries.
41
42#![deny(unsafe_op_in_unsafe_fn)]
43
44mod buffer;
45pub mod content;
46mod edit;
47mod folds;
48pub mod geom;
49mod motion;
50mod position;
51mod selection;
52mod span;
53mod viewport;
54pub mod wrap;
55
56pub use buffer::Buffer;
57pub use content::Content;
58pub use edit::{Edit, MotionKind};
59pub use folds::Fold;
60pub use geom::visual_col_to_char_col;
61pub use motion::is_keyword_char;
62pub use position::Position;
63pub use selection::{RowSpan, Selection};
64pub use span::Span;
65pub use viewport::{Viewport, is_big_viewport_jump, over_provisioned_range};
66pub use wrap::Wrap;
67
68/// Stable per-buffer identifier carried through async pipelines
69/// (syntax, git-signs, format-worker) so workers can multiplex per-buffer
70/// state without holding buffer references.
71///
72/// Assigned by the application layer; 0 is a valid test sentinel.
73///
74/// # Example
75///
76/// ```
77/// use hjkl_buffer::BufferId;
78/// let id: BufferId = 42;
79/// assert_eq!(id, 42);
80/// ```
81pub type BufferId = u64;