Skip to content

Commit

Permalink
Implement buffer-close-others
Browse files Browse the repository at this point in the history
  • Loading branch information
EpocSquadron committed Feb 19, 2022
1 parent 89472c8 commit 1b5a81c
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2135,6 +2135,42 @@ pub mod cmd {
buffer_close_impl(cx.editor, args, true)
}

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

for doc_id in all_documents
.into_iter()
.filter(|doc_id| doc_id != current_document)
{
cx.editor.close_document(doc_id, false)?;
}

Ok(())
}

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

for doc_id in all_documents
.into_iter()
.filter(|doc_id| doc_id != current_document)
{
cx.editor.close_document(doc_id, true)?;
}

Ok(())
}

fn buffer_close_all(
cx: &mut compositor::Context,
_args: &[Cow<str>],
Expand Down Expand Up @@ -2998,6 +3034,20 @@ pub mod cmd {
fun: force_buffer_close,
completer: Some(completers::buffer),
},
TypableCommand {
name: "buffer-close-others",
aliases: &["bco", "bcloseother"],
doc: "Close all buffers but the currently focused one.",
fun: buffer_close_others,
completer: None,
},
TypableCommand {
name: "buffer-close-others!",
aliases: &["bco!", "bcloseother!"],
doc: "Close all buffers but the currently focused one.",
fun: force_buffer_close_others,
completer: None,
},
TypableCommand {
name: "buffer-close-all",
aliases: &["bca", "bcloseall"],
Expand Down

0 comments on commit 1b5a81c

Please sign in to comment.