on master help sign in
Add `qa` and `qa!`
17c9a84Wojciech Kępka
helix-term/src/commands.rs+50−5
@@ -1086,6 +1086,36 @@ mod cmd {
1086 _write_all(editor, args, event, true, true)
1086 _write_all(editor, args, event, true, true)
1087 }
1087 }
1088
1088
1089+ fn _quit_all(editor: &mut Editor, args: &[&str], event: PromptEvent, force: bool) {
1090+ if !force {
1091+ // check if there are some unsaved buffers
1092+ let modified = _modified_left(editor);
1093+ if !modified.is_empty() {
1094+ let err = format!(
1095+ "{} unsaved buffer(s) remaining: {:?}",
1096+ modified.len(),
1097+ modified
1098+ );
1099+ editor.set_error(err);
1100+ return;
1101+ }
1102+ }
1103+
1104+ // close all views
1105+ let views: Vec<_> = editor.tree.views().map(|(view, _)| view.id).collect();
1106+ for view_id in views {
1107+ editor.close(view_id, false);
1108+ }
1109+ }
1110+
1111+ fn quit_all(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1112+ _quit_all(editor, args, event, false)
1113+ }
1114+
1115+ fn force_quit_all(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1116+ _quit_all(editor, args, event, true)
1117+ }
1118+
1089 pub const COMMAND_LIST: &[Command] = &[
1119 pub const COMMAND_LIST: &[Command] = &[
1090 Command {
1120 Command {
1091 name: "quit",
1121 name: "quit",
@@ -1165,19 +1195,34 @@ mod cmd {
1165 completer: None,
1195 completer: None,
1166 },
1196 },
1167 Command {
1197 Command {
1168− name: "write-all-quit",
1198+ name: "write-quit-all",
1169− alias: Some("waq"),
1199+ alias: Some("wqa"),
1170 doc: "Writes changes from all views to disk and close all views.",
1200 doc: "Writes changes from all views to disk and close all views.",
1171 fun: write_all_quit,
1201 fun: write_all_quit,
1172 completer: None,
1202 completer: None,
1173 },
1203 },
1174 Command {
1204 Command {
1175− name: "write-all-quit!",
1205+ name: "write-quit-all!",
1176− alias: Some("waq!"),
1206+ alias: Some("wqa!"),
1177− doc: "Writes changes from all views to disk and close all views forcefully (ignoring errors).",
1207+ doc: "Writes changes from all views to disk and close all views forcefully (ignoring unsaved changes).",
1178 fun: force_write_all_quit,
1208 fun: force_write_all_quit,
1179 completer: None,
1209 completer: None,
1180 },
1210 },
1211+ Command {
1212+ name: "quit-all",
1213+ alias: Some("qa"),
1214+ doc: "Close all views.",
1215+ fun: quit_all,
1216+ completer: None,
1217+ },
1218+ Command {
1219+ name: "quit-all!",
1220+ alias: Some("qa!"),
1221+ doc: "Close all views forcefully (ignoring unsaved changes).",
1222+ fun: force_quit_all,
1223+ completer: None,
1224+ },
1225+
1181 ];
1226 ];
1182
1227
1183 pub static COMMANDS: Lazy<HashMap<&'static str, &'static Command>> = Lazy::new(|| {
1228 pub static COMMANDS: Lazy<HashMap<&'static str, &'static Command>> = Lazy::new(|| {