Skip to main content

populate

Function populate 

Source
pub fn populate(registry: &mut CommandRegistry) -> Builtins
Expand description

Register every native built-in motion, operator and text object into registry, and return their ids.

Call once per registry, at boot. Each call mints fresh ids, so calling it twice re-registers every name onto new ids (the name index then points at the second set). Also tags w / W as word-forward motions (see CommandRegistry::tag_word_forward_motion).

ยงExamples

dw on hello world: the delete operator with a word-forward target.

use lattice_core::{BufferId, Document};
use lattice_grammar::{
    Args, CancellationToken, CommandInvocation, CommandRegistry, Effect, Target, builtins,
    execute,
};
use lattice_protocol::position::Position;

let mut registry = CommandRegistry::new();
let b = builtins::populate(&mut registry);
assert_eq!(registry.id_by_name("motion:word-forward"), Some(b.word_forward.0));

let mut doc = Document::from_text("hello world");
let dw = CommandInvocation::of(b.delete.0).with_target(Target::Motion(b.word_forward, Args::None));
let effect = execute(
    &registry,
    &mut doc,
    BufferId(0),
    Position::ZERO,
    dw,
    &CancellationToken::never(),
)
.unwrap();

// The operator edited the document in place and reports the edit plus
// the yank into the unnamed register.
assert_eq!(doc.text().to_string(), "world");
assert!(matches!(effect, Effect::Many(ref parts) if parts.len() == 2));