astepano / rpms / vim

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