diff options
author | Michael Ennen <mike.ennen@gmail.com> | 2016-10-26 21:56:02 -0700 |
---|---|---|
committer | James McCoy <jamessan@jamessan.com> | 2016-12-12 10:17:35 -0500 |
commit | cf2701b269a0fd1490da4296774b9fe426100640 (patch) | |
tree | cf878024e86fe921d317273f0035d9cb60a5d6c9 /src | |
parent | 27b2fb944a4b9bce0f06e7c1f2267949c8edab06 (diff) | |
download | rneovim-cf2701b269a0fd1490da4296774b9fe426100640.tar.gz rneovim-cf2701b269a0fd1490da4296774b9fe426100640.tar.bz2 rneovim-cf2701b269a0fd1490da4296774b9fe426100640.zip |
vim-patch:7.4.1586
Problem: Nesting partials doesn't work.
Solution: Append arguments. (Ken Takata)
https://github.com/vim/vim/commit/8a1bb046378f4bc68d6a04af2eab80fb3ce04da6
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/eval.c | 39 | ||||
-rw-r--r-- | src/nvim/testdir/test_partial.vim | 8 | ||||
-rw-r--r-- | src/nvim/version.c | 2 |
3 files changed, 38 insertions, 11 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 51320ea2af..c61476cbfe 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -9455,6 +9455,7 @@ static void f_function(typval_T *argvars, typval_T *rettv, FunPtr fptr) char_u *s; char_u *name; bool use_string = false; + partial_T *arg_pt = NULL; if (argvars[0].v_type == VAR_FUNC) { // function(MyFunc, [arg], dict) @@ -9462,7 +9463,8 @@ static void f_function(typval_T *argvars, typval_T *rettv, FunPtr fptr) } else if (argvars[0].v_type == VAR_PARTIAL && argvars[0].vval.v_partial != NULL) { // function(dict.MyFunc, [arg]) - s = argvars[0].vval.v_partial->pt_name; + arg_pt = argvars[0].vval.v_partial; + s = arg_pt->pt_name; } else { // function('MyFunc', [arg], dict) s = get_tv_string(&argvars[0]); @@ -9535,23 +9537,37 @@ static void f_function(typval_T *argvars, typval_T *rettv, FunPtr fptr) } } } - if (dict_idx > 0 || arg_idx > 0) { + if (dict_idx > 0 || arg_idx > 0 || arg_pt != NULL) { partial_T *pt = (partial_T *)xcalloc(1, sizeof(partial_T)); + // result is a VAR_PARTIAL if (pt != NULL) { - if (arg_idx > 0) { + if (arg_idx > 0 || (arg_pt != NULL && arg_pt->pt_argc > 0)) { listitem_T *li; int i = 0; + int arg_len = 0; + int lv_len = 0; - pt->pt_argv = (typval_T *)xmalloc(sizeof(typval_T) * list->lv_len); + if (arg_pt != NULL) { + arg_len = arg_pt->pt_argc; + } + if (list != NULL) { + lv_len = list->lv_len; + } + pt->pt_argc = arg_len + lv_len; + pt->pt_argv = (typval_T *)xmalloc(sizeof(typval_T) * pt->pt_argc); if (pt->pt_argv == NULL) { xfree(pt); xfree(name); return; } else { - pt->pt_argc = list->lv_len; - for (li = list->lv_first; li != NULL; li = li->li_next) { - copy_tv(&li->li_tv, &pt->pt_argv[i++]); + for (i = 0; i < arg_len; i++) { + copy_tv(&arg_pt->pt_argv[i], &pt->pt_argv[i]); + } + if (lv_len > 0) { + for (li = list->lv_first; li != NULL; li = li->li_next) { + copy_tv(&li->li_tv, &pt->pt_argv[i++]); + } } } } @@ -9561,9 +9577,11 @@ static void f_function(typval_T *argvars, typval_T *rettv, FunPtr fptr) if (dict_idx > 0) { pt->pt_dict = argvars[dict_idx].vval.v_dict; (pt->pt_dict->dv_refcount)++; - } else if (argvars[0].v_type == VAR_PARTIAL) { - pt->pt_dict = argvars[0].vval.v_partial->pt_dict; - (pt->pt_dict->dv_refcount)++; + } else if (arg_pt != NULL) { + pt->pt_dict = arg_pt->pt_dict; + if (pt->pt_dict != NULL) { + (pt->pt_dict->dv_refcount)++; + } } pt->pt_refcount = 1; @@ -9573,6 +9591,7 @@ static void f_function(typval_T *argvars, typval_T *rettv, FunPtr fptr) rettv->v_type = VAR_PARTIAL; rettv->vval.v_partial = pt; } else { + // result is a VAR_FUNC rettv->v_type = VAR_FUNC; rettv->vval.v_string = name; func_ref(name); diff --git a/src/nvim/testdir/test_partial.vim b/src/nvim/testdir/test_partial.vim index 75cbfe2f25..ae4f74cf5b 100644 --- a/src/nvim/testdir/test_partial.vim +++ b/src/nvim/testdir/test_partial.vim @@ -20,9 +20,17 @@ func Test_partial_args() call Cb("zzz") call assert_equal("foo/bar/xxx", Cb("xxx")) call assert_equal("foo/bar/yyy", call(Cb, ["yyy"])) + let Cb2 = function(Cb) + call assert_equal("foo/bar/zzz", Cb2("zzz")) + let Cb3 = function(Cb, ["www"]) + call assert_equal("foo/bar/www", Cb3()) let Cb = function('MyFunc', []) call assert_equal("a/b/c", Cb("a", "b", "c")) + let Cb2 = function(Cb, []) + call assert_equal("a/b/d", Cb2("a", "b", "d")) + let Cb3 = function(Cb, ["a", "b"]) + call assert_equal("a/b/e", Cb3("e")) let Sort = function('MySort', [1]) call assert_equal([1, 2, 3], sort([3, 1, 2], Sort)) diff --git a/src/nvim/version.c b/src/nvim/version.c index e6be91e2fd..da9387c14d 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -856,7 +856,7 @@ static int included_patches[] = { // 1589, 1588, // 1587 NA - // 1586, + 1586, 1585, // 1584 NA // 1583 NA |