summaryrefslogtreecommitdiff
path: root/source/ap/vim/patches/7.2.295
blob: 331498ffd1915f34c4ea034bde2daf6a8c6ab601 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
To: vim-dev@vim.org
Subject: Patch 7.2.295
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 7.2.295
Problem:    When using map() on a List the index is not known.
Solution:   Set v:key to the  index. (Hari Krishna Dara)
Files:	    runtime/doc/eval.txt, src/eval.c


*** ../vim-7.2.294/runtime/doc/eval.txt	2009-11-11 14:21:48.000000000 +0100
--- runtime/doc/eval.txt	2009-11-11 18:22:54.000000000 +0100
***************
*** 3802,3808 ****
  		Replace each item in {expr} with the result of evaluating
  		{string}.
  		Inside {string} |v:val| has the value of the current item.
! 		For a |Dictionary| |v:key| has the key of the current item.
  		Example: >
  			:call map(mylist, '"> " . v:val . " <"')
  <		This puts "> " before and " <" after each item in "mylist".
--- 3812,3819 ----
  		Replace each item in {expr} with the result of evaluating
  		{string}.
  		Inside {string} |v:val| has the value of the current item.
! 		For a |Dictionary| |v:key| has the key of the current item
! 		and for a |List| |v:key| has the index of the current item.
  		Example: >
  			:call map(mylist, '"> " . v:val . " <"')
  <		This puts "> " before and " <" after each item in "mylist".
*** ../vim-7.2.294/src/eval.c	2009-11-11 14:21:48.000000000 +0100
--- src/eval.c	2009-11-11 18:22:49.000000000 +0100
***************
*** 9928,9933 ****
--- 9928,9934 ----
      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,9969 ****
  	save_did_emsg = did_emsg;
  	did_emsg = FALSE;
  
  	if (argvars[0].v_type == VAR_DICT)
  	{
- 	    prepare_vimvar(VV_KEY, &save_key);
  	    vimvars[VV_KEY].vv_type = VAR_STRING;
  
  	    ht = &d->dv_hashtab;
--- 9962,9970 ----
  	save_did_emsg = did_emsg;
  	did_emsg = FALSE;
  
+ 	prepare_vimvar(VV_KEY, &save_key);
  	if (argvars[0].v_type == VAR_DICT)
  	{
  	    vimvars[VV_KEY].vv_type = VAR_STRING;
  
  	    ht = &d->dv_hashtab;
***************
*** 9987,10010 ****
  		}
  	    }
  	    hash_unlock(ht);
- 
- 	    restore_vimvar(VV_KEY, &save_key);
  	}
  	else
  	{
  	    for (li = l->lv_first; li != NULL; li = nli)
  	    {
  		if (tv_check_lock(li->li_tv.v_lock, ermsg))
  		    break;
  		nli = li->li_next;
  		if (filter_map_one(&li->li_tv, expr, map, &rem) == FAIL
  								  || did_emsg)
  		    break;
  		if (!map && rem)
  		    listitem_remove(l, li);
  	    }
  	}
  
  	restore_vimvar(VV_VAL, &save_val);
  
  	did_emsg |= save_did_emsg;
--- 9988,10014 ----
  		}
  	    }
  	    hash_unlock(ht);
  	}
  	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;
*** ../vim-7.2.294/src/version.c	2009-11-17 12:08:48.000000000 +0100
--- src/version.c	2009-11-17 12:18:08.000000000 +0100
***************
*** 683,684 ****
--- 683,686 ----
  {   /* Add new patch number below this line */
+ /**/
+     295,
  /**/

-- 
ARTHUR:       You are indeed brave Sir knight, but the fight is mine.
BLACK KNIGHT: Had enough?
ARTHUR:       You stupid bastard.  You havn't got any arms left.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///