1
0
forked from aniani/vim

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.
This commit is contained in:
Bram Moolenaar
2016-01-18 23:29:01 +01:00
parent 61ff4dd6a4
commit b20e334859
10 changed files with 107 additions and 46 deletions

View File

@@ -25054,6 +25054,7 @@ read_viminfo_varlist(virp, writing)
char_u *tab; char_u *tab;
int type = VAR_NUMBER; int type = VAR_NUMBER;
typval_T tv; typval_T tv;
funccall_T *save_funccal;
if (!writing && (find_viminfo_parameter('!') != NULL)) 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); set_var(virp->vir_line + 1, &tv, FALSE);
current_funccal = save_funccal;
if (tv.v_type == VAR_STRING) if (tv.v_type == VAR_STRING)
vim_free(tv.vval.v_string); vim_free(tv.vval.v_string);

View File

@@ -1707,9 +1707,10 @@ append_redir(buf, buflen, opt, fname)
(char *)opt, (char *)fname); (char *)opt, (char *)fname);
} }
#ifdef FEAT_VIMINFO #if defined(FEAT_VIMINFO) || defined(PROTO)
static int no_viminfo __ARGS((void)); static int no_viminfo __ARGS((void));
static void write_viminfo_barlines(vir_T *virp, FILE *fp_out);
static int viminfo_errcnt; static int viminfo_errcnt;
static int static int
@@ -2123,6 +2124,7 @@ do_viminfo(fp_in, fp_out, flags)
#ifdef FEAT_MBYTE #ifdef FEAT_MBYTE
vir.vir_conv.vc_type = CONV_NONE; vir.vir_conv.vc_type = CONV_NONE;
#endif #endif
ga_init2(&vir.vir_barlines, (int)sizeof(char_u *), 100);
if (fp_in != NULL) if (fp_in != NULL)
{ {
@@ -2159,6 +2161,7 @@ do_viminfo(fp_in, fp_out, flags)
#endif #endif
write_viminfo_filemarks(fp_out); write_viminfo_filemarks(fp_out);
write_viminfo_bufferlist(fp_out); write_viminfo_bufferlist(fp_out);
write_viminfo_barlines(&vir, fp_out);
count = write_viminfo_marks(fp_out); count = write_viminfo_marks(fp_out);
} }
if (fp_in != NULL if (fp_in != NULL
@@ -2170,6 +2173,7 @@ do_viminfo(fp_in, fp_out, flags)
if (vir.vir_conv.vc_type != CONV_NONE) if (vir.vir_conv.vc_type != CONV_NONE)
convert_setup(&vir.vir_conv, NULL, NULL); convert_setup(&vir.vir_conv, NULL, NULL);
#endif #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 */ /* Characters reserved for future expansion, ignored now */
case '+': /* "+40 /path/dir file", for running vim without args */ case '+': /* "+40 /path/dir file", for running vim without args */
case '|': /* to be defined */
case '^': /* to be defined */ case '^': /* to be defined */
case '<': /* long line - ignored */ case '<': /* long line - ignored */
/* A comment or empty line. */ /* A comment or empty line. */
@@ -2206,6 +2209,11 @@ read_viminfo_up_to_marks(virp, forceit, writing)
case '#': case '#':
eof = viminfo_readline(virp); eof = viminfo_readline(virp);
break; 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" */ case '*': /* "*encoding=value" */
eof = viminfo_encoding(virp); eof = viminfo_encoding(virp);
break; break;
@@ -2427,6 +2435,21 @@ viminfo_writestring(fd, p)
} }
putc('\n', fd); 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 */ #endif /* FEAT_VIMINFO */
/* /*

View File

@@ -2140,6 +2140,26 @@ ga_concat_strings(gap, sep)
return s; 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. * Concatenate a string to a growarray which contains characters.
* When "s" is NULL does not do anything. * When "s" is NULL does not do anything.

View File

@@ -56,6 +56,7 @@ void ga_init __ARGS((garray_T *gap));
void ga_init2 __ARGS((garray_T *gap, int itemsize, int growsize)); void ga_init2 __ARGS((garray_T *gap, int itemsize, int growsize));
int ga_grow __ARGS((garray_T *gap, int n)); int ga_grow __ARGS((garray_T *gap, int n));
char_u *ga_concat_strings __ARGS((garray_T *gap, char *sep)); 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_concat __ARGS((garray_T *gap, char_u *s));
void ga_append __ARGS((garray_T *gap, int c)); void ga_append __ARGS((garray_T *gap, int c));
void append_ga_line __ARGS((garray_T *gap)); void append_ga_line __ARGS((garray_T *gap));

View File

@@ -1008,6 +1008,7 @@ typedef struct
#ifdef FEAT_MBYTE #ifdef FEAT_MBYTE
vimconv_T vir_conv; /* encoding conversion */ vimconv_T vir_conv; /* encoding conversion */
#endif #endif
garray_T vir_barlines; /* lines starting with | */
} vir_T; } vir_T;
#define CONV_NONE 0 #define CONV_NONE 0

View File

@@ -63,7 +63,6 @@ SCRIPTS_ALL = \
test70.out \ test70.out \
test71.out \ test71.out \
test73.out \ test73.out \
test74.out \
test75.out \ test75.out \
test76.out \ test76.out \
test77.out \ test77.out \
@@ -176,10 +175,11 @@ NEW_TESTS = test_arglist.res \
test_cdo.res \ test_cdo.res \
test_hardcopy.res \ test_hardcopy.res \
test_increment.res \ test_increment.res \
test_perl.res \
test_quickfix.res \ test_quickfix.res \
test_viminfo.res \
test_viml.res \ test_viml.res \
test_alot.res \ test_alot.res
test_perl.res
# Explicit dependencies. # Explicit dependencies.

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -741,6 +741,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1131,
/**/ /**/
1130, 1130,
/**/ /**/