From 53974aadf2205d2a38223067508265bf9fbecc2a Mon Sep 17 00:00:00 2001 From: Oliver Sargison Date: Sat, 1 Jul 2023 19:02:08 +1200 Subject: [PATCH] Added set-register command Adds a typable command to push a value onto a register. Useful for keybinds --- helix-term/src/commands/typed.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 5198e5bdf5cf..647fd66fea7b 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -2144,6 +2144,29 @@ fn pipe_impl( Ok(()) } +fn set_register( + cx: &mut compositor::Context, + args: &[Cow], + event: PromptEvent, +) -> anyhow::Result<()> { + if event != PromptEvent::Validate { + return Ok(()); + } + ensure!(args.len() == 2, ":set-register "); + + match args[0].chars().next() { + None => cx.editor.set_status("Pass a character for the register!"), + Some(register) => { + let value = args[1].to_string(); + cx.editor + .set_status(format!("register {register} set to {value}")); + cx.editor.registers.push(register, value); + } + } + + Ok(()) +} + fn run_shell_command( cx: &mut compositor::Context, args: &[Cow], @@ -2292,6 +2315,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ fun: open, signature: CommandSignature::all(completers::filename), }, + TypableCommand { + name: "set-register", + aliases: &["sr"], + doc: "Set the value of a register", + fun: set_register, + signature: CommandSignature::none(), + }, TypableCommand { name: "buffer-close", aliases: &["bc", "bclose"],