summaryrefslogtreecommitdiffstats
path: root/src/insexpand.c
diff options
context:
space:
mode:
authorYegappan Lakshmanan <yegappan@yahoo.com>2021-10-16 15:41:29 +0100
committerBram Moolenaar <Bram@vim.org>2021-10-16 15:41:29 +0100
commit160e994d768d03a3c826b58115cde94df8fce607 (patch)
tree38f6ec253633b656db1be92790c26fc71eb72eee /src/insexpand.c
parent2286304cdbba53ceb52b3ba2ba4a521b0a2f8d0f (diff)
patch 8.2.3520: cannot define a function for thesaurus completionv8.2.3520
Problem: Cannot define a function for thesaurus completion. Solution: Add 'thesaurusfunc'. (Yegappan Lakshmanan, closes #8987, closes 8950)
Diffstat (limited to 'src/insexpand.c')
-rw-r--r--src/insexpand.c59
1 files changed, 52 insertions, 7 deletions
diff --git a/src/insexpand.c b/src/insexpand.c
index ee8263c8b8..624146a3f1 100644
--- a/src/insexpand.c
+++ b/src/insexpand.c
@@ -299,7 +299,11 @@ has_compl_option(int dict_opt)
&& !curwin->w_p_spell
#endif
)
- : (*curbuf->b_p_tsr == NUL && *p_tsr == NUL))
+ : (*curbuf->b_p_tsr == NUL && *p_tsr == NUL
+#ifdef FEAT_COMPL_FUNC
+ && *curbuf->b_p_thsfu == NUL
+#endif
+ ))
{
ctrl_x_mode = CTRL_X_NORMAL;
edit_submode = NULL;
@@ -2230,6 +2234,25 @@ ins_compl_next_buf(buf_T *buf, int flag)
#ifdef FEAT_COMPL_FUNC
/*
+ * 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_thsfu;
+ default:
+ return (char_u *)"";
+ }
+}
+
+/*
* Execute user defined complete function 'completefunc' or 'omnifunc', and
* get matches in "matches".
*/
@@ -2246,7 +2269,7 @@ expand_by_function(
typval_T rettv;
int save_State = State;
- funcname = (type == CTRL_X_FUNCTION) ? curbuf->b_p_cfu : curbuf->b_p_ofu;
+ funcname = get_complete_funcname(type);
if (*funcname == NUL)
return;
@@ -2721,6 +2744,21 @@ f_complete_info(typval_T *argvars, typval_T *rettv)
#endif
/*
+ * Returns TRUE when using a user-defined function for thesaurus completion.
+ */
+ static int
+thesaurus_func_complete(int type UNUSED)
+{
+#ifdef FEAT_COMPL_FUNC
+ return (type == CTRL_X_THESAURUS
+ && curbuf->b_p_thsfu != NULL
+ && *curbuf->b_p_thsfu != NUL);
+#else
+ return FALSE;
+#endif
+}
+
+/*
* Get the next expansion(s), using "compl_pattern".
* The search starts at position "ini" in curbuf and in the direction
* compl_direction.
@@ -2906,7 +2944,12 @@ ins_compl_get_exp(pos_T *ini)
case CTRL_X_DICTIONARY:
case CTRL_X_THESAURUS:
- ins_compl_dictionaries(
+#ifdef FEAT_COMPL_FUNC
+ if (thesaurus_func_complete(type))
+ expand_by_function(type, compl_pattern);
+ else
+#endif
+ ins_compl_dictionaries(
dict != NULL ? dict
: (type == CTRL_X_THESAURUS
? (*curbuf->b_p_tsr == NUL
@@ -3760,7 +3803,9 @@ ins_complete(int c, int 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)
@@ -3910,7 +3955,8 @@ ins_complete(int c, int 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)
+ else if (ctrl_x_mode == CTRL_X_FUNCTION || ctrl_x_mode == CTRL_X_OMNI
+ || thesaurus_func_complete(ctrl_x_mode))
{
#ifdef FEAT_COMPL_FUNC
// Call user defined function 'completefunc' with "a:findstart"
@@ -3923,8 +3969,7 @@ ins_complete(int c, int enable_pum)
// 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;
+ funcname = get_complete_funcname(ctrl_x_mode);
if (*funcname == NUL)
{
semsg(_(e_notset), ctrl_x_mode == CTRL_X_FUNCTION