aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-03-13 20:50:42 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2017-03-13 20:50:42 +0100
commite88608eae24ae5934034e1ecb6c494fefbf1b9ae (patch)
treec9cbd901b79f338250ab243cc8522682b5da18de
parent02a2a278f6684f742fe131e1b598ca01cfa240db (diff)
downloadbusybox-w32-e88608eae24ae5934034e1ecb6c494fefbf1b9ae.tar.gz
busybox-w32-e88608eae24ae5934034e1ecb6c494fefbf1b9ae.tar.bz2
busybox-w32-e88608eae24ae5934034e1ecb6c494fefbf1b9ae.zip
vi: don't touch file with :x when modified_count == 0
Along with it, there are other changes - Check for uppercase X is removed as the expression will be always false and :X itself is another totally different command in standard vim - The status line will show number of written lines instead of lines requested by the colon command. This is also how the standard vim is doing, though the difference is that '!' has to be explicitly specified in vim to allow partial writes Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--editors/vi.c43
1 files changed, 26 insertions, 17 deletions
diff --git a/editors/vi.c b/editors/vi.c
index bbaac50df..1e39b52ff 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -1034,7 +1034,9 @@ static void colon(char *buf)
1034 || strncmp(p, "wn", cnt) == 0 1034 || strncmp(p, "wn", cnt) == 0
1035 || (p[0] == 'x' && !p[1]) 1035 || (p[0] == 'x' && !p[1])
1036 ) { 1036 ) {
1037 cnt = file_write(current_filename, text, end - 1); 1037 if (modified_count != 0 || p[0] != 'x') {
1038 cnt = file_write(current_filename, text, end - 1);
1039 }
1038 if (cnt < 0) { 1040 if (cnt < 0) {
1039 if (cnt == -1) 1041 if (cnt == -1)
1040 status_line_bold("Write error: %s", strerror(errno)); 1042 status_line_bold("Write error: %s", strerror(errno));
@@ -1045,8 +1047,9 @@ static void colon(char *buf)
1045 current_filename, 1047 current_filename,
1046 count_lines(text, end - 1), cnt 1048 count_lines(text, end - 1), cnt
1047 ); 1049 );
1048 if (p[0] == 'x' || p[1] == 'q' || p[1] == 'n' 1050 if (p[0] == 'x'
1049 || p[0] == 'X' || p[1] == 'Q' || p[1] == 'N' 1051 || p[1] == 'q' || p[1] == 'n'
1052 || p[1] == 'Q' || p[1] == 'N'
1050 ) { 1053 ) {
1051 editing = 0; 1054 editing = 0;
1052 } 1055 }
@@ -1476,16 +1479,19 @@ static void colon(char *buf)
1476 goto ret; 1479 goto ret;
1477 } 1480 }
1478#endif 1481#endif
1479 // how many lines in text[]?
1480 li = count_lines(q, r);
1481 size = r - q + 1;
1482 //if (useforce) { 1482 //if (useforce) {
1483 // if "fn" is not write-able, chmod u+w 1483 // if "fn" is not write-able, chmod u+w
1484 // sprintf(syscmd, "chmod u+w %s", fn); 1484 // sprintf(syscmd, "chmod u+w %s", fn);
1485 // system(syscmd); 1485 // system(syscmd);
1486 // forced = TRUE; 1486 // forced = TRUE;
1487 //} 1487 //}
1488 l = file_write(fn, q, r); 1488 if (modified_count != 0 || cmd[0] != 'x') {
1489 size = r - q + 1;
1490 l = file_write(fn, q, r);
1491 } else {
1492 size = 0;
1493 l = 0;
1494 }
1489 //if (useforce && forced) { 1495 //if (useforce && forced) {
1490 // chmod u-w 1496 // chmod u-w
1491 // sprintf(syscmd, "chmod u-w %s", fn); 1497 // sprintf(syscmd, "chmod u-w %s", fn);
@@ -1496,17 +1502,20 @@ static void colon(char *buf)
1496 if (l == -1) 1502 if (l == -1)
1497 status_line_bold_errno(fn); 1503 status_line_bold_errno(fn);
1498 } else { 1504 } else {
1505 // how many lines written
1506 li = count_lines(q, q + l - 1);
1499 status_line("'%s' %dL, %dC", fn, li, l); 1507 status_line("'%s' %dL, %dC", fn, li, l);
1500 if (q == text && r == end - 1 && l == size) { 1508 if (l == size) {
1501 modified_count = 0; 1509 if (q == text && q + l == end) {
1502 last_modified_count = -1; 1510 modified_count = 0;
1503 } 1511 last_modified_count = -1;
1504 if ((cmd[0] == 'x' || cmd[1] == 'q' || cmd[1] == 'n' 1512 }
1505 || cmd[0] == 'X' || cmd[1] == 'Q' || cmd[1] == 'N' 1513 if (cmd[0] == 'x'
1506 ) 1514 || cmd[1] == 'q' || cmd[1] == 'n'
1507 && l == size 1515 || cmd[1] == 'Q' || cmd[1] == 'N'
1508 ) { 1516 ) {
1509 editing = 0; 1517 editing = 0;
1518 }
1510 } 1519 }
1511 } 1520 }
1512#if ENABLE_FEATURE_VI_YANKMARK 1521#if ENABLE_FEATURE_VI_YANKMARK