diff options
author | Dennis Groenen <tj.groenen@gmail.com> | 2012-01-31 14:12:38 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2012-01-31 14:12:38 +0100 |
commit | c0657e0d0a3a818e2c857f99f0b0ddf936324fdb (patch) | |
tree | 1641e9b0f481fcc9089f2ae981c4f975b54dd7a8 /editors/vi.c | |
parent | 800a9a056a3703b4001bf55ebc30b1c14cf55acc (diff) | |
download | busybox-w32-c0657e0d0a3a818e2c857f99f0b0ddf936324fdb.tar.gz busybox-w32-c0657e0d0a3a818e2c857f99f0b0ddf936324fdb.tar.bz2 busybox-w32-c0657e0d0a3a818e2c857f99f0b0ddf936324fdb.zip |
vi: add ":prev" command support
function old new delta
colon 2844 2891 +47
vi_main 243 255 +12
text_yank 54 56 +2
refresh 780 774 -6
Signed-off-by: Dennis Groenen <tj.groenen@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'editors/vi.c')
-rw-r--r-- | editors/vi.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/editors/vi.c b/editors/vi.c index f7b9f3873..b4ad12e5c 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -278,7 +278,6 @@ struct globals { | |||
278 | smallint cmd_mode; // 0=command 1=insert 2=replace | 278 | smallint cmd_mode; // 0=command 1=insert 2=replace |
279 | int file_modified; // buffer contents changed (counter, not flag!) | 279 | int file_modified; // buffer contents changed (counter, not flag!) |
280 | int last_file_modified; // = -1; | 280 | int last_file_modified; // = -1; |
281 | int fn_start; // index of first cmd line file name | ||
282 | int save_argc; // how many file names on cmd line | 281 | int save_argc; // how many file names on cmd line |
283 | int cmdcnt; // repetition count | 282 | int cmdcnt; // repetition count |
284 | unsigned rows, columns; // the terminal screen is this size | 283 | unsigned rows, columns; // the terminal screen is this size |
@@ -363,7 +362,6 @@ struct globals { | |||
363 | #define cmd_mode (G.cmd_mode ) | 362 | #define cmd_mode (G.cmd_mode ) |
364 | #define file_modified (G.file_modified ) | 363 | #define file_modified (G.file_modified ) |
365 | #define last_file_modified (G.last_file_modified ) | 364 | #define last_file_modified (G.last_file_modified ) |
366 | #define fn_start (G.fn_start ) | ||
367 | #define save_argc (G.save_argc ) | 365 | #define save_argc (G.save_argc ) |
368 | #define cmdcnt (G.cmdcnt ) | 366 | #define cmdcnt (G.cmdcnt ) |
369 | #define rows (G.rows ) | 367 | #define rows (G.rows ) |
@@ -599,9 +597,10 @@ int vi_main(int argc, char **argv) | |||
599 | } | 597 | } |
600 | 598 | ||
601 | // The argv array can be used by the ":next" and ":rewind" commands | 599 | // The argv array can be used by the ":next" and ":rewind" commands |
602 | // save optind. | 600 | argv += optind; |
603 | fn_start = optind; // remember first file name for :next and :rew | 601 | argc -= optind; |
604 | save_argc = argc; | 602 | save_argc = argc; |
603 | optind = 0; | ||
605 | 604 | ||
606 | //----- This is the main file handling loop -------------- | 605 | //----- This is the main file handling loop -------------- |
607 | while (1) { | 606 | while (1) { |
@@ -1021,7 +1020,7 @@ static void colon(char *buf) | |||
1021 | } else if (strncmp(cmd, "edit", i) == 0) { // Edit a file | 1020 | } else if (strncmp(cmd, "edit", i) == 0) { // Edit a file |
1022 | // don't edit, if the current file has been modified | 1021 | // don't edit, if the current file has been modified |
1023 | if (file_modified && !useforce) { | 1022 | if (file_modified && !useforce) { |
1024 | status_line_bold("No write since last change (:edit! overrides)"); | 1023 | status_line_bold("No write since last change (:%s! overrides)", cmd); |
1025 | goto ret; | 1024 | goto ret; |
1026 | } | 1025 | } |
1027 | if (args[0]) { | 1026 | if (args[0]) { |
@@ -1111,11 +1110,12 @@ static void colon(char *buf) | |||
1111 | Hit_Return(); | 1110 | Hit_Return(); |
1112 | } else if (strncmp(cmd, "quit", i) == 0 // quit | 1111 | } else if (strncmp(cmd, "quit", i) == 0 // quit |
1113 | || strncmp(cmd, "next", i) == 0 // edit next file | 1112 | || strncmp(cmd, "next", i) == 0 // edit next file |
1113 | || strncmp(cmd, "prev", i) == 0 // edit previous file | ||
1114 | ) { | 1114 | ) { |
1115 | int n; | 1115 | int n; |
1116 | if (useforce) { | 1116 | if (useforce) { |
1117 | // force end of argv list | ||
1118 | if (*cmd == 'q') { | 1117 | if (*cmd == 'q') { |
1118 | // force end of argv list | ||
1119 | optind = save_argc; | 1119 | optind = save_argc; |
1120 | } | 1120 | } |
1121 | editing = 0; | 1121 | editing = 0; |
@@ -1123,8 +1123,7 @@ static void colon(char *buf) | |||
1123 | } | 1123 | } |
1124 | // don't exit if the file been modified | 1124 | // don't exit if the file been modified |
1125 | if (file_modified) { | 1125 | if (file_modified) { |
1126 | status_line_bold("No write since last change (:%s! overrides)", | 1126 | status_line_bold("No write since last change (:%s! overrides)", cmd); |
1127 | (*cmd == 'q' ? "quit" : "next")); | ||
1128 | goto ret; | 1127 | goto ret; |
1129 | } | 1128 | } |
1130 | // are there other file to edit | 1129 | // are there other file to edit |
@@ -1137,6 +1136,14 @@ static void colon(char *buf) | |||
1137 | status_line_bold("No more files to edit"); | 1136 | status_line_bold("No more files to edit"); |
1138 | goto ret; | 1137 | goto ret; |
1139 | } | 1138 | } |
1139 | if (*cmd == 'p') { | ||
1140 | // are there previous files to edit | ||
1141 | if (optind < 1) { | ||
1142 | status_line_bold("No previous files to edit"); | ||
1143 | goto ret; | ||
1144 | } | ||
1145 | optind -= 2; | ||
1146 | } | ||
1140 | editing = 0; | 1147 | editing = 0; |
1141 | } else if (strncmp(cmd, "read", i) == 0) { // read file into text[] | 1148 | } else if (strncmp(cmd, "read", i) == 0) { // read file into text[] |
1142 | fn = args; | 1149 | fn = args; |
@@ -1172,10 +1179,10 @@ static void colon(char *buf) | |||
1172 | } | 1179 | } |
1173 | } else if (strncmp(cmd, "rewind", i) == 0) { // rewind cmd line args | 1180 | } else if (strncmp(cmd, "rewind", i) == 0) { // rewind cmd line args |
1174 | if (file_modified && !useforce) { | 1181 | if (file_modified && !useforce) { |
1175 | status_line_bold("No write since last change (:rewind! overrides)"); | 1182 | status_line_bold("No write since last change (:%s! overrides)", cmd); |
1176 | } else { | 1183 | } else { |
1177 | // reset the filenames to edit | 1184 | // reset the filenames to edit |
1178 | optind = fn_start - 1; | 1185 | optind = -1; /* start from 0th file */ |
1179 | editing = 0; | 1186 | editing = 0; |
1180 | } | 1187 | } |
1181 | #if ENABLE_FEATURE_VI_SET | 1188 | #if ENABLE_FEATURE_VI_SET |
@@ -3507,7 +3514,7 @@ static void do_cmd(int c) | |||
3507 | || strncmp(p, "q!", cnt) == 0 // delete lines | 3514 | || strncmp(p, "q!", cnt) == 0 // delete lines |
3508 | ) { | 3515 | ) { |
3509 | if (file_modified && p[1] != '!') { | 3516 | if (file_modified && p[1] != '!') { |
3510 | status_line_bold("No write since last change (:quit! overrides)"); | 3517 | status_line_bold("No write since last change (:%s! overrides)", p); |
3511 | } else { | 3518 | } else { |
3512 | editing = 0; | 3519 | editing = 0; |
3513 | } | 3520 | } |