]> granicus.if.org Git - vim/commitdiff
patch 7.4.1839 v7.4.1839
authorBram Moolenaar <Bram@vim.org>
Tue, 24 May 2016 16:37:12 +0000 (18:37 +0200)
committerBram Moolenaar <Bram@vim.org>
Tue, 24 May 2016 16:37:12 +0000 (18:37 +0200)
Problem:    Cannot get the items stored in a partial.
Solution:   Support using get() on a partial.

runtime/doc/eval.txt
src/eval.c
src/testdir/test_partial.vim
src/version.c

index 8dbc5b0c396c0beda9fb3b2f09317f64ce201564..36133d839fbfa97bbebcbd7e3ce609930351ae64 100644 (file)
@@ -3771,6 +3771,12 @@ get({dict}, {key} [, {default}])
                Get item with key {key} from |Dictionary| {dict}.  When this
                item is not available return {default}.  Return zero when
                {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({expr}, {lnum} [, {end}])
index a653b89f7227885c7cd67c3a9284ba8a6d23658e..99b948c7d80f438bd9c14f3f60943cf608aa6bbe 100644 (file)
@@ -12423,6 +12423,45 @@ f_get(typval_T *argvars, typval_T *rettv)
                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
        EMSG2(_(e_listdictarg), "get()");
 
index 8b11200d2b13042ff0638bc4f5a249cc269d4e85..30e1df99e7fbd6f2ebc52c05b3924f7635e5e247 100644 (file)
@@ -279,3 +279,12 @@ func Test_auto_partial_rebind()
   call assert_equal('dict1', dict2.f2())
   call assert_equal('dict1', dict2['f2']())
 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
index 46aff5391481257654fe5b9766a61e98c9c818b8..b53a7442643fb239ccf60711e7030c076280d133 100644 (file)
@@ -753,6 +753,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1839,
 /**/
     1838,
 /**/