From 739e96b9e218ee1b545671b13cf296b4a533f03d Mon Sep 17 00:00:00 2001 From: Omnikar Date: Fri, 31 Dec 2021 15:42:31 -0500 Subject: [PATCH 1/2] Add `:cquit!` command and prevent `:cquit` from ignoring unsaved changes --- helix-term/src/commands.rs | 45 ++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index ed7281150801..b431d087ab66 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -2323,12 +2323,7 @@ pub mod cmd { write_all_impl(cx, args, event, true, true) } - fn quit_all_impl( - editor: &mut Editor, - _args: &[Cow], - _event: PromptEvent, - force: bool, - ) -> anyhow::Result<()> { + fn quit_all_impl(editor: &mut Editor, force: bool) -> anyhow::Result<()> { if !force { buffers_remaining_impl(editor)?; } @@ -2344,18 +2339,18 @@ pub mod cmd { fn quit_all( cx: &mut compositor::Context, - args: &[Cow], - event: PromptEvent, + _args: &[Cow], + _event: PromptEvent, ) -> anyhow::Result<()> { - quit_all_impl(cx.editor, args, event, false) + quit_all_impl(cx.editor, false) } fn force_quit_all( cx: &mut compositor::Context, - args: &[Cow], - event: PromptEvent, + _args: &[Cow], + _event: PromptEvent, ) -> anyhow::Result<()> { - quit_all_impl(cx.editor, args, event, true) + quit_all_impl(cx.editor, true) } fn cquit( @@ -2369,12 +2364,21 @@ pub mod cmd { .unwrap_or(1); cx.editor.exit_code = exit_code; - let views: Vec<_> = cx.editor.tree.views().map(|(view, _)| view.id).collect(); - for view_id in views { - cx.editor.close(view_id); - } + quit_all_impl(cx.editor, false) + } - Ok(()) + fn force_cquit( + cx: &mut compositor::Context, + args: &[Cow], + _event: PromptEvent, + ) -> anyhow::Result<()> { + let exit_code = args + .first() + .and_then(|code| code.parse::().ok()) + .unwrap_or(1); + cx.editor.exit_code = exit_code; + + quit_all_impl(cx.editor, true) } fn theme( @@ -2878,6 +2882,13 @@ pub mod cmd { fun: cquit, completer: None, }, + TypableCommand { + name: "cquit!", + aliases: &["cq!"], + doc: "Quit with exit code (default 1) forcefully (ignoring unsaved changes). Accepts an optional integer exit code (:cq! 2).", + fun: force_cquit, + completer: None, + }, TypableCommand { name: "theme", aliases: &[], From 94738a1db49d982e5d53faf298b5a02c034b8ae6 Mon Sep 17 00:00:00 2001 From: Omnikar Date: Fri, 31 Dec 2021 15:53:07 -0500 Subject: [PATCH 2/2] `cargo xtask docgen` --- book/src/generated/typable-cmd.md | 1 + 1 file changed, 1 insertion(+) diff --git a/book/src/generated/typable-cmd.md b/book/src/generated/typable-cmd.md index 45129cc1571d..65b2dc5f1709 100644 --- a/book/src/generated/typable-cmd.md +++ b/book/src/generated/typable-cmd.md @@ -20,6 +20,7 @@ | `:quit-all`, `:qa` | Close all views. | | `:quit-all!`, `:qa!` | Close all views forcefully (ignoring unsaved changes). | | `:cquit`, `:cq` | Quit with exit code (default 1). Accepts an optional integer exit code (:cq 2). | +| `:cquit!`, `:cq!` | Quit with exit code (default 1) forcefully (ignoring unsaved changes). Accepts an optional integer exit code (:cq! 2). | | `:theme` | Change the editor theme. | | `:clipboard-yank` | Yank main selection into system clipboard. | | `:clipboard-yank-join` | Yank joined selections into system clipboard. A separator can be provided as first argument. Default value is newline. |