# HG changeset patch # User Christian Brabandt # Date 1453156205 -3600 # Node ID 1fded31d9e04bd0bc3e25bf801ea7aac3c5023fb # Parent c4b2ec5485e590dd805937a5d6b0da5f22008eb8 commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9 Author: Bram Moolenaar Date: Mon Jan 18 23:29:01 2016 +0100 patch 7.4.1131 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. diff --git a/src/eval.c b/src/eval.c --- a/src/eval.c +++ b/src/eval.c @@ -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); diff --git a/src/ex_cmds.c b/src/ex_cmds.c --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -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, { /* 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, 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 */ /* diff --git a/src/misc2.c b/src/misc2.c --- a/src/misc2.c +++ b/src/misc2.c @@ -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. diff --git a/src/proto/misc2.pro b/src/proto/misc2.pro --- a/src/proto/misc2.pro +++ b/src/proto/misc2.pro @@ -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)); diff --git a/src/structs.h b/src/structs.h --- a/src/structs.h +++ b/src/structs.h @@ -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 diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak --- a/src/testdir/Make_all.mak +++ b/src/testdir/Make_all.mak @@ -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 --- a/src/testdir/test74.in +++ /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 --- a/src/testdir/test74.ok +++ /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 --- /dev/null +++ b/src/testdir/test_viminfo.vim @@ -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 diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -742,6 +742,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1131, +/**/ 1130, /**/ 1129,