To: vim_dev@googlegroups.com Subject: Patch 7.3.831 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 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) Files: runtime/doc/eval.txt, src/eval.c src/testdir/test91.in, src/testdir/test91.ok, 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 *** ../vim-7.3.830/runtime/doc/eval.txt 2013-02-20 17:58:01.000000000 +0100 --- runtime/doc/eval.txt 2013-02-20 20:53:50.000000000 +0100 *************** *** 1761,1772 **** foldtextresult( {lnum}) String text for closed fold at {lnum} foreground( ) Number bring the Vim window to the foreground function( {name}) Funcref reference to function {name} ! garbagecollect( [at_exit]) none free memory, breaking cyclic references 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} getchar( [expr]) Number get one character from the user getcharmod( ) Number modifiers for the last typed character getcmdline() String return the current command-line --- 1772,1784 ---- foldtextresult( {lnum}) String text for closed fold at {lnum} foreground( ) Number bring the Vim window to the foreground function( {name}) Funcref reference to function {name} ! garbagecollect( [{atexit}]) none free memory, breaking cyclic references 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} [, {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 *************** *** 1787,1798 **** 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}) 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} glob( {expr} [, {nosuf} [, {list}]]) any expand file wildcards in {expr} globpath( {path}, {expr} [, {flag}]) --- 1799,1812 ---- getqflist() List list of quickfix items getreg( [{regname} [, 1]]) String contents of register getregtype( [{regname}]) String type of register ! 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} [, {def}]) ! any variable {varname} in window {nr} glob( {expr} [, {nosuf} [, {list}]]) any expand file wildcards in {expr} globpath( {path}, {expr} [, {flag}]) *************** *** 3131,3137 **** Example: > :let lines = getbufline(bufnr("myfile"), 1, "$") ! getbufvar({expr}, {varname}) *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. --- 3146,3152 ---- Example: > :let lines = getbufline(bufnr("myfile"), 1, "$") ! 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. *************** *** 3141,3148 **** 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. Examples: > :let bufmodified = getbufvar(1, "&mod") :echo "todo myvar = " . getbufvar("todo", "myvar") --- 3156,3163 ---- 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 {def} or an empty ! string is returned, there is no error message. Examples: > :let bufmodified = getbufvar(1, "&mod") :echo "todo myvar = " . getbufvar("todo", "myvar") *************** *** 3414,3439 **** is one character with value 0x16. If {regname} is not specified, |v:register| is used. ! gettabvar({tabnr}, {varname}) *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. ! gettabwinvar({tabnr}, {winnr}, {varname}) *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. 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:". Examples: > :let list_is_on = gettabwinvar(1, 2, '&list') :echo "myvar = " . gettabwinvar(3, 1, 'myvar') --- 3434,3463 ---- is one character with value 0x16. If {regname} is not specified, |v:register| is used. ! 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} [, {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 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') *************** *** 3448,3454 **** the top of the GUI Vim window. The result will be -1 if the information is not available. ! getwinvar({winnr}, {varname}) *getwinvar()* Like |gettabwinvar()| for the current tabpage. Examples: > :let list_is_on = getwinvar(2, '&list') --- 3472,3478 ---- the top of the GUI Vim window. The result will be -1 if the information is not available. ! getwinvar({winnr}, {varname} [, {def}]) *getwinvar()* Like |gettabwinvar()| for the current tabpage. Examples: > :let list_is_on = getwinvar(2, '&list') *** ../vim-7.3.830/src/eval.c 2013-02-20 17:58:01.000000000 +0100 --- src/eval.c 2013-02-20 20:52:09.000000000 +0100 *************** *** 7916,7922 **** {"garbagecollect", 0, 1, f_garbagecollect}, {"get", 2, 3, f_get}, {"getbufline", 2, 3, f_getbufline}, ! {"getbufvar", 2, 2, f_getbufvar}, {"getchar", 0, 1, f_getchar}, {"getcharmod", 0, 0, f_getcharmod}, {"getcmdline", 0, 0, f_getcmdline}, --- 7916,7922 ---- {"garbagecollect", 0, 1, f_garbagecollect}, {"get", 2, 3, f_get}, {"getbufline", 2, 3, f_getbufline}, ! {"getbufvar", 2, 3, f_getbufvar}, {"getchar", 0, 1, f_getchar}, {"getcharmod", 0, 0, f_getcharmod}, {"getcmdline", 0, 0, f_getcmdline}, *************** *** 7936,7946 **** {"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}, {"getwinposx", 0, 0, f_getwinposx}, {"getwinposy", 0, 0, f_getwinposy}, ! {"getwinvar", 2, 2, f_getwinvar}, {"glob", 1, 3, f_glob}, {"globpath", 2, 3, f_globpath}, {"has", 1, 1, f_has}, --- 7936,7946 ---- {"getqflist", 0, 0, f_getqflist}, {"getreg", 0, 2, f_getreg}, {"getregtype", 0, 1, f_getregtype}, ! {"gettabvar", 2, 3, f_gettabvar}, ! {"gettabwinvar", 3, 4, f_gettabwinvar}, {"getwinposx", 0, 0, f_getwinposx}, {"getwinposy", 0, 0, f_getwinposy}, ! {"getwinvar", 2, 3, f_getwinvar}, {"glob", 1, 3, f_glob}, {"globpath", 2, 3, f_globpath}, {"has", 1, 1, f_has}, *************** *** 11115,11122 **** ++emsg_off; buf = get_buf_tv(&argvars[0]); ! rettv->v_type = VAR_STRING; ! rettv->vval.v_string = NULL; if (buf != NULL && varname != NULL) { --- 11115,11128 ---- ++emsg_off; buf = get_buf_tv(&argvars[0]); ! 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,11791 **** --- 11791,11801 ---- 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,11914 **** varname = get_tv_string_chk(&argvars[off + 1]); ++emsg_off; ! rettv->v_type = VAR_STRING; ! rettv->vval.v_string = NULL; if (win != NULL && varname != NULL) { --- 11917,11930 ---- varname = get_tv_string_chk(&argvars[off + 1]); ++emsg_off; ! 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) { *** ../vim-7.3.830/src/testdir/test91.in 2013-02-20 21:09:20.000000000 +0100 --- src/testdir/test91.in 2013-02-20 20:57:49.000000000 +0100 *************** *** 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: *** ../vim-7.3.830/src/testdir/test91.ok 2013-02-20 21:09:20.000000000 +0100 --- src/testdir/test91.ok 2013-02-20 20:57:45.000000000 +0100 *************** *** 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 *** ../vim-7.3.830/src/testdir/Make_amiga.mak 2013-02-13 17:34:59.000000000 +0100 --- src/testdir/Make_amiga.mak 2013-02-20 20:21:03.000000000 +0100 *************** *** 32,38 **** 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 .SUFFIXES: .in .out --- 32,38 ---- 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 test91.out .SUFFIXES: .in .out *************** *** 139,141 **** --- 139,142 ---- test88.out: test88.in test89.out: test89.in test90.out: test90.in + test91.out: test91.in *** ../vim-7.3.830/src/testdir/Make_dos.mak 2013-02-13 17:34:59.000000000 +0100 --- src/testdir/Make_dos.mak 2013-02-20 20:21:13.000000000 +0100 *************** *** 31,37 **** 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 SCRIPTS32 = test50.out test70.out --- 31,37 ---- 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 test91.out SCRIPTS32 = test50.out test70.out *** ../vim-7.3.830/src/testdir/Make_ming.mak 2013-02-13 17:34:59.000000000 +0100 --- src/testdir/Make_ming.mak 2013-02-20 20:21:19.000000000 +0100 *************** *** 51,57 **** 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 SCRIPTS32 = test50.out test70.out --- 51,57 ---- 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 test91.out SCRIPTS32 = test50.out test70.out *** ../vim-7.3.830/src/testdir/Make_os2.mak 2013-02-13 17:34:59.000000000 +0100 --- src/testdir/Make_os2.mak 2013-02-20 20:21:25.000000000 +0100 *************** *** 32,38 **** 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 .SUFFIXES: .in .out --- 32,38 ---- 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 test91.out .SUFFIXES: .in .out *** ../vim-7.3.830/src/testdir/Make_vms.mms 2013-02-13 17:34:59.000000000 +0100 --- src/testdir/Make_vms.mms 2013-02-20 20:21:31.000000000 +0100 *************** *** 4,10 **** # Authors: Zoltan Arpadffy, # Sandor Kopanyi, # ! # Last change: 2013 Feb 13 # # 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. --- 4,10 ---- # Authors: Zoltan Arpadffy, # Sandor Kopanyi, # ! # 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,83 **** 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 # Known problems: # Test 30: a problem around mac format - unknown reason --- 77,83 ---- 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 test91.out # Known problems: # Test 30: a problem around mac format - unknown reason *** ../vim-7.3.830/src/testdir/Makefile 2013-02-13 17:34:59.000000000 +0100 --- src/testdir/Makefile 2013-02-20 20:21:47.000000000 +0100 *************** *** 28,34 **** 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 SCRIPTS_GUI = test16.out --- 28,34 ---- 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 test91.out SCRIPTS_GUI = test16.out *** ../vim-7.3.830/src/version.c 2013-02-20 19:26:24.000000000 +0100 --- src/version.c 2013-02-20 21:08:40.000000000 +0100 *************** *** 730,731 **** --- 730,733 ---- { /* Add new patch number below this line */ + /**/ + 831, /**/ -- | Ceci n'est pas une pipe. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///