summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2022-09-24 11:17:51 +0100
committerBram Moolenaar <Bram@vim.org>2022-09-24 11:17:51 +0100
commit87af60c91503e37c9144f8e48022b12994ce2c85 (patch)
tree47a15f29beb65b378d85bc7686485c94cb4b71d6
parent9fd1583c839c5e43b0d48ec815a79005a2364776 (diff)
patch 9.0.0567: 'completeopt' "longest" is not used for complete()v9.0.0567
Problem: 'completeopt' "longest" is not used for complete(). Solution: Also use "longest" for complete(). (Bjorn Linse, closes #11206)
-rw-r--r--src/insexpand.c13
-rw-r--r--src/testdir/test_ins_complete.vim20
-rw-r--r--src/version.c2
3 files changed, 32 insertions, 3 deletions
diff --git a/src/insexpand.c b/src/insexpand.c
index f9ee4e6e5e..37162a48ce 100644
--- a/src/insexpand.c
+++ b/src/insexpand.c
@@ -153,6 +153,8 @@ static int compl_no_insert = FALSE; // FALSE: select & insert
// TRUE: noinsert
static int compl_no_select = FALSE; // FALSE: select & insert
// TRUE: noselect
+static int compl_longest = FALSE; // FALSE: insert full match
+ // TRUE: insert longest prefix
// Selected one of the matches. When FALSE the match was edited or using the
// longest common string.
@@ -1042,10 +1044,13 @@ completeopt_was_set(void)
{
compl_no_insert = FALSE;
compl_no_select = FALSE;
+ compl_longest = FALSE;
if (strstr((char *)p_cot, "noselect") != NULL)
compl_no_select = TRUE;
if (strstr((char *)p_cot, "noinsert") != NULL)
compl_no_insert = TRUE;
+ if (strstr((char *)p_cot, "longest") != NULL)
+ compl_longest = TRUE;
}
@@ -2383,7 +2388,7 @@ ins_compl_prep(int c)
if (ctrl_x_mode_not_defined_yet()
|| (ctrl_x_mode_normal() && !compl_started))
{
- compl_get_longest = (strstr((char *)p_cot, "longest") != NULL);
+ compl_get_longest = compl_longest;
compl_used_match = TRUE;
}
@@ -2864,6 +2869,7 @@ set_completion(colnr_T startcol, list_T *list)
ins_compl_prep(' ');
ins_compl_clear();
ins_compl_free();
+ compl_get_longest = compl_longest;
compl_direction = FORWARD;
if (startcol > curwin->w_cursor.col)
@@ -2888,10 +2894,11 @@ set_completion(colnr_T startcol, list_T *list)
compl_cont_status = 0;
compl_curr_match = compl_first_match;
- if (compl_no_insert || compl_no_select)
+ int no_select = compl_no_select || compl_longest;
+ if (compl_no_insert || no_select)
{
ins_complete(K_DOWN, FALSE);
- if (compl_no_select)
+ if (no_select)
// Down/Up has no real effect.
ins_complete(K_UP, FALSE);
}
diff --git a/src/testdir/test_ins_complete.vim b/src/testdir/test_ins_complete.vim
index a79a7867fe..aca97d047e 100644
--- a/src/testdir/test_ins_complete.vim
+++ b/src/testdir/test_ins_complete.vim
@@ -699,6 +699,26 @@ func Test_recursive_complete_func()
bw!
endfunc
+" Test for using complete() with completeopt+=longest
+func Test_complete_with_longest()
+ inoremap <f3> <cmd>call complete(1, ["iaax", "iaay", "iaaz"])<cr>
+ new
+
+ " default: insert first match
+ set completeopt&
+ call setline(1, ['i'])
+ exe "normal Aa\<f3>\<esc>"
+ call assert_equal('iaax', getline(1))
+
+ " with longest: insert longest prefix
+ set completeopt+=longest
+ call setline(1, ['i'])
+ exe "normal Aa\<f3>\<esc>"
+ call assert_equal('iaa', getline(1))
+ set completeopt&
+endfunc
+
+
" Test for completing words following a completed word in a line
func Test_complete_wrapscan()
" complete words from another buffer
diff --git a/src/version.c b/src/version.c
index 26eada3463..bf58a7aca7 100644
--- a/src/version.c
+++ b/src/version.c
@@ -700,6 +700,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 567,
+/**/
566,
/**/
565,