]> granicus.if.org Git - vim/commitdiff
patch 7.4.1131 v7.4.1131
authorBram Moolenaar <Bram@vim.org>
Mon, 18 Jan 2016 22:29:01 +0000 (23:29 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 18 Jan 2016 22:29:01 +0000 (23:29 +0100)
Problem:    New lines in the viminfo file are dropped.
Solution:   Copy lines starting with "|".  Fix that when using :rviminfo in a
            function global variables were restored as function-local
            variables.

src/eval.c
src/ex_cmds.c
src/misc2.c
src/proto/misc2.pro
src/structs.h
src/testdir/Make_all.mak
src/testdir/test74.in [deleted file]
src/testdir/test74.ok [deleted file]
src/testdir/test_viminfo.vim [new file with mode: 0644]
src/version.c

index 5d0885401f085a7d5ba118bab34c0205a53e1a7f..0d83f1d5cf8342dbcded621963a24751a7099dfe 100644 (file)
@@ -25054,6 +25054,7 @@ read_viminfo_varlist(virp, writing)
     char_u     *tab;
     int                type = VAR_NUMBER;
     typval_T   tv;
+    funccall_T  *save_funccal;
 
     if (!writing && (find_viminfo_parameter('!') != NULL))
     {
@@ -25100,7 +25101,11 @@ read_viminfo_varlist(virp, writing)
                    }
                }
 
+               /* when in a function use global variables */
+               save_funccal = current_funccal;
+               current_funccal = NULL;
                set_var(virp->vir_line + 1, &tv, FALSE);
+               current_funccal = save_funccal;
 
                if (tv.v_type == VAR_STRING)
                    vim_free(tv.vval.v_string);
index 1d0a3856c58737f81844d3df3b5e3121459850d5..bb6daa8ca08aa6e83b5628d3db22edfc86545315 100644 (file)
@@ -1707,9 +1707,10 @@ append_redir(buf, buflen, opt, fname)
                (char *)opt, (char *)fname);
 }
 
-#ifdef FEAT_VIMINFO
+#if defined(FEAT_VIMINFO) || defined(PROTO)
 
 static int no_viminfo __ARGS((void));
+static void write_viminfo_barlines(vir_T *virp, FILE *fp_out);
 static int  viminfo_errcnt;
 
     static int
@@ -2123,6 +2124,7 @@ do_viminfo(fp_in, fp_out, flags)
 #ifdef FEAT_MBYTE
     vir.vir_conv.vc_type = CONV_NONE;
 #endif
+    ga_init2(&vir.vir_barlines, (int)sizeof(char_u *), 100);
 
     if (fp_in != NULL)
     {
@@ -2159,6 +2161,7 @@ do_viminfo(fp_in, fp_out, flags)
 #endif
        write_viminfo_filemarks(fp_out);
        write_viminfo_bufferlist(fp_out);
+       write_viminfo_barlines(&vir, fp_out);
        count = write_viminfo_marks(fp_out);
     }
     if (fp_in != NULL
@@ -2170,6 +2173,7 @@ do_viminfo(fp_in, fp_out, flags)
     if (vir.vir_conv.vc_type != CONV_NONE)
        convert_setup(&vir.vir_conv, NULL, NULL);
 #endif
+    ga_clear_strings(&vir.vir_barlines);
 }
 
 /*
@@ -2196,7 +2200,6 @@ read_viminfo_up_to_marks(virp, forceit, writing)
        {
                /* Characters reserved for future expansion, ignored now */
            case '+': /* "+40 /path/dir file", for running vim without args */
-           case '|': /* to be defined */
            case '^': /* to be defined */
            case '<': /* long line - ignored */
                /* A comment or empty line. */
@@ -2206,6 +2209,11 @@ read_viminfo_up_to_marks(virp, forceit, writing)
            case '#':
                eof = viminfo_readline(virp);
                break;
+           case '|': /* copy line (for future use) */
+               if (writing)
+                   ga_add_string(&virp->vir_barlines, virp->vir_line);
+               eof = viminfo_readline(virp);
+               break;
            case '*': /* "*encoding=value" */
                eof = viminfo_encoding(virp);
                break;
@@ -2427,6 +2435,21 @@ viminfo_writestring(fd, p)
     }
     putc('\n', fd);
 }
+
+    static void
+write_viminfo_barlines(vir_T *virp, FILE *fp_out)
+{
+    int                i;
+    garray_T   *gap = &virp->vir_barlines;
+
+    if (gap->ga_len > 0)
+    {
+       fputs(_("\n# Bar lines, copied verbatim:\n"), fp_out);
+
+       for (i = 0; i < gap->ga_len; ++i)
+           fputs(((char **)(gap->ga_data))[i], fp_out);
+    }
+}
 #endif /* FEAT_VIMINFO */
 
 /*
index 4e9e47357e1de6971c16cdfc5991249ca703a2d5..014c66a9b78dd3fbd75bf633d1dde9fcd733d144 100644 (file)
@@ -2140,6 +2140,26 @@ ga_concat_strings(gap, sep)
     return s;
 }
 
+#if defined(FEAT_VIMINFO) || defined(PROTO)
+/*
+ * Make a copy of string "p" and add it to "gap".
+ * When out of memory nothing changes.
+ */
+    void
+ga_add_string(garray_T *gap, char_u *p)
+{
+    char_u *cp = vim_strsave(p);
+
+    if (cp != NULL)
+    {
+       if (ga_grow(gap, 1) == OK)
+           ((char_u **)(gap->ga_data))[gap->ga_len++] = cp;
+       else
+           vim_free(cp);
+    }
+}
+#endif
+
 /*
  * Concatenate a string to a growarray which contains characters.
  * When "s" is NULL does not do anything.
index 3d1f10ad55490e40c6042acfd3687e0bcb0d21b3..8baf43a3fc5a25abd418df7212851d9b3c2b9ce7 100644 (file)
@@ -56,6 +56,7 @@ void ga_init __ARGS((garray_T *gap));
 void ga_init2 __ARGS((garray_T *gap, int itemsize, int growsize));
 int ga_grow __ARGS((garray_T *gap, int n));
 char_u *ga_concat_strings __ARGS((garray_T *gap, char *sep));
+void ga_add_string __ARGS((garray_T *gap, char_u *p));
 void ga_concat __ARGS((garray_T *gap, char_u *s));
 void ga_append __ARGS((garray_T *gap, int c));
 void append_ga_line __ARGS((garray_T *gap));
index 0c06401db517e11a78c4a8cb9c3207e3eaf2966c..5c65cc65a4162e746bc72d7f95409a2183ac0373 100644 (file)
@@ -1008,6 +1008,7 @@ typedef struct
 #ifdef FEAT_MBYTE
     vimconv_T  vir_conv;       /* encoding conversion */
 #endif
+    garray_T   vir_barlines;   /* lines starting with | */
 } vir_T;
 
 #define CONV_NONE              0
index 33d76ba49edc62ed6b24957821d8ebc375a23ba3..a5b8cd365bc94dae250b7b303e1bf1372e4250d9 100644 (file)
@@ -63,7 +63,6 @@ SCRIPTS_ALL = \
        test70.out \
        test71.out \
        test73.out \
-       test74.out \
        test75.out \
        test76.out \
        test77.out \
@@ -176,10 +175,11 @@ NEW_TESTS = test_arglist.res \
            test_cdo.res \
            test_hardcopy.res \
            test_increment.res \
+           test_perl.res \
            test_quickfix.res \
+           test_viminfo.res \
            test_viml.res \
-           test_alot.res \
-           test_perl.res
+           test_alot.res
 
 
 # Explicit dependencies.
diff --git a/src/testdir/test74.in b/src/testdir/test74.in
deleted file mode 100644 (file)
index 4fbe5e4..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-" Tests for storing global variables in the .viminfo file vim: set ft=vim:
-
-STARTTEST
-:so small.vim
-:" Do all test in a separate window to avoid E211 when we recursively
-:" delete the Xfind directory during cleanup
-:"
-:" This will cause a few errors, do it silently.
-:set visualbell
-:set nocp viminfo+=!,nviminfo
-:let MY_GLOBAL_DICT={'foo': 1, 'bar': 0, 'longvarible': 1000}
-:" store a really long list, so line wrapping will occur in viminfo file
-:let MY_GLOBAL_LIST=range(1,100)
-:wv! Xviminfo
-:unlet MY_GLOBAL_DICT
-:unlet MY_GLOBAL_LIST
-:rv! Xviminfo
-:call delete('Xviminfo')
-:if exists("MY_GLOBAL_DICT")
-:redir >> test.out
-:echo MY_GLOBAL_DICT
-:redir end
-:endif
-:if exists("MY_GLOBAL_LIST")
-:redir >> test.out
-:echo MY_GLOBAL_LIST
-:redir end
-:endif
-:redir >> test.out
-:echo "foobar"
-:redir end
-:endif
-:qa!
-ENDTEST
-
-eof
diff --git a/src/testdir/test74.ok b/src/testdir/test74.ok
deleted file mode 100644 (file)
index b026c33..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-
-{'foo': 1, 'longvarible': 1000, 'bar': 0}
-[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
-
-foobar
diff --git a/src/testdir/test_viminfo.vim b/src/testdir/test_viminfo.vim
new file mode 100644 (file)
index 0000000..3efe75e
--- /dev/null
@@ -0,0 +1,50 @@
+" Test for reading and writing .viminfo
+
+function Test_read_and_write()
+  let lines = [
+       \ '# comment line',
+       \ '*encoding=utf-8',
+       \ '~MSle0~/asdf',
+       \ '|copied as-is',
+       \ '|and one more',
+       \ ]
+  call writefile(lines, 'Xviminfo')
+  rviminfo Xviminfo
+  call assert_equal('asdf', @/)
+
+  wviminfo Xviminfo
+  let lines = readfile('Xviminfo')
+  let done = 0
+  for line in lines
+    if line[0] == '|'
+      if done == 0
+       call assert_equal('|copied as-is', line)
+      elseif done == 1
+       call assert_equal('|and one more', line)
+      endif
+      let done += 1
+    endif
+  endfor
+  call assert_equal(2, done)
+
+  call delete('Xviminfo')
+endfunc
+
+func Test_global_vars()
+  let test_dict = {'foo': 1, 'bar': 0, 'longvarible': 1000}
+  let g:MY_GLOBAL_DICT = test_dict
+  " store a really long list, so line wrapping will occur in viminfo file
+  let test_list = range(1,100)
+  let g:MY_GLOBAL_LIST = test_list
+  set viminfo='100,<50,s10,h,!
+  wv! Xviminfo
+  unlet g:MY_GLOBAL_DICT
+  unlet g:MY_GLOBAL_LIST
+
+  rv! Xviminfo
+  call assert_equal(test_dict, g:MY_GLOBAL_DICT)
+  call assert_equal(test_list, g:MY_GLOBAL_LIST)
+
+  call delete('Xviminfo')
+  set viminfo-=!
+endfunc
index 444d4b81711d743eedc33ba5a802c35a7cd9eecf..0b595183fb73ed20b7f4ffd03cca409e3333e67e 100644 (file)
@@ -741,6 +741,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1131,
 /**/
     1130,
 /**/