vi: avoid touching a new file with ZZ when no editing has been done
authorYousong Zhou <yszhou4tech@gmail.com>
Fri, 24 Mar 2017 20:13:10 +0000 (21:13 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Fri, 24 Mar 2017 20:13:10 +0000 (21:13 +0100)
This is the behaviour observed with standard vim and busybox vi of at
least 1.22.1.  It was changed with commit "32afd3a vi: some
simplifications" which happened before 1.23.0.

Mistyping filename on command line happens fairly often and it's better
we restore the old behaviour to avoid a few unnecessary flash writes and
sometimes efforts of debugging bugs caused by those unneeded stray
files.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
editors/vi.c

index 1e39b52ff72540f813f199470b8e15f2a56f5113..f33db66c655d8ac40921e3202f3786ff51a27961 100644 (file)
@@ -715,14 +715,6 @@ static int init_text_buffer(char *fn)
 {
        int rc;
 
-       flush_undo_data();
-       modified_count = 0;
-       last_modified_count = -1;
-#if ENABLE_FEATURE_VI_YANKMARK
-       /* init the marks */
-       memset(mark, 0, sizeof(mark));
-#endif
-
        /* allocate/reallocate text buffer */
        free(text);
        text_size = 10240;
@@ -737,6 +729,14 @@ static int init_text_buffer(char *fn)
                // file doesnt exist. Start empty buf with dummy line
                char_insert(text, '\n', NO_UNDO);
        }
+
+       flush_undo_data();
+       modified_count = 0;
+       last_modified_count = -1;
+#if ENABLE_FEATURE_VI_YANKMARK
+       /* init the marks */
+       memset(mark, 0, sizeof(mark));
+#endif
        return rc;
 }