From 17c9a8499eb5fc923c83d7d03100ecd2c76bcfe9 Mon Sep 17 00:00:00 2001 From: Wojciech Kępka Date: Sun, 13 Jun 2021 11:06:06 +0200 Subject: Add `qa` and `qa!` --- helix-term/src/commands.rs | 55 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 5 deletions(-) (limited to 'helix-term') diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 9d190da1..13ca8bfd 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1086,6 +1086,36 @@ mod cmd { _write_all(editor, args, event, true, true) } + fn _quit_all(editor: &mut Editor, args: &[&str], event: PromptEvent, force: bool) { + if !force { + // check if there are some unsaved buffers + let modified = _modified_left(editor); + if !modified.is_empty() { + let err = format!( + "{} unsaved buffer(s) remaining: {:?}", + modified.len(), + modified + ); + editor.set_error(err); + return; + } + } + + // close all views + let views: Vec<_> = editor.tree.views().map(|(view, _)| view.id).collect(); + for view_id in views { + editor.close(view_id, false); + } + } + + fn quit_all(editor: &mut Editor, args: &[&str], event: PromptEvent) { + _quit_all(editor, args, event, false) + } + + fn force_quit_all(editor: &mut Editor, args: &[&str], event: PromptEvent) { + _quit_all(editor, args, event, true) + } + pub const COMMAND_LIST: &[Command] = &[ Command { name: "quit", @@ -1165,19 +1195,34 @@ mod cmd { completer: None, }, Command { - name: "write-all-quit", - alias: Some("waq"), + name: "write-quit-all", + alias: Some("wqa"), doc: "Writes changes from all views to disk and close all views.", fun: write_all_quit, completer: None, }, Command { - name: "write-all-quit!", - alias: Some("waq!"), - doc: "Writes changes from all views to disk and close all views forcefully (ignoring errors).", + name: "write-quit-all!", + alias: Some("wqa!"), + doc: "Writes changes from all views to disk and close all views forcefully (ignoring unsaved changes).", fun: force_write_all_quit, completer: None, }, + Command { + name: "quit-all", + alias: Some("qa"), + doc: "Close all views.", + fun: quit_all, + completer: None, + }, + Command { + name: "quit-all!", + alias: Some("qa!"), + doc: "Close all views forcefully (ignoring unsaved changes).", + fun: force_quit_all, + completer: None, + }, + ]; pub static COMMANDS: Lazy> = Lazy::new(|| { -- cgit v1.2.3-70-g09d2