1 To: vim_dev@googlegroups.com
4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: Can't pass dict to sort function.
12 Solution: Add the optional {dict} argument to sort(). (ZyX)
13 Files: runtime/doc/eval.txt, src/eval.c
16 *** ../mercurial/vim73/runtime/doc/eval.txt 2011-05-19 17:25:36.000000000 +0200
17 --- runtime/doc/eval.txt 2011-06-19 02:42:52.000000000 +0200
20 simplify( {filename}) String simplify filename as much as possible
21 sin( {expr}) Float sine of {expr}
22 sinh( {expr}) Float hyperbolic sine of {expr}
23 ! sort( {list} [, {func}]) List sort {list}, using {func} to compare
24 soundfold( {word}) String sound-fold {word}
25 spellbadword() String badly spelled word at cursor
26 spellsuggest( {word} [, {max} [, {capital}]])
28 simplify( {filename}) String simplify filename as much as possible
29 sin( {expr}) Float sine of {expr}
30 sinh( {expr}) Float hyperbolic sine of {expr}
31 ! sort( {list} [, {func} [, {dict}]])
32 ! List sort {list}, using {func} to compare
33 soundfold( {word}) String sound-fold {word}
34 spellbadword() String badly spelled word at cursor
35 spellsuggest( {word} [, {max} [, {capital}]])
38 {only available when compiled with the |+float| feature}
41 ! sort({list} [, {func}]) *sort()* *E702*
42 Sort the items in {list} in-place. Returns {list}. If you
43 want a list to remain unmodified make a copy first: >
44 :let sortedlist = sort(copy(mylist))
46 {only available when compiled with the |+float| feature}
49 ! sort({list} [, {func} [, {dict}]]) *sort()* *E702*
50 Sort the items in {list} in-place. Returns {list}. If you
51 want a list to remain unmodified make a copy first: >
52 :let sortedlist = sort(copy(mylist))
56 Numbers sort after Strings, |Lists| after Numbers.
57 For sorting text in the current buffer use |:sort|.
58 When {func} is given and it is one then case is ignored.
59 + {dict} is for functions with the "dict" attribute. It will be
60 + used to set the local variable "self". |Dictionary-function|
61 When {func} is a |Funcref| or a function name, this function
62 is called to compare items. The function is invoked with two
63 items as argument and must return zero if they are equal, 1 or
64 *** ../mercurial/vim73/src/eval.c 2011-05-19 18:26:34.000000000 +0200
65 --- src/eval.c 2011-06-19 02:51:13.000000000 +0200
69 {"sinh", 1, 1, f_sinh},
71 ! {"sort", 1, 2, f_sort},
72 {"soundfold", 1, 1, f_soundfold},
73 {"spellbadword", 0, 1, f_spellbadword},
74 {"spellsuggest", 1, 3, f_spellsuggest},
77 {"sinh", 1, 1, f_sinh},
79 ! {"sort", 1, 3, f_sort},
80 {"soundfold", 1, 1, f_soundfold},
81 {"spellbadword", 0, 1, f_spellbadword},
82 {"spellsuggest", 1, 3, f_spellsuggest},
87 static int item_compare_ic;
88 static char_u *item_compare_func;
89 + static dict_T *item_compare_selfdict;
90 static int item_compare_func_err;
91 #define ITEM_COMPARE_FAIL 999
96 rettv.v_type = VAR_UNKNOWN; /* clear_tv() uses this */
97 res = call_func(item_compare_func, (int)STRLEN(item_compare_func),
98 ! &rettv, 2, argv, 0L, 0L, &dummy, TRUE, NULL);
104 rettv.v_type = VAR_UNKNOWN; /* clear_tv() uses this */
105 res = call_func(item_compare_func, (int)STRLEN(item_compare_func),
106 ! &rettv, 2, argv, 0L, 0L, &dummy, TRUE,
107 ! item_compare_selfdict);
115 item_compare_ic = FALSE;
116 item_compare_func = NULL;
117 + item_compare_selfdict = NULL;
118 if (argvars[1].v_type != VAR_UNKNOWN)
120 + /* optional second argument: {func} */
121 if (argvars[1].v_type == VAR_FUNC)
122 item_compare_func = argvars[1].vval.v_string;
128 item_compare_func = get_tv_string(&argvars[1]);
131 + if (argvars[2].v_type != VAR_UNKNOWN)
133 + /* optional third argument: {dict} */
134 + if (argvars[2].v_type != VAR_DICT)
136 + EMSG(_(e_dictreq));
139 + item_compare_selfdict = argvars[2].vval.v_dict;
143 /* Make an array with each entry pointing to an item in the List. */
144 *** ../vim-7.3.223/src/version.c 2011-06-19 01:30:01.000000000 +0200
145 --- src/version.c 2011-06-19 02:52:46.000000000 +0200
149 { /* Add new patch number below this line */
155 hundred-and-one symptoms of being an internet addict:
156 193. You ask your girlfriend to drive home so you can sit back with
157 your PDA and download the information to your laptop
159 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
160 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
161 \\\ an exciting new programming language -- http://www.Zimbu.org ///
162 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///