Skip to main content

MotionSpec

Struct MotionSpec 

Source
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(
    &registry,
    &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: bool

A 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: bool

Whether 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: CurswantEffect

VM.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

Source§

fn clone(&self) -> MotionSpec

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MotionSpec

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more