components/vim/vim72-patches/7.2.295
author Danek Duvall <danek.duvall@oracle.com>
Thu, 07 Apr 2011 16:25:07 -0700
changeset 198 172fc01ce997
permissions -rw-r--r--
7016732 move vim from sfw to userland 7036367 vim is too big

To: [email protected]
Subject: Patch 7.2.295
Fcc: outbox
From: Bram Moolenaar <[email protected]>
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 -- [email protected] -- 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    ///