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
10 Patch 7.3.311 (replaces 7.3.289)
11 Problem: Complete function isn't called when the leader changed.
12 Solution: Allow the complete function to return a dictionary with a flag
13 that indicates ins_compl_restart() is to be called when the leader
14 changes. (Taro Muraoka)
15 Files: runtime/insert.txt, src/edit.c, src/eval.c, src/proto/eval.pro
18 *** ../vim-7.3.310/src/edit.c 2011-09-05 20:13:37.000000000 +0200
19 --- src/edit.c 2011-09-14 16:43:14.000000000 +0200
23 static int compl_cont_mode = 0;
24 static expand_T compl_xp;
26 + static int compl_opt_refresh_always = FALSE;
28 static void ins_ctrl_x __ARGS((void));
29 static int has_compl_option __ARGS((int dict_opt));
30 static int ins_compl_accept_char __ARGS((int c));
33 static void ins_compl_free __ARGS((void));
34 static void ins_compl_clear __ARGS((void));
35 static int ins_compl_bs __ARGS((void));
36 static void ins_compl_new_leader __ARGS((void));
37 static void ins_compl_addleader __ARGS((int c));
38 ! static int ins_compl_len __ARGS((void));
39 static void ins_compl_restart __ARGS((void));
40 static void ins_compl_set_original_text __ARGS((char_u *str));
41 static void ins_compl_addfrommatch __ARGS((void));
43 static void ins_compl_free __ARGS((void));
44 static void ins_compl_clear __ARGS((void));
45 static int ins_compl_bs __ARGS((void));
46 + static int ins_compl_need_restart __ARGS((void));
47 static void ins_compl_new_leader __ARGS((void));
48 static void ins_compl_addleader __ARGS((int c));
49 ! static int ins_compl_len __ARGS((void));
50 static void ins_compl_restart __ARGS((void));
51 static void ins_compl_set_original_text __ARGS((char_u *str));
52 static void ins_compl_addfrommatch __ARGS((void));
56 static buf_T *ins_compl_next_buf __ARGS((buf_T *buf, int flag));
57 #if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL)
58 static void ins_compl_add_list __ARGS((list_T *list));
59 + static void ins_compl_add_dict __ARGS((dict_T *dict));
61 static int ins_compl_get_exp __ARGS((pos_T *ini));
62 static void ins_compl_delete __ARGS((void));
65 /* Deleted more than what was used to find matches or didn't finish
66 * finding all matches: need to look for matches all over again. */
67 if (curwin->w_cursor.col <= compl_col + compl_length
68 ! || compl_was_interrupted)
71 vim_free(compl_leader);
73 /* Deleted more than what was used to find matches or didn't finish
74 * finding all matches: need to look for matches all over again. */
75 if (curwin->w_cursor.col <= compl_col + compl_length
76 ! || ins_compl_need_restart())
79 vim_free(compl_leader);
86 + * Return TRUE when we need to find matches again, ins_compl_restart() is to
90 + ins_compl_need_restart()
92 + /* Return TRUE if we didn't complete finding matches or when the
93 + * 'completefunc' returned "always" in the "refresh" dictionary item. */
94 + return compl_was_interrupted
95 + || ((ctrl_x_mode == CTRL_X_FUNCTION || ctrl_x_mode == CTRL_X_OMNI)
96 + && compl_opt_refresh_always);
100 * Called after changing "compl_leader".
101 * Show the popup menu with a different set of matches.
102 * May also search for matches again if the previous search was interrupted.
107 /* If we didn't complete finding matches we must search again. */
108 ! if (compl_was_interrupted)
111 vim_free(compl_leader);
115 /* If we didn't complete finding matches we must search again. */
116 ! if (ins_compl_need_restart())
119 vim_free(compl_leader);
122 int type; /* CTRL_X_OMNI or CTRL_X_FUNCTION */
132 funcname = (type == CTRL_X_FUNCTION) ? curbuf->b_p_cfu : curbuf->b_p_ofu;
133 if (*funcname == NUL)
135 int type; /* CTRL_X_OMNI or CTRL_X_FUNCTION */
138 ! list_T *matchlist = NULL;
139 ! dict_T *matchdict = NULL;
147 funcname = (type == CTRL_X_FUNCTION) ? curbuf->b_p_cfu : curbuf->b_p_ofu;
148 if (*funcname == NUL)
151 pos = curwin->w_cursor;
152 curwin_save = curwin;
153 curbuf_save = curbuf;
154 ! matchlist = call_func_retlist(funcname, 2, args, FALSE);
155 if (curwin_save != curwin || curbuf_save != curbuf)
159 pos = curwin->w_cursor;
160 curwin_save = curwin;
161 curbuf_save = curbuf;
163 ! /* Call a function, which returns a list or dict. */
164 ! if (call_vim_function(funcname, 2, args, FALSE, &rettv) == OK)
166 ! switch (rettv.v_type)
169 ! matchlist = rettv.vval.v_list;
172 ! matchdict = rettv.vval.v_dict;
175 ! /* TODO: Give error message? */
181 if (curwin_save != curwin || curbuf_save != curbuf)
191 if (matchlist != NULL)
192 ins_compl_add_list(matchlist);
193 + else if (matchdict != NULL)
194 + ins_compl_add_dict(matchdict);
197 + if (matchdict != NULL)
198 + dict_unref(matchdict);
199 if (matchlist != NULL)
200 list_unref(matchlist);
208 + * Add completions from a dict.
211 + ins_compl_add_dict(dict)
214 + dictitem_T *refresh;
217 + /* Check for optional "refresh" item. */
218 + compl_opt_refresh_always = FALSE;
219 + refresh = dict_find(dict, (char_u *)"refresh", 7);
220 + if (refresh != NULL && refresh->di_tv.v_type == VAR_STRING)
222 + char_u *v = refresh->di_tv.vval.v_string;
224 + if (v != NULL && STRCMP(v, (char_u *)"always") == 0)
225 + compl_opt_refresh_always = TRUE;
228 + /* Add completions from a "words" list. */
229 + words = dict_find(dict, (char_u *)"words", 5);
230 + if (words != NULL && words->di_tv.v_type == VAR_LIST)
231 + ins_compl_add_list(words->di_tv.vval.v_list);
235 * Add a match to the list of matches from a typeval_T.
236 * If the given string is already in the list of completions, then return
237 * NOTDONE, otherwise add it to the list and return OK. If there is an error,
245 + * Reset extended parameters of completion, when start new
248 + compl_opt_refresh_always = FALSE;
253 *** ../vim-7.3.310/src/eval.c 2011-09-14 14:33:47.000000000 +0200
254 --- src/eval.c 2011-09-14 16:16:47.000000000 +0200
258 static void prepare_vimvar __ARGS((int idx, typval_T *save_tv));
259 static void restore_vimvar __ARGS((int idx, typval_T *save_tv));
260 - #if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL)
261 - static int call_vim_function __ARGS((char_u *func, int argc, char_u **argv, int safe, typval_T *rettv));
263 static int ex_let_vars __ARGS((char_u *arg, typval_T *tv, int copy, int semicolon, int var_count, char_u *nextchars));
264 static char_u *skip_var_list __ARGS((char_u *arg, int *var_count, int *semicolon));
265 static char_u *skip_var_one __ARGS((char_u *arg));
269 static void set_ref_in_list __ARGS((list_T *l, int copyID));
270 static void set_ref_in_item __ARGS((typval_T *tv, int copyID));
271 static int rettv_dict_alloc __ARGS((typval_T *rettv));
272 - static void dict_unref __ARGS((dict_T *d));
273 static void dict_free __ARGS((dict_T *d, int recurse));
274 static dictitem_T *dictitem_copy __ARGS((dictitem_T *org));
275 static void dictitem_remove __ARGS((dict_T *dict, dictitem_T *item));
279 * arguments are currently supported.
280 * Returns OK or FAIL.
283 call_vim_function(func, argc, argv, safe, rettv)
287 * arguments are currently supported.
288 * Returns OK or FAIL.
291 call_vim_function(func, argc, argv, safe, rettv)
296 * Unreference a Dictionary: decrement the reference count and free it when it
304 * Unreference a Dictionary: decrement the reference count and free it when it
311 *** ../vim-7.3.310/src/proto/eval.pro 2010-08-15 21:57:28.000000000 +0200
312 --- src/proto/eval.pro 2011-09-14 16:16:47.000000000 +0200
316 list_T *eval_spell_expr __ARGS((char_u *badword, char_u *expr));
317 int get_spellword __ARGS((list_T *list, char_u **pp));
318 typval_T *eval_expr __ARGS((char_u *arg, char_u **nextcmd));
319 + int call_vim_function __ARGS((char_u *func, int argc, char_u **argv, int safe, typval_T *rettv));
320 void *call_func_retstr __ARGS((char_u *func, int argc, char_u **argv, int safe));
321 long call_func_retnr __ARGS((char_u *func, int argc, char_u **argv, int safe));
322 void *call_func_retlist __ARGS((char_u *func, int argc, char_u **argv, int safe));
326 int list_append_string __ARGS((list_T *l, char_u *str, int len));
327 int garbage_collect __ARGS((void));
328 dict_T *dict_alloc __ARGS((void));
329 + void dict_unref __ARGS((dict_T *d));
330 dictitem_T *dictitem_alloc __ARGS((char_u *key));
331 void dictitem_free __ARGS((dictitem_T *item));
332 int dict_add __ARGS((dict_T *d, dictitem_T *item));
333 *** ../vim-7.3.310/src/version.c 2011-09-14 16:04:52.000000000 +0200
334 --- src/version.c 2011-09-14 16:25:08.000000000 +0200
338 { /* Add new patch number below this line */
344 Contrary to popular belief, it's often your clothing that gets promoted, not
346 (Scott Adams - The Dilbert principle)
348 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
349 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
350 \\\ an exciting new programming language -- http://www.Zimbu.org ///
351 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///