aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval.c
diff options
context:
space:
mode:
authorMichael Ennen <mike.ennen@gmail.com>2016-12-14 00:20:48 -0700
committerMichael Ennen <mike.ennen@gmail.com>2017-02-14 17:38:16 -0700
commitbb2afeb0266ffd410e2e226a376f7ddbac633491 (patch)
tree0488197944e3fc6a7c5ddf887eebc545c9f34c8b /src/nvim/eval.c
parentb0fc6108c923a198325354ae36b71f90c4c68e19 (diff)
downloadrneovim-bb2afeb0266ffd410e2e226a376f7ddbac633491.tar.gz
rneovim-bb2afeb0266ffd410e2e226a376f7ddbac633491.tar.bz2
rneovim-bb2afeb0266ffd410e2e226a376f7ddbac633491.zip
vim-patch:7.4.1989
Problem: filter() and map() only accept a string argument. Solution: Implement using a Funcref argument (Yasuhiro Matsumoto, Ken Takata) https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r--src/nvim/eval.c58
1 files changed, 39 insertions, 19 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 8692ddc334..e4afa18d10 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -5285,7 +5285,8 @@ tv_equal (
return TRUE;
}
- // For VAR_FUNC and VAR_PARTIAL only compare the function name.
+ // For VAR_FUNC and VAR_PARTIAL compare the function name, bound dict and
+ // arguments.
if ((tv1->v_type == VAR_FUNC
|| (tv1->v_type == VAR_PARTIAL && tv1->vval.v_partial != NULL))
&& (tv2->v_type == VAR_FUNC
@@ -9306,8 +9307,7 @@ static void findfilendir(typval_T *argvars, typval_T *rettv, int find_what)
*/
static void filter_map(typval_T *argvars, typval_T *rettv, int map)
{
- char_u buf[NUMBUFLEN];
- char_u *expr;
+ typval_T *expr;
listitem_T *li, *nli;
list_T *l = NULL;
dictitem_T *di;
@@ -9339,16 +9339,15 @@ static void filter_map(typval_T *argvars, typval_T *rettv, int map)
return;
}
- expr = get_tv_string_buf_chk(&argvars[1], buf);
- /* On type errors, the preceding call has already displayed an error
- * message. Avoid a misleading error message for an empty string that
- * was not passed as argument. */
- if (expr != NULL) {
+ expr = &argvars[1];
+ // On type errors, the preceding call has already displayed an error
+ // message. Avoid a misleading error message for an empty string that
+ // was not passed as argument.
+ if (expr->v_type != VAR_UNKNOWN) {
prepare_vimvar(VV_VAL, &save_val);
- expr = skipwhite(expr);
- /* We reset "did_emsg" to be able to detect whether an error
- * occurred during evaluation of the expression. */
+ // We reset "did_emsg" to be able to detect whether an error
+ // occurred during evaluation of the expression.
save_did_emsg = did_emsg;
did_emsg = FALSE;
@@ -9412,20 +9411,41 @@ static void filter_map(typval_T *argvars, typval_T *rettv, int map)
copy_tv(&argvars[0], rettv);
}
-static int filter_map_one(typval_T *tv, char_u *expr, int map, int *remp)
+static int filter_map_one(typval_T *tv, typval_T *expr, int map, int *remp)
{
typval_T rettv;
+ typeval_T argv[3];
char_u *s;
int retval = FAIL;
+ int dummy;
copy_tv(tv, &vimvars[VV_VAL].vv_tv);
- s = expr;
- if (eval1(&s, &rettv, TRUE) == FAIL)
- goto theend;
- if (*s != NUL) { /* check for trailing chars after expr */
- EMSG2(_(e_invexpr2), s);
- clear_tv(&rettv);
- goto theend;
+ argv[0] = vimvars[VV_KEY].vv_tv;
+ argv[1] = vimvars[VV_VAL].vv_tv;
+ s = expr->vval.v_string;
+ if (expr->v_type == VAR_FUNC) {
+ if (call_func(s, (int)STRLEN(s), &rettv, 2, argv, 0L, 0L, &dummy,
+ true, NULL, NULL) == FAIL) {
+ goto theend;
+ }
+ } else if (expr->v_type == VAR_PARTIAL) {
+ partial_T *partial = expr->vval.v_partial;
+
+ s = partial->pt_name;
+ if (call_func(s, (int)STRLEN(s), &rettv, 2, argv, 0L, 0L, &dummy,
+ true, partial, NULL) == FAIL) {
+ goto theend;
+ }
+ } else {
+ s = skipwhite(s);
+ if (eval1(&s, &rettv, true) == FAIL) {
+ goto theend;
+ }
+
+ if (*s != NUL) { // check for trailing chars after expr
+ EMSG2(_(e_invexpr2), s);
+ goto theend;
+ }
}
if (map) {
/* map(): replace the list item value */