mirror of https://github.com/helix-editor/helix
Merge a078a1ae51
into 362e97e927
commit
5ed2d9ec94
|
@ -89,3 +89,4 @@
|
|||
| `:read`, `:r` | Load a file into buffer |
|
||||
| `:echo` | Prints the given arguments to the statusline. |
|
||||
| `:noop` | Does nothing. |
|
||||
| `:buffer-nth`, `:bi` | Switch to the nth buffer, out of those you have open. |
|
||||
|
|
|
@ -321,6 +321,24 @@ fn buffer_previous(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn buffer_nth(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> anyhow::Result<()> {
|
||||
if event != PromptEvent::Validate {
|
||||
return Ok(());
|
||||
}
|
||||
let n: usize = args[0]
|
||||
.parse()
|
||||
.map_err(|_| anyhow!("provided argument is not an integer"))?;
|
||||
ensure!(n != 0);
|
||||
let (id, _) = if args.has_flag("reverse") {
|
||||
cx.editor.documents.iter().nth_back(n - 1)
|
||||
} else {
|
||||
cx.editor.documents.iter().nth(n - 1)
|
||||
}
|
||||
.ok_or(anyhow!("buffer {n} is out of range"))?;
|
||||
cx.editor.switch(*id, helix_view::editor::Action::Replace);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn write_impl(cx: &mut compositor::Context, path: Option<&str>, force: bool) -> anyhow::Result<()> {
|
||||
let config = cx.editor.config();
|
||||
let jobs = &mut cx.jobs;
|
||||
|
@ -3567,6 +3585,25 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
|
|||
..Signature::DEFAULT
|
||||
},
|
||||
},
|
||||
TypableCommand {
|
||||
name: "buffer-nth",
|
||||
aliases: &["bi"],
|
||||
doc: "Switch to the nth buffer, out of those you have open.",
|
||||
fun: buffer_nth,
|
||||
completer: CommandCompleter::none(),
|
||||
signature: Signature {
|
||||
positionals: (1, None),
|
||||
flags: &[
|
||||
Flag {
|
||||
name: "reverse",
|
||||
alias: Some('r'),
|
||||
doc: "count buffers from the end",
|
||||
..Flag::DEFAULT
|
||||
},
|
||||
],
|
||||
..Signature::DEFAULT
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
pub static TYPABLE_COMMAND_MAP: Lazy<HashMap<&'static str, &'static TypableCommand>> =
|
||||
|
|
Loading…
Reference in New Issue