To: vim_dev@googlegroups.com Subject: Patch 7.3.311 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.3.311 (replaces 7.3.289) Problem: Complete function isn't called when the leader changed. Solution: Allow the complete function to return a dictionary with a flag that indicates ins_compl_restart() is to be called when the leader changes. (Taro Muraoka) Files: runtime/insert.txt, src/edit.c, src/eval.c, src/proto/eval.pro *** ../vim-7.3.310/src/edit.c 2011-09-05 20:13:37.000000000 +0200 --- src/edit.c 2011-09-14 16:43:14.000000000 +0200 *************** *** 135,140 **** --- 135,142 ---- static int compl_cont_mode = 0; static expand_T compl_xp; + static int compl_opt_refresh_always = FALSE; + static void ins_ctrl_x __ARGS((void)); static int has_compl_option __ARGS((int dict_opt)); static int ins_compl_accept_char __ARGS((int c)); *************** *** 153,161 **** static void ins_compl_free __ARGS((void)); static void ins_compl_clear __ARGS((void)); static int ins_compl_bs __ARGS((void)); static void ins_compl_new_leader __ARGS((void)); static void ins_compl_addleader __ARGS((int c)); ! static int ins_compl_len __ARGS((void)); static void ins_compl_restart __ARGS((void)); static void ins_compl_set_original_text __ARGS((char_u *str)); static void ins_compl_addfrommatch __ARGS((void)); --- 155,164 ---- static void ins_compl_free __ARGS((void)); static void ins_compl_clear __ARGS((void)); static int ins_compl_bs __ARGS((void)); + static int ins_compl_need_restart __ARGS((void)); static void ins_compl_new_leader __ARGS((void)); static void ins_compl_addleader __ARGS((int c)); ! static int ins_compl_len __ARGS((void)); static void ins_compl_restart __ARGS((void)); static void ins_compl_set_original_text __ARGS((char_u *str)); static void ins_compl_addfrommatch __ARGS((void)); *************** *** 163,168 **** --- 166,172 ---- static buf_T *ins_compl_next_buf __ARGS((buf_T *buf, int flag)); #if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL) static void ins_compl_add_list __ARGS((list_T *list)); + static void ins_compl_add_dict __ARGS((dict_T *dict)); #endif static int ins_compl_get_exp __ARGS((pos_T *ini)); static void ins_compl_delete __ARGS((void)); *************** *** 3341,3347 **** /* Deleted more than what was used to find matches or didn't finish * finding all matches: need to look for matches all over again. */ if (curwin->w_cursor.col <= compl_col + compl_length ! || compl_was_interrupted) ins_compl_restart(); vim_free(compl_leader); --- 3345,3351 ---- /* Deleted more than what was used to find matches or didn't finish * finding all matches: need to look for matches all over again. */ if (curwin->w_cursor.col <= compl_col + compl_length ! || ins_compl_need_restart()) ins_compl_restart(); vim_free(compl_leader); *************** *** 3355,3360 **** --- 3359,3378 ---- } /* + * Return TRUE when we need to find matches again, ins_compl_restart() is to + * be called. + */ + static int + ins_compl_need_restart() + { + /* Return TRUE if we didn't complete finding matches or when the + * 'completefunc' returned "always" in the "refresh" dictionary item. */ + return compl_was_interrupted + || ((ctrl_x_mode == CTRL_X_FUNCTION || ctrl_x_mode == CTRL_X_OMNI) + && compl_opt_refresh_always); + } + + /* * Called after changing "compl_leader". * Show the popup menu with a different set of matches. * May also search for matches again if the previous search was interrupted. *************** *** 3443,3449 **** ins_char(c); /* If we didn't complete finding matches we must search again. */ ! if (compl_was_interrupted) ins_compl_restart(); vim_free(compl_leader); --- 3461,3467 ---- ins_char(c); /* If we didn't complete finding matches we must search again. */ ! if (ins_compl_need_restart()) ins_compl_restart(); vim_free(compl_leader); *************** *** 3871,3882 **** int type; /* CTRL_X_OMNI or CTRL_X_FUNCTION */ char_u *base; { ! list_T *matchlist; char_u *args[2]; char_u *funcname; pos_T pos; win_T *curwin_save; buf_T *curbuf_save; funcname = (type == CTRL_X_FUNCTION) ? curbuf->b_p_cfu : curbuf->b_p_ofu; if (*funcname == NUL) --- 3889,3902 ---- int type; /* CTRL_X_OMNI or CTRL_X_FUNCTION */ char_u *base; { ! list_T *matchlist = NULL; ! dict_T *matchdict = NULL; char_u *args[2]; char_u *funcname; pos_T pos; win_T *curwin_save; buf_T *curbuf_save; + typval_T rettv; funcname = (type == CTRL_X_FUNCTION) ? curbuf->b_p_cfu : curbuf->b_p_ofu; if (*funcname == NUL) *************** *** 3889,3895 **** pos = curwin->w_cursor; curwin_save = curwin; curbuf_save = curbuf; ! matchlist = call_func_retlist(funcname, 2, args, FALSE); if (curwin_save != curwin || curbuf_save != curbuf) { EMSG(_(e_complwin)); --- 3909,3933 ---- pos = curwin->w_cursor; curwin_save = curwin; curbuf_save = curbuf; ! ! /* Call a function, which returns a list or dict. */ ! if (call_vim_function(funcname, 2, args, FALSE, &rettv) == OK) ! { ! switch (rettv.v_type) ! { ! case VAR_LIST: ! matchlist = rettv.vval.v_list; ! break; ! case VAR_DICT: ! matchdict = rettv.vval.v_dict; ! break; ! default: ! /* TODO: Give error message? */ ! clear_tv(&rettv); ! break; ! } ! } ! if (curwin_save != curwin || curbuf_save != curbuf) { EMSG(_(e_complwin)); *************** *** 3902,3911 **** --- 3940,3954 ---- EMSG(_(e_compldel)); goto theend; } + if (matchlist != NULL) ins_compl_add_list(matchlist); + else if (matchdict != NULL) + ins_compl_add_dict(matchdict); theend: + if (matchdict != NULL) + dict_unref(matchdict); if (matchlist != NULL) list_unref(matchlist); } *************** *** 3934,3939 **** --- 3977,4009 ---- } /* + * Add completions from a dict. + */ + static void + ins_compl_add_dict(dict) + dict_T *dict; + { + dictitem_T *refresh; + dictitem_T *words; + + /* Check for optional "refresh" item. */ + compl_opt_refresh_always = FALSE; + refresh = dict_find(dict, (char_u *)"refresh", 7); + if (refresh != NULL && refresh->di_tv.v_type == VAR_STRING) + { + char_u *v = refresh->di_tv.vval.v_string; + + if (v != NULL && STRCMP(v, (char_u *)"always") == 0) + compl_opt_refresh_always = TRUE; + } + + /* Add completions from a "words" list. */ + words = dict_find(dict, (char_u *)"words", 5); + if (words != NULL && words->di_tv.v_type == VAR_LIST) + ins_compl_add_list(words->di_tv.vval.v_list); + } + + /* * Add a match to the list of matches from a typeval_T. * If the given string is already in the list of completions, then return * NOTDONE, otherwise add it to the list and return OK. If there is an error, *************** *** 5088,5093 **** --- 5158,5169 ---- return FAIL; } + /* + * Reset extended parameters of completion, when start new + * completion. + */ + compl_opt_refresh_always = FALSE; + if (col < 0) col = curs_col; compl_col = col; *** ../vim-7.3.310/src/eval.c 2011-09-14 14:33:47.000000000 +0200 --- src/eval.c 2011-09-14 16:16:47.000000000 +0200 *************** *** 380,388 **** static void prepare_vimvar __ARGS((int idx, typval_T *save_tv)); static void restore_vimvar __ARGS((int idx, typval_T *save_tv)); - #if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) - static int call_vim_function __ARGS((char_u *func, int argc, char_u **argv, int safe, typval_T *rettv)); - #endif static int ex_let_vars __ARGS((char_u *arg, typval_T *tv, int copy, int semicolon, int var_count, char_u *nextchars)); static char_u *skip_var_list __ARGS((char_u *arg, int *var_count, int *semicolon)); static char_u *skip_var_one __ARGS((char_u *arg)); --- 380,385 ---- *************** *** 451,457 **** static void set_ref_in_list __ARGS((list_T *l, int copyID)); static void set_ref_in_item __ARGS((typval_T *tv, int copyID)); static int rettv_dict_alloc __ARGS((typval_T *rettv)); - static void dict_unref __ARGS((dict_T *d)); static void dict_free __ARGS((dict_T *d, int recurse)); static dictitem_T *dictitem_copy __ARGS((dictitem_T *org)); static void dictitem_remove __ARGS((dict_T *dict, dictitem_T *item)); --- 448,453 ---- *************** *** 1563,1569 **** * arguments are currently supported. * Returns OK or FAIL. */ ! static int call_vim_function(func, argc, argv, safe, rettv) char_u *func; int argc; --- 1559,1565 ---- * arguments are currently supported. * Returns OK or FAIL. */ ! int call_vim_function(func, argc, argv, safe, rettv) char_u *func; int argc; *************** *** 6903,6909 **** * Unreference a Dictionary: decrement the reference count and free it when it * becomes zero. */ ! static void dict_unref(d) dict_T *d; { --- 6899,6905 ---- * Unreference a Dictionary: decrement the reference count and free it when it * becomes zero. */ ! void dict_unref(d) dict_T *d; { *** ../vim-7.3.310/src/proto/eval.pro 2010-08-15 21:57:28.000000000 +0200 --- src/proto/eval.pro 2011-09-14 16:16:47.000000000 +0200 *************** *** 23,28 **** --- 23,29 ---- list_T *eval_spell_expr __ARGS((char_u *badword, char_u *expr)); int get_spellword __ARGS((list_T *list, char_u **pp)); typval_T *eval_expr __ARGS((char_u *arg, char_u **nextcmd)); + int call_vim_function __ARGS((char_u *func, int argc, char_u **argv, int safe, typval_T *rettv)); void *call_func_retstr __ARGS((char_u *func, int argc, char_u **argv, int safe)); long call_func_retnr __ARGS((char_u *func, int argc, char_u **argv, int safe)); void *call_func_retlist __ARGS((char_u *func, int argc, char_u **argv, int safe)); *************** *** 52,57 **** --- 53,59 ---- int list_append_string __ARGS((list_T *l, char_u *str, int len)); int garbage_collect __ARGS((void)); dict_T *dict_alloc __ARGS((void)); + void dict_unref __ARGS((dict_T *d)); dictitem_T *dictitem_alloc __ARGS((char_u *key)); void dictitem_free __ARGS((dictitem_T *item)); int dict_add __ARGS((dict_T *d, dictitem_T *item)); *** ../vim-7.3.310/src/version.c 2011-09-14 16:04:52.000000000 +0200 --- src/version.c 2011-09-14 16:25:08.000000000 +0200 *************** *** 711,712 **** --- 711,714 ---- { /* Add new patch number below this line */ + /**/ + 311, /**/ -- Contrary to popular belief, it's often your clothing that gets promoted, not you. (Scott Adams - The Dilbert principle) /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///