mirror of
https://github.com/vim/vim.git
synced 2025-09-27 04:14:06 -04:00
patch 7.4.1839
Problem: Cannot get the items stored in a partial. Solution: Support using get() on a partial.
This commit is contained in:
@@ -3771,6 +3771,12 @@ get({dict}, {key} [, {default}])
|
|||||||
Get item with key {key} from |Dictionary| {dict}. When this
|
Get item with key {key} from |Dictionary| {dict}. When this
|
||||||
item is not available return {default}. Return zero when
|
item is not available return {default}. Return zero when
|
||||||
{default} is omitted.
|
{default} is omitted.
|
||||||
|
get({partial}, {what})
|
||||||
|
Get an item with from Funcref {partial}. Possible values for
|
||||||
|
{what} are:
|
||||||
|
'func' The function
|
||||||
|
'dict' The dictionary
|
||||||
|
'args' The list with arguments
|
||||||
|
|
||||||
*getbufline()*
|
*getbufline()*
|
||||||
getbufline({expr}, {lnum} [, {end}])
|
getbufline({expr}, {lnum} [, {end}])
|
||||||
|
39
src/eval.c
39
src/eval.c
@@ -12423,6 +12423,45 @@ f_get(typval_T *argvars, typval_T *rettv)
|
|||||||
tv = &di->di_tv;
|
tv = &di->di_tv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (argvars[0].v_type == VAR_PARTIAL)
|
||||||
|
{
|
||||||
|
partial_T *pt = argvars[0].vval.v_partial;
|
||||||
|
|
||||||
|
if (pt != NULL)
|
||||||
|
{
|
||||||
|
char_u *what = get_tv_string(&argvars[1]);
|
||||||
|
|
||||||
|
if (STRCMP(what, "func") == 0)
|
||||||
|
{
|
||||||
|
rettv->v_type = VAR_STRING;
|
||||||
|
if (pt->pt_name == NULL)
|
||||||
|
rettv->vval.v_string = NULL;
|
||||||
|
else
|
||||||
|
rettv->vval.v_string = vim_strsave(pt->pt_name);
|
||||||
|
}
|
||||||
|
else if (STRCMP(what, "dict") == 0)
|
||||||
|
{
|
||||||
|
rettv->v_type = VAR_DICT;
|
||||||
|
rettv->vval.v_dict = pt->pt_dict;
|
||||||
|
if (pt->pt_dict != NULL)
|
||||||
|
++pt->pt_dict->dv_refcount;
|
||||||
|
}
|
||||||
|
else if (STRCMP(what, "args") == 0)
|
||||||
|
{
|
||||||
|
rettv->v_type = VAR_LIST;
|
||||||
|
if (rettv_list_alloc(rettv) == OK)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < pt->pt_argc; ++i)
|
||||||
|
list_append_tv(rettv->vval.v_list, &pt->pt_argv[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
EMSG2(_(e_invarg2), what);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
EMSG2(_(e_listdictarg), "get()");
|
EMSG2(_(e_listdictarg), "get()");
|
||||||
|
|
||||||
|
@@ -279,3 +279,12 @@ func Test_auto_partial_rebind()
|
|||||||
call assert_equal('dict1', dict2.f2())
|
call assert_equal('dict1', dict2.f2())
|
||||||
call assert_equal('dict1', dict2['f2']())
|
call assert_equal('dict1', dict2['f2']())
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_get_partial_items()
|
||||||
|
let dict = {'name': 'hello'}
|
||||||
|
let Cb = function('MyDictFunc', ["foo", "bar"], dict)
|
||||||
|
call assert_equal('MyDictFunc', get(Cb, 'func'))
|
||||||
|
call assert_equal(["foo", "bar"], get(Cb, 'args'))
|
||||||
|
call assert_equal(dict, get(Cb, 'dict'))
|
||||||
|
call assert_fails('call get(Cb, "xxx")', 'E475:')
|
||||||
|
endfunc
|
||||||
|
@@ -753,6 +753,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1839,
|
||||||
/**/
|
/**/
|
||||||
1838,
|
1838,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user