mirror of
https://github.com/neovim/neovim.git
synced 2025-10-07 02:16:31 +00:00
Merge pull request #16047 from mcepl/vim-8.2.3520
vim-patch:8.2.3520: cannot define a function for thesaurus completion
This commit is contained in:
@@ -2071,7 +2071,8 @@ static bool check_compl_option(bool dict_opt)
|
||||
{
|
||||
if (dict_opt
|
||||
? (*curbuf->b_p_dict == NUL && *p_dict == NUL && !curwin->w_p_spell)
|
||||
: (*curbuf->b_p_tsr == NUL && *p_tsr == NUL)) {
|
||||
: (*curbuf->b_p_tsr == NUL && *p_tsr == NUL
|
||||
&& *curbuf->b_p_tsrfu == NUL && *p_tsrfu == NUL)) {
|
||||
ctrl_x_mode = CTRL_X_NORMAL;
|
||||
edit_submode = NULL;
|
||||
msg_attr((dict_opt
|
||||
@@ -3922,6 +3923,20 @@ static buf_T *ins_compl_next_buf(buf_T *buf, int flag)
|
||||
}
|
||||
|
||||
|
||||
/// Get the user-defined completion function name for completion 'type'
|
||||
static char_u *get_complete_funcname(int type) {
|
||||
switch (type) {
|
||||
case CTRL_X_FUNCTION:
|
||||
return curbuf->b_p_cfu;
|
||||
case CTRL_X_OMNI:
|
||||
return curbuf->b_p_ofu;
|
||||
case CTRL_X_THESAURUS:
|
||||
return *curbuf->b_p_tsrfu == NUL ? p_tsrfu : curbuf->b_p_tsrfu;
|
||||
default:
|
||||
return (char_u *)"";
|
||||
}
|
||||
}
|
||||
|
||||
/// Execute user defined complete function 'completefunc' or 'omnifunc', and
|
||||
/// get matches in "matches".
|
||||
///
|
||||
@@ -3938,7 +3953,7 @@ static void expand_by_function(int type, char_u *base)
|
||||
const int save_State = State;
|
||||
|
||||
assert(curbuf != NULL);
|
||||
funcname = (type == CTRL_X_FUNCTION) ? curbuf->b_p_cfu : curbuf->b_p_ofu;
|
||||
funcname = get_complete_funcname(type);
|
||||
if (*funcname == NUL) {
|
||||
return;
|
||||
}
|
||||
@@ -4097,6 +4112,13 @@ int ins_compl_add_tv(typval_T *const tv, const Direction dir, bool fast)
|
||||
(char_u **)cptext, true, &user_data, dir, flags, dup);
|
||||
}
|
||||
|
||||
/// Returns true when using a user-defined function for thesaurus completion.
|
||||
static bool thesaurus_func_complete(int type)
|
||||
{
|
||||
return type == CTRL_X_THESAURUS
|
||||
&& (*curbuf->b_p_tsrfu != NUL || *p_tsrfu != NUL);
|
||||
}
|
||||
|
||||
// Get the next expansion(s), using "compl_pattern".
|
||||
// The search starts at position "ini" in curbuf and in the direction
|
||||
// compl_direction.
|
||||
@@ -4270,17 +4292,17 @@ static int ins_compl_get_exp(pos_T *ini)
|
||||
|
||||
case CTRL_X_DICTIONARY:
|
||||
case CTRL_X_THESAURUS:
|
||||
ins_compl_dictionaries(dict != NULL ? dict
|
||||
: (type == CTRL_X_THESAURUS
|
||||
? (*curbuf->b_p_tsr == NUL
|
||||
? p_tsr
|
||||
: curbuf->b_p_tsr)
|
||||
: (*curbuf->b_p_dict == NUL
|
||||
? p_dict
|
||||
: curbuf->b_p_dict)),
|
||||
compl_pattern,
|
||||
dict != NULL ? dict_f
|
||||
: 0, type == CTRL_X_THESAURUS);
|
||||
if (thesaurus_func_complete(type)) {
|
||||
expand_by_function(type, compl_pattern);
|
||||
} else {
|
||||
ins_compl_dictionaries(dict != NULL ? dict
|
||||
: (type == CTRL_X_THESAURUS
|
||||
? (*curbuf->b_p_tsr == NUL ? p_tsr : curbuf->b_p_tsr)
|
||||
: (*curbuf->b_p_dict ==
|
||||
NUL ? p_dict : curbuf->b_p_dict)),
|
||||
compl_pattern,
|
||||
dict != NULL ? dict_f : 0, type == CTRL_X_THESAURUS);
|
||||
}
|
||||
dict = NULL;
|
||||
break;
|
||||
|
||||
@@ -5093,7 +5115,9 @@ static int ins_complete(int c, bool enable_pum)
|
||||
}
|
||||
|
||||
// Work out completion pattern and original text -- webb
|
||||
if (ctrl_x_mode == CTRL_X_NORMAL || (ctrl_x_mode & CTRL_X_WANT_IDENT)) {
|
||||
if (ctrl_x_mode == CTRL_X_NORMAL
|
||||
|| (ctrl_x_mode & CTRL_X_WANT_IDENT
|
||||
&& !thesaurus_func_complete(ctrl_x_mode))) {
|
||||
if ((compl_cont_status & CONT_SOL)
|
||||
|| ctrl_x_mode == CTRL_X_PATH_DEFINES) {
|
||||
if (!(compl_cont_status & CONT_ADDING)) {
|
||||
@@ -5203,22 +5227,18 @@ static int ins_complete(int c, bool enable_pum)
|
||||
compl_col = (int)(compl_xp.xp_pattern - compl_pattern);
|
||||
}
|
||||
compl_length = curs_col - compl_col;
|
||||
} else if (ctrl_x_mode == CTRL_X_FUNCTION || ctrl_x_mode ==
|
||||
CTRL_X_OMNI) {
|
||||
/*
|
||||
* Call user defined function 'completefunc' with "a:findstart"
|
||||
* set to 1 to obtain the length of text to use for completion.
|
||||
*/
|
||||
} else if (ctrl_x_mode == CTRL_X_FUNCTION || ctrl_x_mode == CTRL_X_OMNI
|
||||
|| thesaurus_func_complete(ctrl_x_mode)) {
|
||||
// Call user defined function 'completefunc' with "a:findstart"
|
||||
// set to 1 to obtain the length of text to use for completion.
|
||||
char_u *funcname;
|
||||
pos_T pos;
|
||||
win_T *curwin_save;
|
||||
buf_T *curbuf_save;
|
||||
const int save_State = State;
|
||||
|
||||
/* Call 'completefunc' or 'omnifunc' and get pattern length as a
|
||||
* string */
|
||||
funcname = ctrl_x_mode == CTRL_X_FUNCTION
|
||||
? curbuf->b_p_cfu : curbuf->b_p_ofu;
|
||||
// Call 'completefunc' or 'omnifunc' and get pattern length as a string
|
||||
funcname = get_complete_funcname(ctrl_x_mode);
|
||||
if (*funcname == NUL) {
|
||||
semsg(_(e_notset), ctrl_x_mode == CTRL_X_FUNCTION
|
||||
? "completefunc" : "omnifunc");
|
||||
|
Reference in New Issue
Block a user