Skip to content

Commit b20e334

Browse files
committed
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.
1 parent 61ff4dd commit b20e334

File tree

10 files changed

+107
-46
lines changed

10 files changed

+107
-46
lines changed

src/eval.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25054,6 +25054,7 @@ read_viminfo_varlist(virp, writing)
2505425054
char_u *tab;
2505525055
int type = VAR_NUMBER;
2505625056
typval_T tv;
25057+
funccall_T *save_funccal;
2505725058

2505825059
if (!writing && (find_viminfo_parameter('!') != NULL))
2505925060
{
@@ -25100,7 +25101,11 @@ read_viminfo_varlist(virp, writing)
2510025101
}
2510125102
}
2510225103

25104+
/* when in a function use global variables */
25105+
save_funccal = current_funccal;
25106+
current_funccal = NULL;
2510325107
set_var(virp->vir_line + 1, &tv, FALSE);
25108+
current_funccal = save_funccal;
2510425109

2510525110
if (tv.v_type == VAR_STRING)
2510625111
vim_free(tv.vval.v_string);

src/ex_cmds.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,9 +1707,10 @@ append_redir(buf, buflen, opt, fname)
17071707
(char *)opt, (char *)fname);
17081708
}
17091709

1710-
#ifdef FEAT_VIMINFO
1710+
#if defined(FEAT_VIMINFO) || defined(PROTO)
17111711

17121712
static int no_viminfo __ARGS((void));
1713+
static void write_viminfo_barlines(vir_T *virp, FILE *fp_out);
17131714
static int viminfo_errcnt;
17141715

17151716
static int
@@ -2123,6 +2124,7 @@ do_viminfo(fp_in, fp_out, flags)
21232124
#ifdef FEAT_MBYTE
21242125
vir.vir_conv.vc_type = CONV_NONE;
21252126
#endif
2127+
ga_init2(&vir.vir_barlines, (int)sizeof(char_u *), 100);
21262128

21272129
if (fp_in != NULL)
21282130
{
@@ -2159,6 +2161,7 @@ do_viminfo(fp_in, fp_out, flags)
21592161
#endif
21602162
write_viminfo_filemarks(fp_out);
21612163
write_viminfo_bufferlist(fp_out);
2164+
write_viminfo_barlines(&vir, fp_out);
21622165
count = write_viminfo_marks(fp_out);
21632166
}
21642167
if (fp_in != NULL
@@ -2170,6 +2173,7 @@ do_viminfo(fp_in, fp_out, flags)
21702173
if (vir.vir_conv.vc_type != CONV_NONE)
21712174
convert_setup(&vir.vir_conv, NULL, NULL);
21722175
#endif
2176+
ga_clear_strings(&vir.vir_barlines);
21732177
}
21742178

21752179
/*
@@ -2196,7 +2200,6 @@ read_viminfo_up_to_marks(virp, forceit, writing)
21962200
{
21972201
/* Characters reserved for future expansion, ignored now */
21982202
case '+': /* "+40 /path/dir file", for running vim without args */
2199-
case '|': /* to be defined */
22002203
case '^': /* to be defined */
22012204
case '<': /* long line - ignored */
22022205
/* A comment or empty line. */
@@ -2206,6 +2209,11 @@ read_viminfo_up_to_marks(virp, forceit, writing)
22062209
case '#':
22072210
eof = viminfo_readline(virp);
22082211
break;
2212+
case '|': /* copy line (for future use) */
2213+
if (writing)
2214+
ga_add_string(&virp->vir_barlines, virp->vir_line);
2215+
eof = viminfo_readline(virp);
2216+
break;
22092217
case '*': /* "*encoding=value" */
22102218
eof = viminfo_encoding(virp);
22112219
break;
@@ -2427,6 +2435,21 @@ viminfo_writestring(fd, p)
24272435
}
24282436
putc('\n', fd);
24292437
}
2438+
2439+
static void
2440+
write_viminfo_barlines(vir_T *virp, FILE *fp_out)
2441+
{
2442+
int i;
2443+
garray_T *gap = &virp->vir_barlines;
2444+
2445+
if (gap->ga_len > 0)
2446+
{
2447+
fputs(_("\n# Bar lines, copied verbatim:\n"), fp_out);
2448+
2449+
for (i = 0; i < gap->ga_len; ++i)
2450+
fputs(((char **)(gap->ga_data))[i], fp_out);
2451+
}
2452+
}
24302453
#endif /* FEAT_VIMINFO */
24312454

24322455
/*

src/misc2.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2140,6 +2140,26 @@ ga_concat_strings(gap, sep)
21402140
return s;
21412141
}
21422142

2143+
#if defined(FEAT_VIMINFO) || defined(PROTO)
2144+
/*
2145+
* Make a copy of string "p" and add it to "gap".
2146+
* When out of memory nothing changes.
2147+
*/
2148+
void
2149+
ga_add_string(garray_T *gap, char_u *p)
2150+
{
2151+
char_u *cp = vim_strsave(p);
2152+
2153+
if (cp != NULL)
2154+
{
2155+
if (ga_grow(gap, 1) == OK)
2156+
((char_u **)(gap->ga_data))[gap->ga_len++] = cp;
2157+
else
2158+
vim_free(cp);
2159+
}
2160+
}
2161+
#endif
2162+
21432163
/*
21442164
* Concatenate a string to a growarray which contains characters.
21452165
* When "s" is NULL does not do anything.

src/proto/misc2.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ void ga_init __ARGS((garray_T *gap));
5656
void ga_init2 __ARGS((garray_T *gap, int itemsize, int growsize));
5757
int ga_grow __ARGS((garray_T *gap, int n));
5858
char_u *ga_concat_strings __ARGS((garray_T *gap, char *sep));
59+
void ga_add_string __ARGS((garray_T *gap, char_u *p));
5960
void ga_concat __ARGS((garray_T *gap, char_u *s));
6061
void ga_append __ARGS((garray_T *gap, int c));
6162
void append_ga_line __ARGS((garray_T *gap));

src/structs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,7 @@ typedef struct
10081008
#ifdef FEAT_MBYTE
10091009
vimconv_T vir_conv; /* encoding conversion */
10101010
#endif
1011+
garray_T vir_barlines; /* lines starting with | */
10111012
} vir_T;
10121013

10131014
#define CONV_NONE 0

src/testdir/Make_all.mak

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ SCRIPTS_ALL = \
6363
test70.out \
6464
test71.out \
6565
test73.out \
66-
test74.out \
6766
test75.out \
6867
test76.out \
6968
test77.out \
@@ -176,10 +175,11 @@ NEW_TESTS = test_arglist.res \
176175
test_cdo.res \
177176
test_hardcopy.res \
178177
test_increment.res \
178+
test_perl.res \
179179
test_quickfix.res \
180+
test_viminfo.res \
180181
test_viml.res \
181-
test_alot.res \
182-
test_perl.res
182+
test_alot.res
183183

184184

185185
# Explicit dependencies.

src/testdir/test74.in

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/testdir/test74.ok

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/testdir/test_viminfo.vim

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
" Test for reading and writing .viminfo
2+
3+
function Test_read_and_write()
4+
let lines = [
5+
\ '# comment line',
6+
\ '*encoding=utf-8',
7+
\ '~MSle0~/asdf',
8+
\ '|copied as-is',
9+
\ '|and one more',
10+
\ ]
11+
call writefile(lines, 'Xviminfo')
12+
rviminfo Xviminfo
13+
call assert_equal('asdf', @/)
14+
15+
wviminfo Xviminfo
16+
let lines = readfile('Xviminfo')
17+
let done = 0
18+
for line in lines
19+
if line[0] == '|'
20+
if done == 0
21+
call assert_equal('|copied as-is', line)
22+
elseif done == 1
23+
call assert_equal('|and one more', line)
24+
endif
25+
let done += 1
26+
endif
27+
endfor
28+
call assert_equal(2, done)
29+
30+
call delete('Xviminfo')
31+
endfunc
32+
33+
func Test_global_vars()
34+
let test_dict = {'foo': 1, 'bar': 0, 'longvarible': 1000}
35+
let g:MY_GLOBAL_DICT = test_dict
36+
" store a really long list, so line wrapping will occur in viminfo file
37+
let test_list = range(1,100)
38+
let g:MY_GLOBAL_LIST = test_list
39+
set viminfo='100,<50,s10,h,!
40+
wv! Xviminfo
41+
unlet g:MY_GLOBAL_DICT
42+
unlet g:MY_GLOBAL_LIST
43+
44+
rv! Xviminfo
45+
call assert_equal(test_dict, g:MY_GLOBAL_DICT)
46+
call assert_equal(test_list, g:MY_GLOBAL_LIST)
47+
48+
call delete('Xviminfo')
49+
set viminfo-=!
50+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,8 @@ static char *(features[]) =
741741

742742
static int included_patches[] =
743743
{ /* Add new patch number below this line */
744+
/**/
745+
1131,
744746
/**/
745747
1130,
746748
/**/

0 commit comments

Comments
 (0)