Browse Source

vi: :wq/:x should warn if there are more files to edit

':wq' or ':x' should issue a warning if there are more files to edit,
unless they're followed by '!'.

function                                             old     new   delta
colon                                               3911    3960     +49
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 49/0)               Total: 49 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Ron Yorston 3 years ago
parent
commit
8e71f2aab8
1 changed files with 14 additions and 3 deletions
  1. 14 3
      editors/vi.c

+ 14 - 3
editors/vi.c

@@ -3181,9 +3181,20 @@ static void colon(char *buf)
 					modified_count = 0;
 					last_modified_count = -1;
 				}
-				if (cmd[0] == 'x'
-				 || cmd[1] == 'q' || cmd[1] == 'n'
-				) {
+				if (cmd[1] == 'n') {
+					editing = 0;
+				} else if (cmd[0] == 'x' || cmd[1] == 'q') {
+					// are there other files to edit?
+					int n = cmdline_filecnt - optind - 1;
+					if (n > 0) {
+						if (useforce) {
+							// force end of argv list
+							optind = cmdline_filecnt;
+						} else {
+							status_line_bold("%u more file(s) to edit", n);
+							goto ret;
+						}
+					}
 					editing = 0;
 				}
 			}