Skip to content

Commit

Permalink
Implement buffer-close-all
Browse files Browse the repository at this point in the history
  • Loading branch information
EpocSquadron committed Feb 19, 2022
1 parent a449156 commit 89472c8
Showing 1 changed file with 42 additions and 0 deletions.
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,
},
TypableCommand {
name: "write",
aliases: &["w"],
Expand Down

0 comments on commit 89472c8

Please sign in to comment.