Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement bulk buffer closing commands #1677

Merged
Next Next commit
Implement buffer-close-all
  • Loading branch information
EpocSquadron committed Feb 27, 2022
commit 83b94ac734b56973fe099e348636e9d69cb750ba
42 changes: 42 additions & 0 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2135,6 +2135,34 @@ pub mod cmd {
buffer_close_impl(cx.editor, args, true)
}

fn buffer_close_all(
cx: &mut compositor::Context,
_args: &[Cow<str>],
_event: PromptEvent,
) -> anyhow::Result<()> {
let all_documents: Vec<_> = cx.editor.documents().map(|doc| doc.id()).collect();

for doc_id in all_documents {
cx.editor.close_document(doc_id, false)?;
}

Ok(())
}

fn force_buffer_close_all(
cx: &mut compositor::Context,
_args: &[Cow<str>],
_event: PromptEvent,
) -> anyhow::Result<()> {
let all_documents: Vec<_> = cx.editor.documents().map(|doc| doc.id()).collect();

for doc_id in all_documents {
cx.editor.close_document(doc_id, true)?;
}

Ok(())
}

fn write_impl(cx: &mut compositor::Context, path: Option<&Cow<str>>) -> anyhow::Result<()> {
let jobs = &mut cx.jobs;
let doc = doc_mut!(cx.editor);
Expand Down Expand Up @@ -2970,6 +2998,20 @@ pub mod cmd {
fun: force_buffer_close,
completer: Some(completers::buffer),
},
TypableCommand {
name: "buffer-close-all",
aliases: &["bca", "bcloseall"],
doc: "Close all buffers, without quiting.",
fun: buffer_close_all,
completer: None,
},
TypableCommand {
name: "buffer-close-all!",
aliases: &["bca!", "bcloseall!"],
doc: "Close all buffers forcefully (ignoring unsaved changes), without quiting.",
fun: force_buffer_close_all,
completer: None,
},
EpocSquadron marked this conversation as resolved.
Show resolved Hide resolved
TypableCommand {
name: "write",
aliases: &["w"],
Expand Down