Karsten Hopp 195c47
To: vim-dev@vim.org
Karsten Hopp 195c47
Subject: Patch 7.2.295
Karsten Hopp 195c47
Fcc: outbox
Karsten Hopp 195c47
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 195c47
Mime-Version: 1.0
Karsten Hopp 195c47
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 195c47
Content-Transfer-Encoding: 8bit
Karsten Hopp 195c47
------------
Karsten Hopp 195c47
Karsten Hopp 195c47
Patch 7.2.295
Karsten Hopp 195c47
Problem:    When using map() on a List the index is not known.
Karsten Hopp 195c47
Solution:   Set v:key to the  index. (Hari Krishna Dara)
Karsten Hopp 195c47
Files:	    runtime/doc/eval.txt, src/eval.c
Karsten Hopp 195c47
Karsten Hopp 195c47
Karsten Hopp 195c47
*** ../vim-7.2.294/runtime/doc/eval.txt	2009-11-11 14:21:48.000000000 +0100
Karsten Hopp 195c47
--- runtime/doc/eval.txt	2009-11-11 18:22:54.000000000 +0100
Karsten Hopp 195c47
***************
Karsten Hopp 195c47
*** 3802,3808 ****
Karsten Hopp 195c47
  		Replace each item in {expr} with the result of evaluating
Karsten Hopp 195c47
  		{string}.
Karsten Hopp 195c47
  		Inside {string} |v:val| has the value of the current item.
Karsten Hopp 195c47
! 		For a |Dictionary| |v:key| has the key of the current item.
Karsten Hopp 195c47
  		Example: >
Karsten Hopp 195c47
  			:call map(mylist, '"> " . v:val . " <"')
Karsten Hopp 195c47
  <		This puts "> " before and " <" after each item in "mylist".
Karsten Hopp 195c47
--- 3812,3819 ----
Karsten Hopp 195c47
  		Replace each item in {expr} with the result of evaluating
Karsten Hopp 195c47
  		{string}.
Karsten Hopp 195c47
  		Inside {string} |v:val| has the value of the current item.
Karsten Hopp 195c47
! 		For a |Dictionary| |v:key| has the key of the current item
Karsten Hopp 195c47
! 		and for a |List| |v:key| has the index of the current item.
Karsten Hopp 195c47
  		Example: >
Karsten Hopp 195c47
  			:call map(mylist, '"> " . v:val . " <"')
Karsten Hopp 195c47
  <		This puts "> " before and " <" after each item in "mylist".
Karsten Hopp 195c47
*** ../vim-7.2.294/src/eval.c	2009-11-11 14:21:48.000000000 +0100
Karsten Hopp 195c47
--- src/eval.c	2009-11-11 18:22:49.000000000 +0100
Karsten Hopp 195c47
***************
Karsten Hopp 195c47
*** 9928,9933 ****
Karsten Hopp 195c47
--- 9928,9934 ----
Karsten Hopp 195c47
      int		todo;
Karsten Hopp 195c47
      char_u	*ermsg = map ? (char_u *)"map()" : (char_u *)"filter()";
Karsten Hopp 195c47
      int		save_did_emsg;
Karsten Hopp 195c47
+     int		index = 0;
Karsten Hopp 195c47
  
Karsten Hopp 195c47
      if (argvars[0].v_type == VAR_LIST)
Karsten Hopp 195c47
      {
Karsten Hopp 195c47
***************
Karsten Hopp 195c47
*** 9961,9969 ****
Karsten Hopp 195c47
  	save_did_emsg = did_emsg;
Karsten Hopp 195c47
  	did_emsg = FALSE;
Karsten Hopp 195c47
  
Karsten Hopp 195c47
  	if (argvars[0].v_type == VAR_DICT)
Karsten Hopp 195c47
  	{
Karsten Hopp 195c47
- 	    prepare_vimvar(VV_KEY, &save_key);
Karsten Hopp 195c47
  	    vimvars[VV_KEY].vv_type = VAR_STRING;
Karsten Hopp 195c47
  
Karsten Hopp 195c47
  	    ht = &d->dv_hashtab;
Karsten Hopp 195c47
--- 9962,9970 ----
Karsten Hopp 195c47
  	save_did_emsg = did_emsg;
Karsten Hopp 195c47
  	did_emsg = FALSE;
Karsten Hopp 195c47
  
Karsten Hopp 195c47
+ 	prepare_vimvar(VV_KEY, &save_key);
Karsten Hopp 195c47
  	if (argvars[0].v_type == VAR_DICT)
Karsten Hopp 195c47
  	{
Karsten Hopp 195c47
  	    vimvars[VV_KEY].vv_type = VAR_STRING;
Karsten Hopp 195c47
  
Karsten Hopp 195c47
  	    ht = &d->dv_hashtab;
Karsten Hopp 195c47
***************
Karsten Hopp 195c47
*** 9987,10010 ****
Karsten Hopp 195c47
  		}
Karsten Hopp 195c47
  	    }
Karsten Hopp 195c47
  	    hash_unlock(ht);
Karsten Hopp 195c47
- 
Karsten Hopp 195c47
- 	    restore_vimvar(VV_KEY, &save_key);
Karsten Hopp 195c47
  	}
Karsten Hopp 195c47
  	else
Karsten Hopp 195c47
  	{
Karsten Hopp 195c47
  	    for (li = l->lv_first; li != NULL; li = nli)
Karsten Hopp 195c47
  	    {
Karsten Hopp 195c47
  		if (tv_check_lock(li->li_tv.v_lock, ermsg))
Karsten Hopp 195c47
  		    break;
Karsten Hopp 195c47
  		nli = li->li_next;
Karsten Hopp 195c47
  		if (filter_map_one(&li->li_tv, expr, map, &rem) == FAIL
Karsten Hopp 195c47
  								  || did_emsg)
Karsten Hopp 195c47
  		    break;
Karsten Hopp 195c47
  		if (!map && rem)
Karsten Hopp 195c47
  		    listitem_remove(l, li);
Karsten Hopp 195c47
  	    }
Karsten Hopp 195c47
  	}
Karsten Hopp 195c47
  
Karsten Hopp 195c47
  	restore_vimvar(VV_VAL, &save_val);
Karsten Hopp 195c47
  
Karsten Hopp 195c47
  	did_emsg |= save_did_emsg;
Karsten Hopp 195c47
--- 9988,10014 ----
Karsten Hopp 195c47
  		}
Karsten Hopp 195c47
  	    }
Karsten Hopp 195c47
  	    hash_unlock(ht);
Karsten Hopp 195c47
  	}
Karsten Hopp 195c47
  	else
Karsten Hopp 195c47
  	{
Karsten Hopp 195c47
+ 	    vimvars[VV_KEY].vv_type = VAR_NUMBER;
Karsten Hopp 195c47
+ 
Karsten Hopp 195c47
  	    for (li = l->lv_first; li != NULL; li = nli)
Karsten Hopp 195c47
  	    {
Karsten Hopp 195c47
  		if (tv_check_lock(li->li_tv.v_lock, ermsg))
Karsten Hopp 195c47
  		    break;
Karsten Hopp 195c47
  		nli = li->li_next;
Karsten Hopp 195c47
+ 		vimvars[VV_KEY].vv_nr = index;
Karsten Hopp 195c47
  		if (filter_map_one(&li->li_tv, expr, map, &rem) == FAIL
Karsten Hopp 195c47
  								  || did_emsg)
Karsten Hopp 195c47
  		    break;
Karsten Hopp 195c47
  		if (!map && rem)
Karsten Hopp 195c47
  		    listitem_remove(l, li);
Karsten Hopp 195c47
+ 		++index;
Karsten Hopp 195c47
  	    }
Karsten Hopp 195c47
  	}
Karsten Hopp 195c47
  
Karsten Hopp 195c47
+ 	restore_vimvar(VV_KEY, &save_key);
Karsten Hopp 195c47
  	restore_vimvar(VV_VAL, &save_val);
Karsten Hopp 195c47
  
Karsten Hopp 195c47
  	did_emsg |= save_did_emsg;
Karsten Hopp 195c47
*** ../vim-7.2.294/src/version.c	2009-11-17 12:08:48.000000000 +0100
Karsten Hopp 195c47
--- src/version.c	2009-11-17 12:18:08.000000000 +0100
Karsten Hopp 195c47
***************
Karsten Hopp 195c47
*** 683,684 ****
Karsten Hopp 195c47
--- 683,686 ----
Karsten Hopp 195c47
  {   /* Add new patch number below this line */
Karsten Hopp 195c47
+ /**/
Karsten Hopp 195c47
+     295,
Karsten Hopp 195c47
  /**/
Karsten Hopp 195c47
Karsten Hopp 195c47
-- 
Karsten Hopp 195c47
ARTHUR:       You are indeed brave Sir knight, but the fight is mine.
Karsten Hopp 195c47
BLACK KNIGHT: Had enough?
Karsten Hopp 195c47
ARTHUR:       You stupid bastard.  You havn't got any arms left.
Karsten Hopp 195c47
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
Karsten Hopp 195c47
Karsten Hopp 195c47
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 195c47
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 195c47
\\\        download, build and distribute -- http://www.A-A-P.org        ///
Karsten Hopp 195c47
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///