I created the patch for adding default value argument feature.
I think this feature is useful to write Vim script.

Below is vim script for testing the feature.

-----------------------

echomsg getbufvar(1, 'foo', 'var')
echomsg getwinvar(1, 'foo', 'var')
echomsg gettabvar(1, 'foo', 'var')
echomsg gettabwinvar(1, 1, 'foo', 'var')

-----------------------

If you applied the patch to Vim, you get "var" output.
I tested the patch in Vim 7.3.762 and it works.

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
diff -r c0ac5ba66243 runtime/doc/eval.txt
--- a/runtime/doc/eval.txt	Wed Aug 29 18:50:54 2012 +0200
+++ b/runtime/doc/eval.txt	Thu Aug 30 16:46:06 2012 +0900
@@ -1777,7 +1777,9 @@
 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}
+					or {def}
 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 +1800,16 @@
 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}
+					or {def}
 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}
+					or {def}
 glob( {expr} [, {nosuf} [, {list}]])
 				any	expand file wildcards in {expr}
 globpath( {path}, {expr} [, {flag}])
 
@@ -3136,7 +3142,7 @@
 		Example: >
 			:let lines = getbufline(bufnr("myfile"), 1, "$")
 
-getbufvar({expr}, {varname})				*getbufvar()*
+getbufvar({expr}, {varname} [, {default}])		*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,8 +3152,8 @@
 		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 {default} or an
+		empty string is returned, there is no error message.
 		Examples: >
 			:let bufmodified = getbufvar(1, "&mod")
 			:echo "todo myvar = " . getbufvar("todo", "myvar")
@@ -3424,13 +3430,16 @@
 		<CTRL-V> is one character with value 0x16.
 		If {regname} is not specified, |v:register| is used.
 
-gettabvar({tabnr}, {varname})				*gettabvar()*
+gettabvar({tabnr}, {varname} [, {default}])		*gettabvar()*
 		Get the value of a tab-local variable {varname} in tab page
 		{tabnr}. |t:var|
 		Tabs are numbered starting with one.
+		When the tab or variable doesn't exist {default} or an
+		empty string is returned, there is no error message.
 		Note that the name without "t:" must be used.
 
-gettabwinvar({tabnr}, {winnr}, {varname})		*gettabwinvar()*
+gettabwinvar({tabnr}, {winnr}, {varname} [, {default}])
+							*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
@@ -3443,6 +3452,8 @@
 		or buffer-local variable.
 		When {varname} is empty a dictionary with all window-local
 		variables is returned.
+		When the tab or or window or variable doesn't exist {default}
+		or an empty string is returned, there is no error message.
 		Note that {varname} must be the name without "w:".
 		Examples: >
 			:let list_is_on = gettabwinvar(1, 2, '&list')
@@ -3458,7 +3469,7 @@
 		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} [, {default}])		*getwinvar()*
 		Like |gettabwinvar()| for the current tabpage.
 		Examples: >
 			:let list_is_on = getwinvar(2, '&list')
diff -r c0ac5ba66243 src/eval.c
--- a/src/eval.c	Wed Aug 29 18:50:54 2012 +0200
+++ b/src/eval.c	Thu Aug 30 16:46:06 2012 +0900
@@ -7909,7 +7909,7 @@
     {"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},
@@ -7929,11 +7929,11 @@
     {"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},
@@ -11091,8 +11091,15 @@
     ++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)
+    {
+	copy_tv(&argvars[2], rettv);
+    }
+    else
+    {
+	rettv->v_type = VAR_STRING;
+	rettv->vval.v_string = NULL;
+    }
 
     if (buf != NULL && varname != NULL)
     {
@@ -11750,8 +11757,15 @@
     dictitem_T	*v;
     char_u	*varname;
 
-    rettv->v_type = VAR_STRING;
-    rettv->vval.v_string = NULL;
+    if (argvars[2].v_type != VAR_UNKNOWN)
+    {
+	copy_tv(&argvars[2], rettv);
+    }
+    else
+    {
+	rettv->v_type = VAR_STRING;
+	rettv->vval.v_string = NULL;
+    }
 
     varname = get_tv_string_chk(&argvars[1]);
     tp = find_tabpage((int)get_tv_number_chk(&argvars[0], NULL));
@@ -11883,8 +11897,15 @@
     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)
+    {
+	copy_tv(&argvars[off + 2], rettv);
+    }
+    else
+    {
+	rettv->v_type = VAR_STRING;
+	rettv->vval.v_string = NULL;
+    }
 
     if (win != NULL && varname != NULL)
     {

Raspunde prin e-mail lui