5889ec3
To: vim_dev@googlegroups.com
5889ec3
Subject: Patch 7.3.224
5889ec3
Fcc: outbox
5889ec3
From: Bram Moolenaar <Bram@moolenaar.net>
5889ec3
Mime-Version: 1.0
5889ec3
Content-Type: text/plain; charset=UTF-8
5889ec3
Content-Transfer-Encoding: 8bit
5889ec3
------------
5889ec3
5889ec3
Patch 7.3.224
5889ec3
Problem:    Can't pass dict to sort function.
5889ec3
Solution:   Add the optional {dict} argument to sort(). (ZyX)
5889ec3
Files:      runtime/doc/eval.txt, src/eval.c
5889ec3
5889ec3
5889ec3
*** ../mercurial/vim73/runtime/doc/eval.txt	2011-05-19 17:25:36.000000000 +0200
5889ec3
--- runtime/doc/eval.txt	2011-06-19 02:42:52.000000000 +0200
5889ec3
***************
5889ec3
*** 1919,1925 ****
5889ec3
  simplify( {filename})		String	simplify filename as much as possible
5889ec3
  sin( {expr})			Float	sine of {expr}
5889ec3
  sinh( {expr})			Float	hyperbolic sine of {expr}
5889ec3
! sort( {list} [, {func}])	List	sort {list}, using {func} to compare
5889ec3
  soundfold( {word})		String	sound-fold {word}
5889ec3
  spellbadword()			String	badly spelled word at cursor
5889ec3
  spellsuggest( {word} [, {max} [, {capital}]])
5889ec3
--- 1922,1929 ----
5889ec3
  simplify( {filename})		String	simplify filename as much as possible
5889ec3
  sin( {expr})			Float	sine of {expr}
5889ec3
  sinh( {expr})			Float	hyperbolic sine of {expr}
5889ec3
! sort( {list} [, {func} [, {dict}]])
5889ec3
! 				List	sort {list}, using {func} to compare
5889ec3
  soundfold( {word})		String	sound-fold {word}
5889ec3
  spellbadword()			String	badly spelled word at cursor
5889ec3
  spellsuggest( {word} [, {max} [, {capital}]])
5889ec3
***************
5889ec3
*** 5275,5281 ****
5889ec3
  		{only available when compiled with the |+float| feature}
5889ec3
  
5889ec3
  
5889ec3
! sort({list} [, {func}])					*sort()* *E702*
5889ec3
  		Sort the items in {list} in-place.  Returns {list}.  If you
5889ec3
  		want a list to remain unmodified make a copy first: >
5889ec3
  			:let sortedlist = sort(copy(mylist))
5889ec3
--- 5279,5285 ----
5889ec3
  		{only available when compiled with the |+float| feature}
5889ec3
  
5889ec3
  
5889ec3
! sort({list} [, {func} [, {dict}]])			*sort()* *E702*
5889ec3
  		Sort the items in {list} in-place.  Returns {list}.  If you
5889ec3
  		want a list to remain unmodified make a copy first: >
5889ec3
  			:let sortedlist = sort(copy(mylist))
5889ec3
***************
5889ec3
*** 5283,5288 ****
5889ec3
--- 5287,5294 ----
5889ec3
  		Numbers sort after Strings, |Lists| after Numbers.
5889ec3
  		For sorting text in the current buffer use |:sort|.
5889ec3
  		When {func} is given and it is one then case is ignored.
5889ec3
+ 		{dict} is for functions with the "dict" attribute.  It will be
5889ec3
+ 		used to set the local variable "self". |Dictionary-function|
5889ec3
  		When {func} is a |Funcref| or a function name, this function
5889ec3
  		is called to compare items.  The function is invoked with two
5889ec3
  		items as argument and must return zero if they are equal, 1 or
5889ec3
*** ../mercurial/vim73/src/eval.c	2011-05-19 18:26:34.000000000 +0200
5889ec3
--- src/eval.c	2011-06-19 02:51:13.000000000 +0200
5889ec3
***************
5889ec3
*** 7930,7936 ****
5889ec3
      {"sin",		1, 1, f_sin},
5889ec3
      {"sinh",		1, 1, f_sinh},
5889ec3
  #endif
5889ec3
!     {"sort",		1, 2, f_sort},
5889ec3
      {"soundfold",	1, 1, f_soundfold},
5889ec3
      {"spellbadword",	0, 1, f_spellbadword},
5889ec3
      {"spellsuggest",	1, 3, f_spellsuggest},
5889ec3
--- 7930,7936 ----
5889ec3
      {"sin",		1, 1, f_sin},
5889ec3
      {"sinh",		1, 1, f_sinh},
5889ec3
  #endif
5889ec3
!     {"sort",		1, 3, f_sort},
5889ec3
      {"soundfold",	1, 1, f_soundfold},
5889ec3
      {"spellbadword",	0, 1, f_spellbadword},
5889ec3
      {"spellsuggest",	1, 3, f_spellsuggest},
5889ec3
***************
5889ec3
*** 16366,16371 ****
5889ec3
--- 16366,16372 ----
5889ec3
  
5889ec3
  static int	item_compare_ic;
5889ec3
  static char_u	*item_compare_func;
5889ec3
+ static dict_T	*item_compare_selfdict;
5889ec3
  static int	item_compare_func_err;
5889ec3
  #define ITEM_COMPARE_FAIL 999
5889ec3
  
5889ec3
***************
5889ec3
*** 16425,16431 ****
5889ec3
  
5889ec3
      rettv.v_type = VAR_UNKNOWN;		/* clear_tv() uses this */
5889ec3
      res = call_func(item_compare_func, (int)STRLEN(item_compare_func),
5889ec3
! 				 &rettv, 2, argv, 0L, 0L, &dummy, TRUE, NULL);
5889ec3
      clear_tv(&argv[0]);
5889ec3
      clear_tv(&argv[1]);
5889ec3
  
5889ec3
--- 16426,16433 ----
5889ec3
  
5889ec3
      rettv.v_type = VAR_UNKNOWN;		/* clear_tv() uses this */
5889ec3
      res = call_func(item_compare_func, (int)STRLEN(item_compare_func),
5889ec3
! 				 &rettv, 2, argv, 0L, 0L, &dummy, TRUE,
5889ec3
! 				 item_compare_selfdict);
5889ec3
      clear_tv(&argv[0]);
5889ec3
      clear_tv(&argv[1]);
5889ec3
  
5889ec3
***************
5889ec3
*** 16471,16478 ****
5889ec3
--- 16473,16482 ----
5889ec3
  
5889ec3
  	item_compare_ic = FALSE;
5889ec3
  	item_compare_func = NULL;
5889ec3
+ 	item_compare_selfdict = NULL;
5889ec3
  	if (argvars[1].v_type != VAR_UNKNOWN)
5889ec3
  	{
5889ec3
+ 	    /* optional second argument: {func} */
5889ec3
  	    if (argvars[1].v_type == VAR_FUNC)
5889ec3
  		item_compare_func = argvars[1].vval.v_string;
5889ec3
  	    else
5889ec3
***************
5889ec3
*** 16487,16492 ****
5889ec3
--- 16491,16507 ----
5889ec3
  		else
5889ec3
  		    item_compare_func = get_tv_string(&argvars[1]);
5889ec3
  	    }
5889ec3
+ 
5889ec3
+ 	    if (argvars[2].v_type != VAR_UNKNOWN)
5889ec3
+ 	    {
5889ec3
+ 		/* optional third argument: {dict} */
5889ec3
+ 		if (argvars[2].v_type != VAR_DICT)
5889ec3
+ 		{
5889ec3
+ 		    EMSG(_(e_dictreq));
5889ec3
+ 		    return;
5889ec3
+ 		}
5889ec3
+ 		item_compare_selfdict = argvars[2].vval.v_dict;
5889ec3
+ 	    }
5889ec3
  	}
5889ec3
  
5889ec3
  	/* Make an array with each entry pointing to an item in the List. */
5889ec3
*** ../vim-7.3.223/src/version.c	2011-06-19 01:30:01.000000000 +0200
5889ec3
--- src/version.c	2011-06-19 02:52:46.000000000 +0200
5889ec3
***************
5889ec3
*** 711,712 ****
5889ec3
--- 711,714 ----
5889ec3
  {   /* Add new patch number below this line */
5889ec3
+ /**/
5889ec3
+     224,
5889ec3
  /**/
5889ec3
5889ec3
-- 
5889ec3
hundred-and-one symptoms of being an internet addict:
5889ec3
193. You ask your girlfriend to drive home so you can sit back with
5889ec3
     your PDA and download the information to your laptop
5889ec3
5889ec3
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
5889ec3
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
5889ec3
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
5889ec3
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///