]> granicus.if.org Git - vim/commitdiff
updated for version 7.3.224 v7.3.224
authorBram Moolenaar <Bram@vim.org>
Sun, 19 Jun 2011 00:55:37 +0000 (02:55 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 19 Jun 2011 00:55:37 +0000 (02:55 +0200)
Problem:    Can't pass dict to sort function.
Solution:   Add the optional {dict} argument to sort(). (ZyX)

runtime/doc/eval.txt
src/eval.c
src/version.c

index db5ae56360ffc06345efaa95071f2ae323e0fc06..01a59bf82f10982a826da6a2620a873b9c022b1d 100644 (file)
@@ -1919,7 +1919,8 @@ shellescape( {string} [, {special}])
 simplify( {filename})          String  simplify filename as much as possible
 sin( {expr})                   Float   sine of {expr}
 sinh( {expr})                  Float   hyperbolic sine of {expr}
-sort( {list} [, {func}])       List    sort {list}, using {func} to compare
+sort( {list} [, {func} [, {dict}]])
+                               List    sort {list}, using {func} to compare
 soundfold( {word})             String  sound-fold {word}
 spellbadword()                 String  badly spelled word at cursor
 spellsuggest( {word} [, {max} [, {capital}]])
@@ -5275,7 +5276,7 @@ sinh({expr})                                              *sinh()*
                {only available when compiled with the |+float| feature}
 
 
-sort({list} [, {func}])                                        *sort()* *E702*
+sort({list} [, {func} [, {dict}]])                     *sort()* *E702*
                Sort the items in {list} in-place.  Returns {list}.  If you
                want a list to remain unmodified make a copy first: >
                        :let sortedlist = sort(copy(mylist))
@@ -5283,6 +5284,8 @@ sort({list} [, {func}])                                   *sort()* *E702*
                Numbers sort after Strings, |Lists| after Numbers.
                For sorting text in the current buffer use |:sort|.
                When {func} is given and it is one then case is ignored.
+               {dict} is for functions with the "dict" attribute.  It will be
+               used to set the local variable "self". |Dictionary-function|
                When {func} is a |Funcref| or a function name, this function
                is called to compare items.  The function is invoked with two
                items as argument and must return zero if they are equal, 1 or
index a1912fd3c597fd1505965d9d5b9606d98002f7f1..648d938dc25d787632029d0abc7ad2ec7397dd9a 100644 (file)
@@ -7930,7 +7930,7 @@ static struct fst
     {"sin",            1, 1, f_sin},
     {"sinh",           1, 1, f_sinh},
 #endif
-    {"sort",           1, 2, f_sort},
+    {"sort",           1, 3, f_sort},
     {"soundfold",      1, 1, f_soundfold},
     {"spellbadword",   0, 1, f_spellbadword},
     {"spellsuggest",   1, 3, f_spellsuggest},
@@ -16366,6 +16366,7 @@ static int
 
 static int     item_compare_ic;
 static char_u  *item_compare_func;
+static dict_T  *item_compare_selfdict;
 static int     item_compare_func_err;
 #define ITEM_COMPARE_FAIL 999
 
@@ -16425,7 +16426,8 @@ item_compare2(s1, s2)
 
     rettv.v_type = VAR_UNKNOWN;                /* clear_tv() uses this */
     res = call_func(item_compare_func, (int)STRLEN(item_compare_func),
-                                &rettv, 2, argv, 0L, 0L, &dummy, TRUE, NULL);
+                                &rettv, 2, argv, 0L, 0L, &dummy, TRUE,
+                                item_compare_selfdict);
     clear_tv(&argv[0]);
     clear_tv(&argv[1]);
 
@@ -16471,8 +16473,10 @@ f_sort(argvars, rettv)
 
        item_compare_ic = FALSE;
        item_compare_func = NULL;
+       item_compare_selfdict = NULL;
        if (argvars[1].v_type != VAR_UNKNOWN)
        {
+           /* optional second argument: {func} */
            if (argvars[1].v_type == VAR_FUNC)
                item_compare_func = argvars[1].vval.v_string;
            else
@@ -16487,6 +16491,17 @@ f_sort(argvars, rettv)
                else
                    item_compare_func = get_tv_string(&argvars[1]);
            }
+
+           if (argvars[2].v_type != VAR_UNKNOWN)
+           {
+               /* optional third argument: {dict} */
+               if (argvars[2].v_type != VAR_DICT)
+               {
+                   EMSG(_(e_dictreq));
+                   return;
+               }
+               item_compare_selfdict = argvars[2].vval.v_dict;
+           }
        }
 
        /* Make an array with each entry pointing to an item in the List. */
index b6f1965919d766ffee7b6619c44a649bd0e3d0ff..a5afd2242e9c4c825224c7767386d01cc27d41d2 100644 (file)
@@ -709,6 +709,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    224,
 /**/
     223,
 /**/