Commit: patch 9.1.1498: completion: 'complete' funcs behave different to 'omnifunc'

4 views
Skip to first unread message

Christian Brabandt

unread,
Jun 30, 2025, 2:30:22 PM6/30/25
to vim...@googlegroups.com
patch 9.1.1498: completion: 'complete' funcs behave different to 'omnifunc'

Commit: https://github.com/vim/vim/commit/fa16c7ab3f219f93b24cf31ac8aafbd6b522d1bf
Author: Girish Palya <giri...@gmail.com>
Date: Mon Jun 30 20:14:43 2025 +0200

patch 9.1.1498: completion: 'complete' funcs behave different to 'omnifunc'

Problem: completion: Functions specified in the 'complete' option did
not have the leader string removed when called with findstart = 0,
unlike 'omnifunc' behavior
Solution: update behaviour and make behaviour consistent (Girish Palya)

closes: #17636

Signed-off-by: Girish Palya <giri...@gmail.com>
Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/insexpand.c b/src/insexpand.c
index ed1b5ff29..0c920709e 100644
--- a/src/insexpand.c
+++ b/src/insexpand.c
@@ -250,7 +250,7 @@ static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg);
static void ins_compl_add_list(list_T *list);
static void ins_compl_add_dict(dict_T *dict);
static int get_userdefined_compl_info(colnr_T curs_col, callback_T *cb, int *startcol);
-static void get_cpt_func_completion_matches(callback_T *cb);
+static void get_cpt_func_completion_matches(callback_T *cb, int restore_leader);
static callback_T *get_callback_if_cpt_func(char_u *p);
# endif
static int setup_cpt_sources(void);
@@ -4807,20 +4807,6 @@ get_callback_if_cpt_func(char_u *p)
}
return NULL;
}
-
-/*
- * Retrieve new completion matches by invoking callback "cb".
- */
- static void
-expand_cpt_function(callback_T *cb)
-{
- // Re-insert the text removed by ins_compl_delete().
- ins_compl_insert_bytes(compl_orig_text.string + get_compl_len(), -1);
- // Get matches
- get_cpt_func_completion_matches(cb);
- // Undo insertion
- ins_compl_delete();
-}
#endif

/*
@@ -4984,7 +4970,7 @@ get_next_completion_match(int type, ins_compl_next_state_T *st, pos_T *ini)
#ifdef FEAT_COMPL_FUNC
case CTRL_X_FUNCTION:
if (ctrl_x_mode_normal()) // Invoked by a func in 'cpt' option
- expand_cpt_function(st->func_cb);
+ get_cpt_func_completion_matches(st->func_cb, TRUE);
else
expand_by_function(type, compl_pattern.string, NULL);
break;
@@ -6989,16 +6975,23 @@ remove_old_matches(void)
*/
#ifdef FEAT_COMPL_FUNC
static void
-get_cpt_func_completion_matches(callback_T *cb UNUSED)
+get_cpt_func_completion_matches(callback_T *cb UNUSED, int restore_leader)
{
int startcol = cpt_sources_array[cpt_sources_index].cs_startcol;
+ int result;

VIM_CLEAR_STRING(cpt_compl_pattern);

if (startcol == -2 || startcol == -3)
return;

- if (set_compl_globals(startcol, curwin->w_cursor.col, TRUE) == OK)
+ if (restore_leader) // Re-insert the text removed by ins_compl_delete()
+ ins_compl_insert_bytes(compl_orig_text.string + get_compl_len(), -1);
+ result = set_compl_globals(startcol, curwin->w_cursor.col, TRUE);
+ if (restore_leader)
+ ins_compl_delete(); // Undo insertion
+
+ if (result == OK)
{
expand_by_function(0, cpt_compl_pattern.string, cb);
cpt_sources_array[cpt_sources_index].cs_refresh_always =
@@ -7051,7 +7044,7 @@ cpt_compl_refresh(void)
}
cpt_sources_array[cpt_sources_index].cs_startcol = startcol;
if (ret == OK)
- get_cpt_func_completion_matches(cb);
+ get_cpt_func_completion_matches(cb, FALSE);
}
}

diff --git a/src/testdir/test_ins_complete.vim b/src/testdir/test_ins_complete.vim
index b6692b554..d7309cb54 100644
--- a/src/testdir/test_ins_complete.vim
+++ b/src/testdir/test_ins_complete.vim
@@ -592,8 +592,8 @@ func Test_cpt_func_cursorcol()
call assert_equal(8, col('.'))
return col('.')
endif
- call assert_equal("foo bar", getline(1))
- call assert_equal(8, col('.'))
+ call assert_equal("foo ", getline(1))
+ call assert_equal(5, col('.'))
return v:none
endfunc

diff --git a/src/version.c b/src/version.c
index 7b13da4da..23a9f19aa 100644
--- a/src/version.c
+++ b/src/version.c
@@ -719,6 +719,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1498,
/**/
1497,
/**/
Reply all
Reply to author
Forward
0 new messages