Skip to content

Commit

Permalink
Added set-register command
Browse files Browse the repository at this point in the history
Adds a typable command to push a value onto a register. Useful for keybinds
  • Loading branch information
ElSargo committed Jul 1, 2023
1 parent a9849eb commit 53974aa
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2144,6 +2144,29 @@ fn pipe_impl(
Ok(())
}

fn set_register(
cx: &mut compositor::Context,
args: &[Cow<str>],
event: PromptEvent,
) -> anyhow::Result<()> {
if event != PromptEvent::Validate {
return Ok(());
}
ensure!(args.len() == 2, ":set-register <reg> <value>");

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<str>],
Expand Down Expand Up @@ -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"],
Expand Down

0 comments on commit 53974aa

Please sign in to comment.