]> git.pld-linux.org Git - packages/vim.git/blob - 7.2.295
- new
[packages/vim.git] / 7.2.295
1 To: vim-dev@vim.org
2 Subject: Patch 7.2.295
3 Fcc: outbox
4 From: Bram Moolenaar <Bram@moolenaar.net>
5 Mime-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8 ------------
9
10 Patch 7.2.295
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
14
15
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
18 ***************
19 *** 3802,3808 ****
20                 Replace each item in {expr} with the result of evaluating
21                 {string}.
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.
24                 Example: >
25                         :call map(mylist, '"> " . v:val . " <"')
26   <             This puts "> " before and " <" after each item in "mylist".
27 --- 3812,3819 ----
28                 Replace each item in {expr} with the result of evaluating
29                 {string}.
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.
33                 Example: >
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
38 ***************
39 *** 9928,9933 ****
40 --- 9928,9934 ----
41       int               todo;
42       char_u    *ermsg = map ? (char_u *)"map()" : (char_u *)"filter()";
43       int               save_did_emsg;
44 +     int               index = 0;
45   
46       if (argvars[0].v_type == VAR_LIST)
47       {
48 ***************
49 *** 9961,9969 ****
50         save_did_emsg = did_emsg;
51         did_emsg = FALSE;
52   
53         if (argvars[0].v_type == VAR_DICT)
54         {
55 -           prepare_vimvar(VV_KEY, &save_key);
56             vimvars[VV_KEY].vv_type = VAR_STRING;
57   
58             ht = &d->dv_hashtab;
59 --- 9962,9970 ----
60         save_did_emsg = did_emsg;
61         did_emsg = FALSE;
62   
63 +       prepare_vimvar(VV_KEY, &save_key);
64         if (argvars[0].v_type == VAR_DICT)
65         {
66             vimvars[VV_KEY].vv_type = VAR_STRING;
67   
68             ht = &d->dv_hashtab;
69 ***************
70 *** 9987,10010 ****
71                 }
72             }
73             hash_unlock(ht);
74
75 -           restore_vimvar(VV_KEY, &save_key);
76         }
77         else
78         {
79             for (li = l->lv_first; li != NULL; li = nli)
80             {
81                 if (tv_check_lock(li->li_tv.v_lock, ermsg))
82                     break;
83                 nli = li->li_next;
84                 if (filter_map_one(&li->li_tv, expr, map, &rem) == FAIL
85                                                                   || did_emsg)
86                     break;
87                 if (!map && rem)
88                     listitem_remove(l, li);
89             }
90         }
91   
92         restore_vimvar(VV_VAL, &save_val);
93   
94         did_emsg |= save_did_emsg;
95 --- 9988,10014 ----
96                 }
97             }
98             hash_unlock(ht);
99         }
100         else
101         {
102 +           vimvars[VV_KEY].vv_type = VAR_NUMBER;
103
104             for (li = l->lv_first; li != NULL; li = nli)
105             {
106                 if (tv_check_lock(li->li_tv.v_lock, ermsg))
107                     break;
108                 nli = li->li_next;
109 +               vimvars[VV_KEY].vv_nr = index;
110                 if (filter_map_one(&li->li_tv, expr, map, &rem) == FAIL
111                                                                   || did_emsg)
112                     break;
113                 if (!map && rem)
114                     listitem_remove(l, li);
115 +               ++index;
116             }
117         }
118   
119 +       restore_vimvar(VV_KEY, &save_key);
120         restore_vimvar(VV_VAL, &save_val);
121   
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
125 ***************
126 *** 683,684 ****
127 --- 683,686 ----
128   {   /* Add new patch number below this line */
129 + /**/
130 +     295,
131   /**/
132
133 -- 
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
138
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    ///
This page took 1.535065 seconds and 3 git commands to generate.