macro_rules! keymap_entry {
{ mode: $m:ident, $($rest:tt)* } => { ... };
{ mode: [ $($m:ident),+ $(,)? ], $($rest:tt)* } => { ... };
(@build $modes:tt chord: $chord:expr, doc: $doc:expr $(,)?) => { ... };
(@build $modes:tt chord: $chord:expr, doc: $doc:expr, cmd: $cmd:literal, fall_through: $ft:expr $(,)?) => { ... };
(@build $modes:tt chord: $chord:expr, doc: $doc:expr, cmd: $cmd:literal $(,)?) => { ... };
(@build $modes:tt chord: $chord:expr, doc: $doc:expr, cmd: $cmd:expr, fall_through: $ft:expr $(,)?) => { ... };
(@build $modes:tt chord: $chord:expr, doc: $doc:expr, cmd: $cmd:expr $(,)?) => { ... };
}Expand description
Construct a KeymapEntry with the row’s source location captured
at the macro invocation site. Forms:
keymap_entry! { mode: Normal, chord: "j", doc: "Move down", cmd: "motion:line-down" }keymap_entry! { mode: Help, chord: "j", doc: "Scroll down" }(no cmd, defaults to None)keymap_entry! { mode: Normal, chord: "x", doc: "Custom", cmd: Some("plugin:foo") }(explicit Option)keymap_entry! { mode: [Normal, Visual], chord: "zn", doc: "Narrow", cmd: "operator:narrow" }(multi-mode)
The mode: slot accepts a single mode (Normal) or a bracketed list
([Normal, Visual]). A single mode sugars to a one-element slice, so
there is ONE code path: every entry carries modes: &[BindingMode],
and the host translation pass fans it out into one binding per mode.
Existing single-mode call sites are unchanged.
Expansion goes through KeymapEntry::__new so the source field
stays private — callers cannot bypass per-row provenance by
hand-rolling a literal. file!() and line!() expand at the
macro invocation site, so each row in a static slice records its
own distinct line.
K.3: usable from any crate that depends on lattice-keymap (directly)
or transitively through lattice-mode, lattice-host, or lattice-ui-tui.
The path qualifier $crate::keymap_entry::KeymapEntry::__new resolves
inside lattice-keymap; callers use lattice_keymap::keymap_entry! { … },
lattice_mode::keymap_entry! { … }, or lattice_host::keymap_entry!.
§Examples
use lattice_keymap::{BindingMode, keymap_entry};
let e = keymap_entry! { mode: Normal, chord: "j", doc: "Move down", cmd: "motion:line-down" };
assert_eq!(e.command, Some("motion:line-down"));
assert_eq!(e.modes, [BindingMode::Normal].as_slice());
assert!(!e.fall_through);
// Multi-mode, no command (a synthetic action), augment-and-continue.
let e = keymap_entry! {
mode: [Insert, Snippet], chord: "<Esc>", doc: "Leave", cmd: None, fall_through: true
};
assert_eq!(e.command, None);
assert_eq!(e.modes_label(), "Insert, Active-snippet (minor mode)");
assert!(e.fall_through);