busybox: vi: backporting patches to fix ZZ and :x command
[openwrt/openwrt.git] / package / utils / busybox / patches / 402-vi-avoid-touching-a-new-file-with-ZZ-when-no-editing.patch
1 From 8f3bf4f0d3605b50a8e4c48c89aeabc455f04884 Mon Sep 17 00:00:00 2001
2 From: Yousong Zhou <yszhou4tech@gmail.com>
3 Date: Fri, 24 Mar 2017 21:13:10 +0100
4 Subject: [PATCH 2/2] vi: avoid touching a new file with ZZ when no editing has
5 been done
6
7 This is the behaviour observed with standard vim and busybox vi of at
8 least 1.22.1. It was changed with commit "32afd3a vi: some
9 simplifications" which happened before 1.23.0.
10
11 Mistyping filename on command line happens fairly often and it's better
12 we restore the old behaviour to avoid a few unnecessary flash writes and
13 sometimes efforts of debugging bugs caused by those unneeded stray
14 files.
15
16 Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
17 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
18 ---
19 editors/vi.c | 16 ++++++++--------
20 1 file changed, 8 insertions(+), 8 deletions(-)
21
22 --- a/editors/vi.c
23 +++ b/editors/vi.c
24 @@ -719,14 +719,6 @@ static int init_text_buffer(char *fn)
25 {
26 int rc;
27
28 - flush_undo_data();
29 - modified_count = 0;
30 - last_modified_count = -1;
31 -#if ENABLE_FEATURE_VI_YANKMARK
32 - /* init the marks */
33 - memset(mark, 0, sizeof(mark));
34 -#endif
35 -
36 /* allocate/reallocate text buffer */
37 free(text);
38 text_size = 10240;
39 @@ -741,6 +733,14 @@ static int init_text_buffer(char *fn)
40 // file doesnt exist. Start empty buf with dummy line
41 char_insert(text, '\n', NO_UNDO);
42 }
43 +
44 + flush_undo_data();
45 + modified_count = 0;
46 + last_modified_count = -1;
47 +#if ENABLE_FEATURE_VI_YANKMARK
48 + /* init the marks */
49 + memset(mark, 0, sizeof(mark));
50 +#endif
51 return rc;
52 }
53