summaryrefslogtreecommitdiff
path: root/src/eval.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/eval.c b/src/eval.c
index 40fcfefbf..9f7046770 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -9928,6 +9928,7 @@ filter_map(argvars, rettv, map)
int todo;
char_u *ermsg = map ? (char_u *)"map()" : (char_u *)"filter()";
int save_did_emsg;
+ int index = 0;
if (argvars[0].v_type == VAR_LIST)
{
@@ -9961,9 +9962,9 @@ filter_map(argvars, rettv, map)
save_did_emsg = did_emsg;
did_emsg = FALSE;
+ prepare_vimvar(VV_KEY, &save_key);
if (argvars[0].v_type == VAR_DICT)
{
- prepare_vimvar(VV_KEY, &save_key);
vimvars[VV_KEY].vv_type = VAR_STRING;
ht = &d->dv_hashtab;
@@ -9987,24 +9988,27 @@ filter_map(argvars, rettv, map)
}
}
hash_unlock(ht);
-
- restore_vimvar(VV_KEY, &save_key);
}
else
{
+ vimvars[VV_KEY].vv_type = VAR_NUMBER;
+
for (li = l->lv_first; li != NULL; li = nli)
{
if (tv_check_lock(li->li_tv.v_lock, ermsg))
break;
nli = li->li_next;
+ vimvars[VV_KEY].vv_nr = index;
if (filter_map_one(&li->li_tv, expr, map, &rem) == FAIL
|| did_emsg)
break;
if (!map && rem)
listitem_remove(l, li);
+ ++index;
}
}
+ restore_vimvar(VV_KEY, &save_key);
restore_vimvar(VV_VAL, &save_val);
did_emsg |= save_did_emsg;