4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: When using map() on a List the index is not known.
12 Solution: Set v:key to the index. (Hari Krishna Dara)
13 Files: runtime/doc/eval.txt, src/eval.c
16 *** ../vim-7.2.294/runtime/doc/eval.txt 2009-11-11 14:21:48.000000000 +0100
17 --- runtime/doc/eval.txt 2009-11-11 18:22:54.000000000 +0100
20 Replace each item in {expr} with the result of evaluating
22 Inside {string} |v:val| has the value of the current item.
23 ! For a |Dictionary| |v:key| has the key of the current item.
25 :call map(mylist, '"> " . v:val . " <"')
26 < This puts "> " before and " <" after each item in "mylist".
28 Replace each item in {expr} with the result of evaluating
30 Inside {string} |v:val| has the value of the current item.
31 ! For a |Dictionary| |v:key| has the key of the current item
32 ! and for a |List| |v:key| has the index of the current item.
34 :call map(mylist, '"> " . v:val . " <"')
35 < This puts "> " before and " <" after each item in "mylist".
36 *** ../vim-7.2.294/src/eval.c 2009-11-11 14:21:48.000000000 +0100
37 --- src/eval.c 2009-11-11 18:22:49.000000000 +0100
42 char_u *ermsg = map ? (char_u *)"map()" : (char_u *)"filter()";
46 if (argvars[0].v_type == VAR_LIST)
50 save_did_emsg = did_emsg;
53 if (argvars[0].v_type == VAR_DICT)
55 - prepare_vimvar(VV_KEY, &save_key);
56 vimvars[VV_KEY].vv_type = VAR_STRING;
60 save_did_emsg = did_emsg;
63 + prepare_vimvar(VV_KEY, &save_key);
64 if (argvars[0].v_type == VAR_DICT)
66 vimvars[VV_KEY].vv_type = VAR_STRING;
75 - restore_vimvar(VV_KEY, &save_key);
79 for (li = l->lv_first; li != NULL; li = nli)
81 if (tv_check_lock(li->li_tv.v_lock, ermsg))
84 if (filter_map_one(&li->li_tv, expr, map, &rem) == FAIL
88 listitem_remove(l, li);
92 restore_vimvar(VV_VAL, &save_val);
94 did_emsg |= save_did_emsg;
102 + vimvars[VV_KEY].vv_type = VAR_NUMBER;
104 for (li = l->lv_first; li != NULL; li = nli)
106 if (tv_check_lock(li->li_tv.v_lock, ermsg))
109 + vimvars[VV_KEY].vv_nr = index;
110 if (filter_map_one(&li->li_tv, expr, map, &rem) == FAIL
114 listitem_remove(l, li);
119 + restore_vimvar(VV_KEY, &save_key);
120 restore_vimvar(VV_VAL, &save_val);
122 did_emsg |= save_did_emsg;
123 *** ../vim-7.2.294/src/version.c 2009-11-17 12:08:48.000000000 +0100
124 --- src/version.c 2009-11-17 12:18:08.000000000 +0100
128 { /* Add new patch number below this line */
134 ARTHUR: You are indeed brave Sir knight, but the fight is mine.
135 BLACK KNIGHT: Had enough?
136 ARTHUR: You stupid bastard. You havn't got any arms left.
137 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
139 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
140 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
141 \\\ download, build and distribute -- http://www.A-A-P.org ///
142 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///