patch 9.1.1555: completion: repeated insertion of leader

Problem:  completion: repeated insertion and deletion of complete
          functions
Solution: Remove unnecessary insertion and deletion of leader text
          ('compl_orig_text') during expansion of function present in
          'complete' option (Girish Palya).

closes: #17738

Signed-off-by: Girish Palya <girishji@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Girish Palya
2025-07-16 19:53:56 +02:00
committed by Christian Brabandt
parent e4fdb1e4e7
commit 78b10eab6c
3 changed files with 124 additions and 115 deletions

View File

@ -5122,7 +5122,7 @@ strip_caret_numbers_in_place(char_u *str)
* Call functions specified in the 'cpt' option with findstart=1,
* and retrieve the startcol.
*/
static void
static int
prepare_cpt_compl_funcs(void)
{
#ifdef FEAT_COMPL_FUNC
@ -5134,11 +5134,10 @@ prepare_cpt_compl_funcs(void)
// Make a copy of 'cpt' in case the buffer gets wiped out
cpt = vim_strsave(curbuf->b_p_cpt);
if (cpt == NULL)
return FAIL;
strip_caret_numbers_in_place(cpt);
// Re-insert the text removed by ins_compl_delete().
ins_compl_insert_bytes(compl_orig_text.string + get_compl_len(), -1);
for (p = cpt; *p;)
{
while (*p == ',' || *p == ' ') // Skip delimiters
@ -5166,11 +5165,10 @@ prepare_cpt_compl_funcs(void)
idx++;
}
// Undo insertion
ins_compl_delete();
vim_free(cpt);
return OK;
#endif
return FAIL;
}
/*
@ -5179,13 +5177,13 @@ prepare_cpt_compl_funcs(void)
static int
advance_cpt_sources_index_safe(void)
{
if (cpt_sources_index < cpt_sources_count - 1)
if (cpt_sources_index >= 0 && cpt_sources_index < cpt_sources_count - 1)
{
cpt_sources_index++;
return OK;
}
#ifdef FEAT_EVAL
semsg(_(e_list_index_out_of_range_nr), cpt_sources_index + 1);
semsg(_(e_list_index_out_of_range_nr), cpt_sources_index);
#endif
return FAIL;
}
@ -5237,18 +5235,10 @@ ins_compl_get_exp(pos_T *ini)
st.cur_match_pos = (compl_dir_forward())
? &st.last_match_pos : &st.first_match_pos;
if (ctrl_x_mode_normal() && !ctrl_x_mode_line_or_eval() &&
!(compl_cont_status & CONT_LOCAL))
{
// ^N completion, not ^X^L or complete() or ^X^N
if (!compl_started) // Before showing menu the first time
{
if (setup_cpt_sources() == FAIL)
return FAIL;
}
prepare_cpt_compl_funcs();
if (cpt_sources_array != NULL && ctrl_x_mode_normal()
&& !ctrl_x_mode_line_or_eval()
&& !(compl_cont_status & CONT_LOCAL))
cpt_sources_index = 0;
}
// For ^N/^P loop over all the flags/windows/buffers in 'complete'.
for (;;)
@ -6142,6 +6132,14 @@ get_normal_compl_info(char_u *line, int startcol, colnr_T curs_col)
}
}
// Call functions in 'complete' with 'findstart=1'
if (ctrl_x_mode_normal() && !(compl_cont_status & CONT_LOCAL))
{
// ^N completion, not complete() or ^X^N
if (setup_cpt_sources() == FAIL || prepare_cpt_compl_funcs() == FAIL)
return FAIL;
}
return OK;
}
@ -6975,9 +6973,14 @@ setup_cpt_sources(void)
char_u buf[LSIZE];
int slen;
int count = 0, idx = 0;
char_u *p;
char_u *p, *cpt;
for (p = curbuf->b_p_cpt; *p;)
// Make a copy of 'cpt' in case the buffer gets wiped out
cpt = vim_strsave(curbuf->b_p_cpt);
if (cpt == NULL)
return FAIL;
for (p = cpt; *p;)
{
while (*p == ',' || *p == ' ') // Skip delimiters
p++;
@ -6988,7 +6991,7 @@ setup_cpt_sources(void)
}
}
if (count == 0)
return OK;
goto theend;
cpt_sources_clear();
cpt_sources_count = count;
@ -6996,10 +6999,11 @@ setup_cpt_sources(void)
if (cpt_sources_array == NULL)
{
cpt_sources_count = 0;
vim_free(cpt);
return FAIL;
}
for (p = curbuf->b_p_cpt; *p;)
for (p = cpt; *p;)
{
while (*p == ',' || *p == ' ') // Skip delimiters
p++;
@ -7014,6 +7018,9 @@ setup_cpt_sources(void)
idx++;
}
}
theend:
vim_free(cpt);
return OK;
}

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-07-16 18:54+0200\n"
"POT-Creation-Date: 2025-07-16 19:53+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -1781,44 +1781,44 @@ msgstr ""
msgid "Scanning tags."
msgstr ""
#: ../insexpand.c:5567
#: ../insexpand.c:5557
msgid "match in file"
msgstr ""
#: ../insexpand.c:6609
#: ../insexpand.c:6607
msgid " Adding"
msgstr ""
#: ../insexpand.c:6669
#: ../insexpand.c:6667
msgid "-- Searching..."
msgstr ""
#: ../insexpand.c:6689
#: ../insexpand.c:6687
msgid "Hit end of paragraph"
msgstr ""
#: ../insexpand.c:6690
#: ../insexpand.c:6688
msgid "Pattern not found"
msgstr ""
#: ../insexpand.c:6698
#: ../insexpand.c:6696
msgid "Back at original"
msgstr ""
#: ../insexpand.c:6703
#: ../insexpand.c:6701
msgid "Word from other line"
msgstr ""
#: ../insexpand.c:6708
#: ../insexpand.c:6706
msgid "The only match"
msgstr ""
#: ../insexpand.c:6729
#: ../insexpand.c:6727
#, c-format
msgid "match %d of %d"
msgstr ""
#: ../insexpand.c:6733
#: ../insexpand.c:6731
#, c-format
msgid "match %d"
msgstr ""
@ -4257,327 +4257,327 @@ msgstr ""
msgid "%s (%s, compiled %s)"
msgstr ""
#: ../version.c:4042
#: ../version.c:4044
msgid ""
"\n"
"MS-Windows ARM64 GUI/console version"
msgstr ""
#: ../version.c:4044
#: ../version.c:4046
msgid ""
"\n"
"MS-Windows 64-bit GUI/console version"
msgstr ""
#: ../version.c:4047
#: ../version.c:4049
msgid ""
"\n"
"MS-Windows 32-bit GUI/console version"
msgstr ""
#: ../version.c:4052
#: ../version.c:4054
msgid ""
"\n"
"MS-Windows ARM64 GUI version"
msgstr ""
#: ../version.c:4054
#: ../version.c:4056
msgid ""
"\n"
"MS-Windows 64-bit GUI version"
msgstr ""
#: ../version.c:4057
#: ../version.c:4059
msgid ""
"\n"
"MS-Windows 32-bit GUI version"
msgstr ""
#: ../version.c:4061
#: ../version.c:4063
msgid " with OLE support"
msgstr ""
#: ../version.c:4066
msgid ""
"\n"
"MS-Windows ARM64 console version"
msgstr ""
#: ../version.c:4068
msgid ""
"\n"
"MS-Windows ARM64 console version"
msgstr ""
#: ../version.c:4070
msgid ""
"\n"
"MS-Windows 64-bit console version"
msgstr ""
#: ../version.c:4071
#: ../version.c:4073
msgid ""
"\n"
"MS-Windows 32-bit console version"
msgstr ""
#: ../version.c:4077
#: ../version.c:4079
msgid ""
"\n"
"macOS version"
msgstr ""
#: ../version.c:4079
#: ../version.c:4081
msgid ""
"\n"
"macOS version w/o darwin feat."
msgstr ""
#: ../version.c:4089
#: ../version.c:4091
msgid ""
"\n"
"OpenVMS version"
msgstr ""
#: ../version.c:4104
#: ../version.c:4106
msgid ""
"\n"
"Included patches: "
msgstr ""
#: ../version.c:4129
#: ../version.c:4131
msgid ""
"\n"
"Extra patches: "
msgstr ""
#: ../version.c:4141 ../version.c:4452
#: ../version.c:4143 ../version.c:4454
msgid "Modified by "
msgstr ""
#: ../version.c:4148
#: ../version.c:4150
msgid ""
"\n"
"Compiled "
msgstr ""
#: ../version.c:4151
#: ../version.c:4153
msgid "by "
msgstr ""
#: ../version.c:4163
msgid ""
"\n"
"Huge version "
msgstr ""
#: ../version.c:4165
msgid ""
"\n"
"Normal version "
"Huge version "
msgstr ""
#: ../version.c:4167
msgid ""
"\n"
"Normal version "
msgstr ""
#: ../version.c:4169
msgid ""
"\n"
"Tiny version "
msgstr ""
#: ../version.c:4170
#: ../version.c:4172
msgid "without GUI."
msgstr ""
#: ../version.c:4173
#: ../version.c:4175
msgid "with GTK3 GUI."
msgstr ""
#: ../version.c:4175
#: ../version.c:4177
msgid "with GTK2-GNOME GUI."
msgstr ""
#: ../version.c:4177
#: ../version.c:4179
msgid "with GTK2 GUI."
msgstr ""
#: ../version.c:4180
#: ../version.c:4182
msgid "with X11-Motif GUI."
msgstr ""
#: ../version.c:4182
#: ../version.c:4184
msgid "with Haiku GUI."
msgstr ""
#: ../version.c:4184
#: ../version.c:4186
msgid "with Photon GUI."
msgstr ""
#: ../version.c:4186
#: ../version.c:4188
msgid "with GUI."
msgstr ""
#: ../version.c:4188
#: ../version.c:4190
msgid " Features included (+) or not (-):\n"
msgstr ""
#: ../version.c:4195
#: ../version.c:4197
msgid " system vimrc file: \""
msgstr ""
#: ../version.c:4200
#: ../version.c:4202
msgid " user vimrc file: \""
msgstr ""
#: ../version.c:4205
#: ../version.c:4207
msgid " 2nd user vimrc file: \""
msgstr ""
#: ../version.c:4210 ../version.c:4217 ../version.c:4221
#: ../version.c:4212 ../version.c:4219 ../version.c:4223
msgid " 3rd user vimrc file: \""
msgstr ""
#: ../version.c:4213
#: ../version.c:4215
msgid " 4th user vimrc file: \""
msgstr ""
#: ../version.c:4226
#: ../version.c:4228
msgid " user exrc file: \""
msgstr ""
#: ../version.c:4231
#: ../version.c:4233
msgid " 2nd user exrc file: \""
msgstr ""
#: ../version.c:4237
#: ../version.c:4239
msgid " system gvimrc file: \""
msgstr ""
#: ../version.c:4241
#: ../version.c:4243
msgid " user gvimrc file: \""
msgstr ""
#: ../version.c:4245
#: ../version.c:4247
msgid "2nd user gvimrc file: \""
msgstr ""
#: ../version.c:4250
#: ../version.c:4252
msgid "3rd user gvimrc file: \""
msgstr ""
#: ../version.c:4255
#: ../version.c:4257
msgid " defaults file: \""
msgstr ""
#: ../version.c:4260
#: ../version.c:4262
msgid " system menu file: \""
msgstr ""
#: ../version.c:4268
#: ../version.c:4270
msgid " fall-back for $VIM: \""
msgstr ""
#: ../version.c:4274
#: ../version.c:4276
msgid " f-b for $VIMRUNTIME: \""
msgstr ""
#: ../version.c:4278
#: ../version.c:4280
msgid "Compilation: "
msgstr ""
#: ../version.c:4284
#: ../version.c:4286
msgid "Compiler: "
msgstr ""
#: ../version.c:4289
#: ../version.c:4291
msgid "Linking: "
msgstr ""
#: ../version.c:4294
#: ../version.c:4296
msgid " DEBUG BUILD"
msgstr ""
#: ../version.c:4330
#: ../version.c:4332
msgid "VIM - Vi IMproved"
msgstr ""
#: ../version.c:4332
#: ../version.c:4334
msgid "version "
msgstr ""
#: ../version.c:4333
#: ../version.c:4335
msgid "by Bram Moolenaar et al."
msgstr ""
#: ../version.c:4337
#: ../version.c:4339
msgid "Vim is open source and freely distributable"
msgstr ""
#: ../version.c:4339
#: ../version.c:4341
msgid "Help poor children in Uganda!"
msgstr ""
#: ../version.c:4340
#: ../version.c:4342
msgid "type :help iccf<Enter> for information "
msgstr ""
#: ../version.c:4342
#: ../version.c:4344
msgid "type :q<Enter> to exit "
msgstr ""
#: ../version.c:4343
#: ../version.c:4345
msgid "type :help<Enter> or <F1> for on-line help"
msgstr ""
#: ../version.c:4344
#: ../version.c:4346
msgid "type :help version9<Enter> for version info"
msgstr ""
#: ../version.c:4347
#: ../version.c:4349
msgid "Running in Vi compatible mode"
msgstr ""
#: ../version.c:4348
#: ../version.c:4350
msgid "type :set nocp<Enter> for Vim defaults"
msgstr ""
#: ../version.c:4349
#: ../version.c:4351
msgid "type :help cp-default<Enter> for info on this"
msgstr ""
#: ../version.c:4364
#: ../version.c:4366
msgid "menu Help->Orphans for information "
msgstr ""
#: ../version.c:4366
#: ../version.c:4368
msgid "Running modeless, typed text is inserted"
msgstr ""
#: ../version.c:4367
#: ../version.c:4369
msgid "menu Edit->Global Settings->Toggle Insert Mode "
msgstr ""
#: ../version.c:4368
#: ../version.c:4370
msgid " for two modes "
msgstr ""
#: ../version.c:4372
#: ../version.c:4374
msgid "menu Edit->Global Settings->Toggle Vi Compatible"
msgstr ""
#: ../version.c:4373
#: ../version.c:4375
msgid " for Vim defaults "
msgstr ""
#: ../version.c:4414
#: ../version.c:4416
msgid "Sponsor Vim development!"
msgstr ""
#: ../version.c:4415
#: ../version.c:4417
msgid "Become a registered Vim user!"
msgstr ""
#: ../version.c:4418
#: ../version.c:4420
msgid "type :help sponsor<Enter> for information "
msgstr ""
#: ../version.c:4419
#: ../version.c:4421
msgid "type :help register<Enter> for information "
msgstr ""
#: ../version.c:4421
#: ../version.c:4423
msgid "menu Help->Sponsor/Register for information "
msgstr ""

View File

@ -719,6 +719,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1555,
/**/
1554,
/**/