pub struct MotionSpec {
pub jump: bool,
pub exclusive: bool,
pub curswant: CurswantEffect,
pub apply: Arc<dyn Fn(&MotionContext<'_>) -> GrammarResult<MotionResult> + Send + Sync>,
pub args_schema: Vec<ArgSpec>,
}Expand description
A registered motion: its evaluator plus the vim properties the dispatcher and host need without running it.
Registered through CommandRegistry::register_motion (or
CommandRegistry::register_plugin_motion). The dispatcher runs
apply for a bare motion (the cursor moves to the result) and for an
operator target (the span is cursor..result, shaped by exclusive and
the result’s linewise).
§Examples
A motion that jumps to the end of the buffer (a simplified G):
use std::sync::Arc;
use lattice_core::{BufferId, Document};
use lattice_grammar::{
CancellationToken, CommandInvocation, CommandRegistry, CurswantEffect, Effect, MotionSpec,
execute,
};
use lattice_grammar::registry::MotionResult;
use lattice_protocol::position::Position;
let mut registry = CommandRegistry::new();
let id = registry.register_motion(
"motion:buffer-end",
"Move to the start of the last line.",
MotionSpec {
jump: true,
exclusive: false,
curswant: CurswantEffect::default(),
args_schema: vec![],
apply: Arc::new(|ctx| {
let last = ctx.buffer.content_line_count().saturating_sub(1);
Ok(MotionResult { target: Position::new(last, 0), ..Default::default() })
}),
},
);
assert!(registry.motion_is_jump(id.0));
let mut doc = Document::from_text("one\ntwo\nthree");
let effect = execute(
®istry,
&mut doc,
BufferId(0),
Position::ZERO,
CommandInvocation::of(id.0),
&CancellationToken::never(),
)
.unwrap();
assert!(matches!(effect, Effect::CursorMove(p) if p == Position::new(2, 0)));Fields§
§jump: boolA vim jump: the host records the origin in position history (so
<C-o> returns) and opens folds at the destination. Read through
CommandRegistry::motion_is_jump.
exclusive: boolWhether the motion’s end position is excluded from an operator’s span
(w, b, 0 are exclusive; e, f, $ are inclusive). A
MotionResult::exclusive overrides it per invocation.
curswant: CurswantEffectVM.3g-1: this motion’s effect on the goal column. See CurswantEffect.
apply: Arc<dyn Fn(&MotionContext<'_>) -> GrammarResult<MotionResult> + Send + Sync>The evaluator. Pure: reads the MotionContext, returns where to go.
args_schema: Vec<ArgSpec>Per-positional-argument metadata (DESIGN.md §B.1). Empty for motions without args (the common case).
Trait Implementations§
Source§impl Clone for MotionSpec
impl Clone for MotionSpec
Source§fn clone(&self) -> MotionSpec
fn clone(&self) -> MotionSpec
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more