on master help sign in
Add `:cquit!` command and prevent `:cquit` from ignoring unsaved changes (#1414)

* Add `:cquit!` command and prevent `:cquit` from ignoring unsaved changes * `cargo xtask docgen`

commited97ecceb8d1f53bd192deeb38a1bde36a45edc2 authorOmnikar <omnikar5@gmail.com> dateSun 2 Jan 2022, 21:31 (5 years ago) parentea095ca
2 files changed+29−17
book/src/generated/typable-cmd.md+1 helix-term/src/commands.rs+28−17
book/src/generated/typable-cmd.md+1
@@ -20,6 +20,7 @@
2020| `:quit-all`, `:qa` | Close all views. |
2121| `:quit-all!`, `:qa!` | Close all views forcefully (ignoring unsaved changes). |
2222| `:cquit`, `:cq` | Quit with exit code (default 1). Accepts an optional integer exit code (:cq 2). |
23+| `:cquit!`, `:cq!` | Quit with exit code (default 1) forcefully (ignoring unsaved changes). Accepts an optional integer exit code (:cq! 2). |
2324| `:theme` | Change the editor theme. |
2425| `:clipboard-yank` | Yank main selection into system clipboard. |
2526| `:clipboard-yank-join` | Yank joined selections into system clipboard. A separator can be provided as first argument. Default value is newline. |
helix-term/src/commands.rs+28−17
@@ -2322,12 +2322,7 @@ pub mod cmd {
23222322 write_all_impl(cx, args, event, true, true)
23232323 }
23242324
2325− fn quit_all_impl(
2326− editor: &mut Editor,
2327− _args: &[Cow<str>],
2328− _event: PromptEvent,
2329− force: bool,
2330− ) -> anyhow::Result<()> {
2325+ fn quit_all_impl(editor: &mut Editor, force: bool) -> anyhow::Result<()> {
23312326 if !force {
23322327 buffers_remaining_impl(editor)?;
23332328 }
@@ -2343,18 +2338,18 @@ pub mod cmd {
23432338
23442339 fn quit_all(
23452340 cx: &mut compositor::Context,
2346− args: &[Cow<str>],
2347− event: PromptEvent,
2341+ _args: &[Cow<str>],
2342+ _event: PromptEvent,
23482343 ) -> anyhow::Result<()> {
2349− quit_all_impl(cx.editor, args, event, false)
2344+ quit_all_impl(cx.editor, false)
23502345 }
23512346
23522347 fn force_quit_all(
23532348 cx: &mut compositor::Context,
2354− args: &[Cow<str>],
2355− event: PromptEvent,
2349+ _args: &[Cow<str>],
2350+ _event: PromptEvent,
23562351 ) -> anyhow::Result<()> {
2357− quit_all_impl(cx.editor, args, event, true)
2352+ quit_all_impl(cx.editor, true)
23582353 }
23592354
23602355 fn cquit(
@@ -2368,12 +2363,21 @@ pub mod cmd {
23682363 .unwrap_or(1);
23692364 cx.editor.exit_code = exit_code;
23702365
2371− let views: Vec<_> = cx.editor.tree.views().map(|(view, _)| view.id).collect();
2372− for view_id in views {
2373− cx.editor.close(view_id);
2374− }
2366+ quit_all_impl(cx.editor, false)
2367+ }
23752368
2376− Ok(())
2369+ fn force_cquit(
2370+ cx: &mut compositor::Context,
2371+ args: &[Cow<str>],
2372+ _event: PromptEvent,
2373+ ) -> anyhow::Result<()> {
2374+ let exit_code = args
2375+ .first()
2376+ .and_then(|code| code.parse::<i32>().ok())
2377+ .unwrap_or(1);
2378+ cx.editor.exit_code = exit_code;
2379+
2380+ quit_all_impl(cx.editor, true)
23772381 }
23782382
23792383 fn theme(
@@ -2877,6 +2881,13 @@ pub mod cmd {
28772881 fun: cquit,
28782882 completer: None,
28792883 },
2884+ TypableCommand {
2885+ name: "cquit!",
2886+ aliases: &["cq!"],
2887+ doc: "Quit with exit code (default 1) forcefully (ignoring unsaved changes). Accepts an optional integer exit code (:cq! 2).",
2888+ fun: force_cquit,
2889+ completer: None,
2890+ },
28802891 TypableCommand {
28812892 name: "theme",
28822893 aliases: &[],