]> granicus.if.org Git - vim/commitdiff
updated for version 7.3.831 v7.3.831
authorBram Moolenaar <Bram@vim.org>
Wed, 20 Feb 2013 20:12:10 +0000 (21:12 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 20 Feb 2013 20:12:10 +0000 (21:12 +0100)
Problem:    Clumsy to handle the situation that a variable does not exist.
Solution:   Add default value to getbufvar() et al. (Shougo Matsushita,
            Hirohito Higashi)

runtime/doc/eval.txt
src/eval.c
src/testdir/Make_amiga.mak
src/testdir/Make_dos.mak
src/testdir/Make_ming.mak
src/testdir/Make_os2.mak
src/testdir/Make_vms.mms
src/testdir/Makefile
src/testdir/test91.in [new file with mode: 0644]
src/testdir/test91.ok [new file with mode: 0644]
src/version.c

index 6e8fa13a7433d9b0b4ed5096487f6ff71f515d2a..fc744e26afd733f3c9508efe6eae508402214606 100644 (file)
@@ -1,4 +1,4 @@
-*eval.txt*     For Vim version 7.3.  Last change: 2013 Jan 23
+*eval.txt*     For Vim version 7.3.  Last change: 2013 Feb 20
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -1777,7 +1777,8 @@ get( {list}, {idx} [, {def}])     any     get item {idx} from {list} or {def}
 get( {dict}, {key} [, {def}])  any     get item {key} from {dict} or {def}
 getbufline( {expr}, {lnum} [, {end}])
                                List    lines {lnum} to {end} of buffer {expr}
-getbufvar( {expr}, {varname})  any     variable {varname} in buffer {expr}
+getbufvar( {expr}, {varname} [, {def}])
+                               any     variable {varname} in buffer {expr}
 getchar( [expr])               Number  get one character from the user
 getcharmod( )                  Number  modifiers for the last typed character
 getcmdline()                   String  return the current command-line
@@ -1798,12 +1799,14 @@ getpos( {expr})                 List    position of cursor, mark, etc.
 getqflist()                    List    list of quickfix items
 getreg( [{regname} [, 1]])     String  contents of register
 getregtype( [{regname}])       String  type of register
-gettabvar( {nr}, {varname})    any     variable {varname} in tab {nr}
-gettabwinvar( {tabnr}, {winnr}, {name})
+gettabvar( {nr}, {varname} [, {def}])
+                               any     variable {varname} in tab {nr} or {def}
+gettabwinvar( {tabnr}, {winnr}, {name} [, {def}])
                                any     {name} in {winnr} in tab page {tabnr}
 getwinposx()                   Number  X coord in pixels of GUI Vim window
 getwinposy()                   Number  Y coord in pixels of GUI Vim window
-getwinvar( {nr}, {varname})    any     variable {varname} in window {nr}
+getwinvar( {nr}, {varname} [, {def}])
+                               any     variable {varname} in window {nr}
 glob( {expr} [, {nosuf} [, {list}]])
                                any     expand file wildcards in {expr}
 globpath( {path}, {expr} [, {flag}])
@@ -3143,7 +3146,7 @@ getbufline({expr}, {lnum} [, {end}])
                Example: >
                        :let lines = getbufline(bufnr("myfile"), 1, "$")
 
-getbufvar({expr}, {varname})                           *getbufvar()*
+getbufvar({expr}, {varname} [, {def}])                         *getbufvar()*
                The result is the value of option or local buffer variable
                {varname} in buffer {expr}.  Note that the name without "b:"
                must be used.
@@ -3153,8 +3156,8 @@ getbufvar({expr}, {varname})                              *getbufvar()*
                doesn't work for a global variable, window-local variable or
                window-local option.
                For the use of {expr}, see |bufname()| above.
-               When the buffer or variable doesn't exist an empty string is
-               returned, there is no error message.
+               When the buffer or variable doesn't exist {def} or an empty
+               string is returned, there is no error message.
                Examples: >
                        :let bufmodified = getbufvar(1, "&mod")
                        :echo "todo myvar = " . getbufvar("todo", "myvar")
@@ -3431,26 +3434,30 @@ getregtype([{regname}])                                 *getregtype()*
                <CTRL-V> is one character with value 0x16.
                If {regname} is not specified, |v:register| is used.
 
-gettabvar({tabnr}, {varname})                          *gettabvar()*
+gettabvar({tabnr}, {varname} [, {def}])                                *gettabvar()*
                Get the value of a tab-local variable {varname} in tab page
                {tabnr}. |t:var|
                Tabs are numbered starting with one.
                Note that the name without "t:" must be used.
+               When the tab or variable doesn't exist {def} or an empty
+               string is returned, there is no error message.
 
-gettabwinvar({tabnr}, {winnr}, {varname})              *gettabwinvar()*
+gettabwinvar({tabnr}, {winnr}, {varname} [, {def}])            *gettabwinvar()*
                Get the value of window-local variable {varname} in window
                {winnr} in tab page {tabnr}.
                When {varname} starts with "&" get the value of a window-local
                option.
+               When {varname} is empty a dictionary with all window-local
+               variables is returned.
+               Note that {varname} must be the name without "w:".
                Tabs are numbered starting with one.  For the current tabpage
                use |getwinvar()|.
                When {winnr} is zero the current window is used.
                This also works for a global option, buffer-local option and
                window-local option, but it doesn't work for a global variable
                or buffer-local variable.
-               When {varname} is empty a dictionary with all window-local
-               variables is returned.
-               Note that {varname} must be the name without "w:".
+               When the tab, window or variable doesn't exist {def} or an
+               empty string is returned, there is no error message.
                Examples: >
                        :let list_is_on = gettabwinvar(1, 2, '&list')
                        :echo "myvar = " . gettabwinvar(3, 1, 'myvar')
@@ -3465,7 +3472,7 @@ getwinposy()      The result is a Number, which is the Y coordinate in pixels of
                the top of the GUI Vim window.  The result will be -1 if the
                information is not available.
 
-getwinvar({winnr}, {varname})                          *getwinvar()*
+getwinvar({winnr}, {varname} [, {def}])                                *getwinvar()*
                Like |gettabwinvar()| for the current tabpage.
                Examples: >
                        :let list_is_on = getwinvar(2, '&list')
index e1f29c40f5e242da8e85d8fbb02c18e713addd59..480f214b4a54c91550d921e38b434bfe796ed0e3 100644 (file)
@@ -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)
     {
index 19d891074f031a4f234fc97604c3a84dd5f488a0..0e18992def9af8cd6c6a8f36d567d8e74e1527bb 100644 (file)
@@ -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
index 99963e8b3cf73f3f85f9347655837a6c9b4dbed4..968cf6ca1d3c7d4bace428b317b1d6aa7cbdab45 100644 (file)
@@ -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
 
index 32d1db5f7b458ff325ddb4b174bd73907a513fd8..9d845ab94a050fe005dbaaee474c988765107243 100644 (file)
@@ -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
 
index 2f46a415a823b69c720318a8b2a8c94f05078cf7..bddfd5ec9502ac8e6c854c5929d33cbd33f7e702 100644 (file)
@@ -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
 
index a0d29d768237ebc5f3c93fee1541460ea984ccc1..f19dd5a3497e650b59f8ee9f4599d1312c2bd52d 100644 (file)
@@ -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
index 1920834005bfaaf05f32cbb8d8ba64e4c542150e..8b31b91eb3c74b8103f33284c964b23a90f3d790 100644 (file)
@@ -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
 
diff --git a/src/testdir/test91.in b/src/testdir/test91.in
new file mode 100644 (file)
index 0000000..1c8189d
--- /dev/null
@@ -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:
diff --git a/src/testdir/test91.ok b/src/testdir/test91.ok
new file mode 100644 (file)
index 0000000..8777af8
--- /dev/null
@@ -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
index 0881d927cf939b1b76df7848fd93edc46b6ebda5..6675d009a5fa955812a430026af1e6c0ec6cecd7 100644 (file)
@@ -728,6 +728,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    831,
 /**/
     830,
 /**/