aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--helix-term/src/commands.rs55
1 files changed, 50 insertions, 5 deletions
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<HashMap<&'static str, &'static Command>> = Lazy::new(|| {