forked from aniani/vim
updated for version 7.3.831
Problem: Clumsy to handle the situation that a variable does not exist. Solution: Add default value to getbufvar() et al. (Shougo Matsushita, Hirohito Higashi)
This commit is contained in:
32
src/eval.c
32
src/eval.c
@@ -7916,7 +7916,7 @@ static struct fst
|
||||
{"garbagecollect", 0, 1, f_garbagecollect},
|
||||
{"get", 2, 3, f_get},
|
||||
{"getbufline", 2, 3, f_getbufline},
|
||||
{"getbufvar", 2, 2, f_getbufvar},
|
||||
{"getbufvar", 2, 3, f_getbufvar},
|
||||
{"getchar", 0, 1, f_getchar},
|
||||
{"getcharmod", 0, 0, f_getcharmod},
|
||||
{"getcmdline", 0, 0, f_getcmdline},
|
||||
@@ -7936,11 +7936,11 @@ static struct fst
|
||||
{"getqflist", 0, 0, f_getqflist},
|
||||
{"getreg", 0, 2, f_getreg},
|
||||
{"getregtype", 0, 1, f_getregtype},
|
||||
{"gettabvar", 2, 2, f_gettabvar},
|
||||
{"gettabwinvar", 3, 3, f_gettabwinvar},
|
||||
{"gettabvar", 2, 3, f_gettabvar},
|
||||
{"gettabwinvar", 3, 4, f_gettabwinvar},
|
||||
{"getwinposx", 0, 0, f_getwinposx},
|
||||
{"getwinposy", 0, 0, f_getwinposy},
|
||||
{"getwinvar", 2, 2, f_getwinvar},
|
||||
{"getwinvar", 2, 3, f_getwinvar},
|
||||
{"glob", 1, 3, f_glob},
|
||||
{"globpath", 2, 3, f_globpath},
|
||||
{"has", 1, 1, f_has},
|
||||
@@ -11115,8 +11115,14 @@ f_getbufvar(argvars, rettv)
|
||||
++emsg_off;
|
||||
buf = get_buf_tv(&argvars[0]);
|
||||
|
||||
rettv->v_type = VAR_STRING;
|
||||
rettv->vval.v_string = NULL;
|
||||
if (argvars[2].v_type != VAR_UNKNOWN)
|
||||
/* set the default value */
|
||||
copy_tv(&argvars[2], rettv);
|
||||
else
|
||||
{
|
||||
rettv->v_type = VAR_STRING;
|
||||
rettv->vval.v_string = NULL;
|
||||
}
|
||||
|
||||
if (buf != NULL && varname != NULL)
|
||||
{
|
||||
@@ -11785,7 +11791,11 @@ f_gettabvar(argvars, rettv)
|
||||
v = find_var_in_ht(&tp->tp_vars.dv_hashtab, varname, FALSE);
|
||||
if (v != NULL)
|
||||
copy_tv(&v->di_tv, rettv);
|
||||
else if (argvars[2].v_type != VAR_UNKNOWN)
|
||||
copy_tv(&argvars[2], rettv);
|
||||
}
|
||||
else if (argvars[2].v_type != VAR_UNKNOWN)
|
||||
copy_tv(&argvars[2], rettv);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -11907,8 +11917,14 @@ getwinvar(argvars, rettv, off)
|
||||
varname = get_tv_string_chk(&argvars[off + 1]);
|
||||
++emsg_off;
|
||||
|
||||
rettv->v_type = VAR_STRING;
|
||||
rettv->vval.v_string = NULL;
|
||||
if (argvars[off + 2].v_type != VAR_UNKNOWN)
|
||||
/* set the default return value */
|
||||
copy_tv(&argvars[off + 2], rettv);
|
||||
else
|
||||
{
|
||||
rettv->v_type = VAR_STRING;
|
||||
rettv->vval.v_string = NULL;
|
||||
}
|
||||
|
||||
if (win != NULL && varname != NULL)
|
||||
{
|
||||
|
@@ -32,7 +32,7 @@ SCRIPTS = test1.out test3.out test4.out test5.out test6.out \
|
||||
test71.out test72.out test73.out test74.out test75.out \
|
||||
test76.out test77.out test78.out test79.out test80.out \
|
||||
test81.out test82.out test83.out test84.out test88.out \
|
||||
test89.out test90.out
|
||||
test89.out test90.out test91.out
|
||||
|
||||
.SUFFIXES: .in .out
|
||||
|
||||
@@ -139,3 +139,4 @@ test84.out: test84.in
|
||||
test88.out: test88.in
|
||||
test89.out: test89.in
|
||||
test90.out: test90.in
|
||||
test91.out: test91.in
|
||||
|
@@ -31,7 +31,7 @@ SCRIPTS = test3.out test4.out test5.out test6.out test7.out \
|
||||
test74.out test75.out test76.out test77.out test78.out \
|
||||
test79.out test80.out test81.out test82.out test83.out \
|
||||
test84.out test85.out test86.out test87.out test88.out \
|
||||
test89.out test90.out
|
||||
test89.out test90.out test91.out
|
||||
|
||||
SCRIPTS32 = test50.out test70.out
|
||||
|
||||
|
@@ -51,7 +51,7 @@ SCRIPTS = test3.out test4.out test5.out test6.out test7.out \
|
||||
test74.out test75.out test76.out test77.out test78.out \
|
||||
test79.out test80.out test81.out test82.out test83.out \
|
||||
test84.out test85.out test86.out test87.out test88.out \
|
||||
test89.out test90.out
|
||||
test89.out test90.out test91.out
|
||||
|
||||
SCRIPTS32 = test50.out test70.out
|
||||
|
||||
|
@@ -32,7 +32,7 @@ SCRIPTS = test1.out test3.out test4.out test5.out test6.out \
|
||||
test71.out test72.out test73.out test74.out test75.out \
|
||||
test76.out test77.out test78.out test79.out test80.out \
|
||||
test81.out test82.out test83.out test84.out test88.out \
|
||||
test89.out test90.out
|
||||
test89.out test90.out test91.out
|
||||
|
||||
.SUFFIXES: .in .out
|
||||
|
||||
|
@@ -4,7 +4,7 @@
|
||||
# Authors: Zoltan Arpadffy, <arpadffy@polarhome.com>
|
||||
# Sandor Kopanyi, <sandor.kopanyi@mailbox.hu>
|
||||
#
|
||||
# Last change: 2013 Feb 13
|
||||
# Last change: 2013 Feb 20
|
||||
#
|
||||
# This has been tested on VMS 6.2 to 8.3 on DEC Alpha, VAX and IA64.
|
||||
# Edit the lines in the Configuration section below to select.
|
||||
@@ -77,7 +77,7 @@ SCRIPT = test1.out test2.out test3.out test4.out test5.out \
|
||||
test71.out test72.out test74.out test75.out test76.out \
|
||||
test77.out test78.out test79.out test80.out test81.out \
|
||||
test82.out test83.out test84.out test88.out test89.out \
|
||||
test90.out
|
||||
test90.out test91.out
|
||||
|
||||
# Known problems:
|
||||
# Test 30: a problem around mac format - unknown reason
|
||||
|
@@ -28,7 +28,7 @@ SCRIPTS = test1.out test2.out test3.out test4.out test5.out test6.out \
|
||||
test74.out test75.out test76.out test77.out test78.out \
|
||||
test79.out test80.out test81.out test82.out test83.out \
|
||||
test84.out test85.out test86.out test87.out test88.out \
|
||||
test89.out test90.out
|
||||
test89.out test90.out test91.out
|
||||
|
||||
SCRIPTS_GUI = test16.out
|
||||
|
||||
|
98
src/testdir/test91.in
Normal file
98
src/testdir/test91.in
Normal file
@@ -0,0 +1,98 @@
|
||||
Tests for getbufvar(), getwinvar(), gettabvar() and gettabwinvar().
|
||||
vim: set ft=vim :
|
||||
|
||||
STARTTEST
|
||||
:so small.vim
|
||||
:"
|
||||
:" test for getbufvar()
|
||||
:let b:var_num = 1234
|
||||
:let def_num = 5678
|
||||
:$put =string(getbufvar(1, 'var_num'))
|
||||
:$put =string(getbufvar(1, 'var_num', def_num))
|
||||
:$put =string(getbufvar(1, ''))
|
||||
:$put =string(getbufvar(1, '', def_num))
|
||||
:unlet b:var_num
|
||||
:$put =string(getbufvar(1, 'var_num', def_num))
|
||||
:$put =string(getbufvar(1, ''))
|
||||
:$put =string(getbufvar(1, '', def_num))
|
||||
:$put =string(getbufvar(9, ''))
|
||||
:$put =string(getbufvar(9, '', def_num))
|
||||
:unlet def_num
|
||||
:$put =string(getbufvar(1, '&autoindent'))
|
||||
:$put =string(getbufvar(1, '&autoindent', 1))
|
||||
:"
|
||||
:" test for getwinvar()
|
||||
:let w:var_str = "Dance"
|
||||
:let def_str = "Chance"
|
||||
:$put =string(getwinvar(1, 'var_str'))
|
||||
:$put =string(getwinvar(1, 'var_str', def_str))
|
||||
:$put =string(getwinvar(1, ''))
|
||||
:$put =string(getwinvar(1, '', def_str))
|
||||
:unlet w:var_str
|
||||
:$put =string(getwinvar(1, 'var_str', def_str))
|
||||
:$put =string(getwinvar(1, ''))
|
||||
:$put =string(getwinvar(1, '', def_str))
|
||||
:$put =string(getwinvar(9, ''))
|
||||
:$put =string(getwinvar(9, '', def_str))
|
||||
:$put =string(getwinvar(1, '&nu'))
|
||||
:$put =string(getwinvar(1, '&nu', 1))
|
||||
:unlet def_str
|
||||
:"
|
||||
:" test for gettabvar()
|
||||
:tabnew
|
||||
:tabnew
|
||||
:let t:var_list = [1, 2, 3]
|
||||
:let def_list = [4, 5, 6, 7]
|
||||
:tabrewind
|
||||
:$put =string(gettabvar(3, 'var_list'))
|
||||
:$put =string(gettabvar(3, 'var_list', def_list))
|
||||
:$put =string(gettabvar(3, ''))
|
||||
:$put =string(gettabvar(3, '', def_list))
|
||||
:tablast
|
||||
:unlet t:var_list
|
||||
:tabrewind
|
||||
:$put =string(gettabvar(3, 'var_list', def_list))
|
||||
:$put =string(gettabvar(9, ''))
|
||||
:$put =string(gettabvar(9, '', def_list))
|
||||
:$put =string(gettabvar(3, '&nu'))
|
||||
:$put =string(gettabvar(3, '&nu', def_list))
|
||||
:unlet def_list
|
||||
:tabonly
|
||||
:"
|
||||
:" test for gettabwinvar()
|
||||
:tabnew
|
||||
:tabnew
|
||||
:tabprev
|
||||
:split
|
||||
:split
|
||||
:wincmd w
|
||||
:vert split
|
||||
:wincmd w
|
||||
:let w:var_dict = {'dict': 'tabwin'}
|
||||
:let def_dict = {'dict2': 'newval'}
|
||||
:wincmd b
|
||||
:tabrewind
|
||||
:$put =string(gettabwinvar(2, 3, 'var_dict'))
|
||||
:$put =string(gettabwinvar(2, 3, 'var_dict', def_dict))
|
||||
:$put =string(gettabwinvar(2, 3, ''))
|
||||
:$put =string(gettabwinvar(2, 3, '', def_dict))
|
||||
:tabnext
|
||||
:3wincmd w
|
||||
:unlet w:var_dict
|
||||
:tabrewind
|
||||
:$put =string(gettabwinvar(2, 3, 'var_dict', def_dict))
|
||||
:$put =string(gettabwinvar(2, 3, ''))
|
||||
:$put =string(gettabwinvar(2, 3, '', def_dict))
|
||||
:$put =string(gettabwinvar(2, 9, ''))
|
||||
:$put =string(gettabwinvar(2, 9, '', def_dict))
|
||||
:$put =string(gettabwinvar(9, 3, ''))
|
||||
:$put =string(gettabwinvar(9, 3, '', def_dict))
|
||||
:unlet def_dict
|
||||
:$put =string(gettabwinvar(2, 3, '&nux'))
|
||||
:$put =string(gettabwinvar(2, 3, '&nux', 1))
|
||||
:tabonly
|
||||
:"
|
||||
:/^start/,$wq! test.out
|
||||
ENDTEST
|
||||
|
||||
start:
|
45
src/testdir/test91.ok
Normal file
45
src/testdir/test91.ok
Normal file
@@ -0,0 +1,45 @@
|
||||
start:
|
||||
1234
|
||||
1234
|
||||
{'var_num': 1234}
|
||||
{'var_num': 1234}
|
||||
5678
|
||||
{}
|
||||
{}
|
||||
''
|
||||
5678
|
||||
0
|
||||
0
|
||||
'Dance'
|
||||
'Dance'
|
||||
{'var_str': 'Dance'}
|
||||
{'var_str': 'Dance'}
|
||||
'Chance'
|
||||
{}
|
||||
{}
|
||||
''
|
||||
'Chance'
|
||||
0
|
||||
0
|
||||
[1, 2, 3]
|
||||
[1, 2, 3]
|
||||
''
|
||||
[4, 5, 6, 7]
|
||||
[4, 5, 6, 7]
|
||||
''
|
||||
[4, 5, 6, 7]
|
||||
''
|
||||
[4, 5, 6, 7]
|
||||
{'dict': 'tabwin'}
|
||||
{'dict': 'tabwin'}
|
||||
{'var_dict': {'dict': 'tabwin'}}
|
||||
{'var_dict': {'dict': 'tabwin'}}
|
||||
{'dict2': 'newval'}
|
||||
{}
|
||||
{}
|
||||
''
|
||||
{'dict2': 'newval'}
|
||||
''
|
||||
{'dict2': 'newval'}
|
||||
''
|
||||
1
|
@@ -728,6 +728,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
831,
|
||||
/**/
|
||||
830,
|
||||
/**/
|
||||
|
Reference in New Issue
Block a user