changeset 22985:d768cdd50602 v8.2.2039

patch 8.2.2039: viminfo is not written when creating a new file Commit: https://github.com/vim/vim/commit/8e6be34338f13a6a625f19bcef82019c9adc65f2 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Nov 23 22:01:26 2020 +0100 patch 8.2.2039: viminfo is not written when creating a new file Problem: Viminfo is not written when creating a new file. Solution: Set "b_marks_read" in the new buffer. (Christian Brabandt, closes #7350)
author Bram Moolenaar <Bram@vim.org>
date Mon, 23 Nov 2020 22:15:05 +0100
parents 79eac5f2dad6
children 464aed98daf3
files src/bufwrite.c src/testdir/test_viminfo.vim src/version.c
diffstat 3 files changed, 38 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/bufwrite.c
+++ b/src/bufwrite.c
@@ -2579,6 +2579,12 @@ nofail:
 #endif
     }
 
+#ifdef FEAT_VIMINFO
+    // Make sure marks will be written out to the viminfo file later, even when
+    // the file is new.
+    curbuf->b_marks_read = TRUE;
+#endif
+
     got_int |= prev_got_int;
 
     return retval;
--- a/src/testdir/test_viminfo.vim
+++ b/src/testdir/test_viminfo.vim
@@ -1,6 +1,8 @@
 " Test for reading and writing .viminfo
 
 source check.vim
+source term_util.vim
+source shared.vim
 
 function Test_viminfo_read_and_write()
   " First clear 'history', so that "hislen" is zero.  Then set it again,
@@ -879,4 +881,32 @@ func Test_viminfo_option_error()
   call assert_fails('set viminfo=%10', 'E528:')
 endfunc
 
+func Test_viminfo_oldfiles_newfile()
+  CheckRunVimInTerminal
+
+  let save_viminfo = &viminfo
+  let save_viminfofile = &viminfofile
+  set viminfo&vim
+  let v:oldfiles = []
+  let commands =<< trim [CODE]
+    set viminfofile=Xviminfofile
+    set viminfo&vim
+    w! Xnew-file.txt
+    qall
+  [CODE]
+  call writefile(commands, 'Xviminfotest')
+  let buf = RunVimInTerminal('-S Xviminfotest', #{wait_for_ruler: 0})
+  call WaitForAssert({-> assert_equal("finished", term_getstatus(buf))})
+
+  let &viminfofile = 'Xviminfofile'
+  rviminfo! Xviminfofile
+  call assert_match('Xnew-file.txt$', v:oldfiles[0])
+  call assert_equal(1, len(v:oldfiles))
+  call delete('Xviminfofile')
+  call delete('Xviminfotest')
+  call delete('Xnew-file.txt')
+  let &viminfo = save_viminfo
+  let &viminfofile = save_viminfofile
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    2039,
+/**/
     2038,
 /**/
     2037,