mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
updated for version 7.3.311
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)
This commit is contained in:
parent
15d6319b9d
commit
821390843b
86
src/edit.c
86
src/edit.c
@ -135,6 +135,8 @@ static char_u *compl_orig_text = NULL; /* text as it was before
|
||||
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,9 +155,10 @@ static char_u *find_line_end __ARGS((char_u *ptr));
|
||||
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 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,6 +166,7 @@ static int ins_compl_prep __ARGS((int c));
|
||||
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,7 +3345,7 @@ ins_compl_bs()
|
||||
/* 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_need_restart())
|
||||
ins_compl_restart();
|
||||
|
||||
vim_free(compl_leader);
|
||||
@ -3354,6 +3358,20 @@ ins_compl_bs()
|
||||
return K_BS;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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.
|
||||
@ -3443,7 +3461,7 @@ ins_compl_addleader(c)
|
||||
ins_char(c);
|
||||
|
||||
/* If we didn't complete finding matches we must search again. */
|
||||
if (compl_was_interrupted)
|
||||
if (ins_compl_need_restart())
|
||||
ins_compl_restart();
|
||||
|
||||
vim_free(compl_leader);
|
||||
@ -3871,12 +3889,14 @@ expand_by_function(type, base)
|
||||
int type; /* CTRL_X_OMNI or CTRL_X_FUNCTION */
|
||||
char_u *base;
|
||||
{
|
||||
list_T *matchlist;
|
||||
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,7 +3909,25 @@ expand_by_function(type, base)
|
||||
pos = curwin->w_cursor;
|
||||
curwin_save = curwin;
|
||||
curbuf_save = curbuf;
|
||||
matchlist = call_func_retlist(funcname, 2, args, FALSE);
|
||||
|
||||
/* 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,10 +3940,15 @@ expand_by_function(type, base)
|
||||
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);
|
||||
}
|
||||
@ -3933,6 +3976,33 @@ ins_compl_add_list(list)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 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
|
||||
@ -5088,6 +5158,12 @@ ins_complete(c)
|
||||
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;
|
||||
|
@ -380,9 +380,6 @@ static dictitem_T vimvars_var;
|
||||
|
||||
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));
|
||||
@ -451,7 +448,6 @@ static void set_ref_in_ht __ARGS((hashtab_T *ht, int copyID));
|
||||
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));
|
||||
@ -1563,7 +1559,7 @@ eval_expr(arg, nextcmd)
|
||||
* arguments are currently supported.
|
||||
* Returns OK or FAIL.
|
||||
*/
|
||||
static int
|
||||
int
|
||||
call_vim_function(func, argc, argv, safe, rettv)
|
||||
char_u *func;
|
||||
int argc;
|
||||
@ -6903,7 +6899,7 @@ rettv_dict_alloc(rettv)
|
||||
* Unreference a Dictionary: decrement the reference count and free it when it
|
||||
* becomes zero.
|
||||
*/
|
||||
static void
|
||||
void
|
||||
dict_unref(d)
|
||||
dict_T *d;
|
||||
{
|
||||
|
@ -23,6 +23,7 @@ int eval_to_number __ARGS((char_u *expr));
|
||||
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,6 +53,7 @@ int list_append_dict __ARGS((list_T *list, dict_T *dict));
|
||||
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));
|
||||
|
@ -709,6 +709,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
311,
|
||||
/**/
|
||||
310,
|
||||
/**/
|
||||
|
Loading…
x
Reference in New Issue
Block a user