1
0

402-vi-avoid-touching-a-new-file-with-ZZ-when-no-editing.patch 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. This is the behaviour observed with standard vim and busybox vi of at
  7. least 1.22.1. It was changed with commit "32afd3a vi: some
  8. simplifications" which happened before 1.23.0.
  9. Mistyping filename on command line happens fairly often and it's better
  10. we restore the old behaviour to avoid a few unnecessary flash writes and
  11. sometimes efforts of debugging bugs caused by those unneeded stray
  12. files.
  13. Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
  14. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
  15. ---
  16. editors/vi.c | 16 ++++++++--------
  17. 1 file changed, 8 insertions(+), 8 deletions(-)
  18. --- a/editors/vi.c
  19. +++ b/editors/vi.c
  20. @@ -719,14 +719,6 @@ static int init_text_buffer(char *fn)
  21. {
  22. int rc;
  23. - flush_undo_data();
  24. - modified_count = 0;
  25. - last_modified_count = -1;
  26. -#if ENABLE_FEATURE_VI_YANKMARK
  27. - /* init the marks */
  28. - memset(mark, 0, sizeof(mark));
  29. -#endif
  30. -
  31. /* allocate/reallocate text buffer */
  32. free(text);
  33. text_size = 10240;
  34. @@ -741,6 +733,14 @@ static int init_text_buffer(char *fn)
  35. // file doesnt exist. Start empty buf with dummy line
  36. char_insert(text, '\n', NO_UNDO);
  37. }
  38. +
  39. + flush_undo_data();
  40. + modified_count = 0;
  41. + last_modified_count = -1;
  42. +#if ENABLE_FEATURE_VI_YANKMARK
  43. + /* init the marks */
  44. + memset(mark, 0, sizeof(mark));
  45. +#endif
  46. return rc;
  47. }