Skip to content

Commit 529b9ad

Browse files
zeertzjqchrisbra
authored andcommitted
patch 9.1.0469: Cannot have buffer-local value for 'completeopt'
Problem: Cannot have buffer-local value for 'completeopt' (Nick Jensen). Solution: Make 'completeopt' global-local (zeertzjq). Also for some reason test Test_ColonEight_MultiByte seems to be failing sporadically now. Let's mark it as flaky. fixes: #5487 closes: #14922 Signed-off-by: zeertzjq <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 84d9611 commit 529b9ad

File tree

14 files changed

+146
-41
lines changed

14 files changed

+146
-41
lines changed

runtime/doc/options.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*options.txt* For Vim version 9.1. Last change: 2024 Jun 04
1+
*options.txt* For Vim version 9.1. Last change: 2024 Jun 05
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -2101,7 +2101,7 @@ A jump table for the options with a short description can be found at |Q_op|.
21012101

21022102
*'completeopt'* *'cot'*
21032103
'completeopt' 'cot' string (default: "menu,preview")
2104-
global
2104+
global or local to buffer |global-local|
21052105
A comma-separated list of options for Insert mode completion
21062106
|ins-completion|. The supported values are:
21072107

runtime/doc/version9.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*version9.txt* For Vim version 9.1. Last change: 2024 Jun 03
1+
*version9.txt* For Vim version 9.1. Last change: 2024 Jun 05
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -41567,6 +41567,7 @@ Changed~
4156741567
- use 'smoothscroll' logic for CTRL-D and CTRL-U for half-pagewise scrolling
4156841568
- the default for 'commentstring' contains whitespace padding to have
4156941569
automatic comments look nicer |comment-install|
41570+
- 'completeopt' is now a |global-local| option.
4157041571

4157141572
*added-9.2*
4157241573
Added ~

runtime/optwin.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
" These commands create the option window.
22
"
33
" Maintainer: The Vim Project <https://github.com/vim/vim>
4-
" Last Change: 2023 Aug 31
4+
" Last Change: 2024 Jun 05
55
" Former Maintainer: Bram Moolenaar <[email protected]>
66

77
" If there already is an option window, jump to that one.
@@ -846,7 +846,7 @@ if has("insert_expand")
846846
call append("$", "\t" .. s:local_to_buffer)
847847
call <SID>OptionL("cpt")
848848
call <SID>AddOption("completeopt", gettext("whether to use a popup menu for Insert mode completion"))
849-
call <SID>OptionG("cot", &cot)
849+
call <SID>OptionL("cot")
850850
if exists("+completepopup")
851851
call <SID>AddOption("completepopup", gettext("options for the Insert mode completion info popup"))
852852
call <SID>OptionG("cpp", &cpp)

src/buffer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2429,6 +2429,7 @@ free_buf_options(
24292429
clear_string_option(&buf->b_p_lop);
24302430
clear_string_option(&buf->b_p_cinsd);
24312431
clear_string_option(&buf->b_p_cinw);
2432+
clear_string_option(&buf->b_p_cot);
24322433
clear_string_option(&buf->b_p_cpt);
24332434
#ifdef FEAT_COMPL_FUNC
24342435
clear_string_option(&buf->b_p_cfu);

src/insexpand.c

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,6 @@ static char_u *compl_leader = NULL;
148148
static int compl_get_longest = FALSE; // put longest common string
149149
// in compl_leader
150150

151-
static int compl_no_insert = FALSE; // FALSE: select & insert
152-
// TRUE: noinsert
153-
static int compl_no_select = FALSE; // FALSE: select & insert
154-
// TRUE: noselect
155-
static int compl_longest = FALSE; // FALSE: insert full match
156-
// TRUE: insert longest prefix
157-
static int compl_fuzzy_match = FALSE; // True: fuzzy match enabled
158-
159151
// Selected one of the matches. When FALSE the match was edited or using the
160152
// longest common string.
161153
static int compl_used_match;
@@ -1054,24 +1046,12 @@ ins_compl_long_shown_match(void)
10541046
}
10551047

10561048
/*
1057-
* Set variables that store noselect and noinsert behavior from the
1058-
* 'completeopt' value.
1049+
* Get the local or global value of 'completeopt' flags.
10591050
*/
1060-
void
1061-
completeopt_was_set(void)
1051+
unsigned int
1052+
get_cot_flags(void)
10621053
{
1063-
compl_no_insert = FALSE;
1064-
compl_no_select = FALSE;
1065-
compl_longest = FALSE;
1066-
compl_fuzzy_match = FALSE;
1067-
if (strstr((char *)p_cot, "noselect") != NULL)
1068-
compl_no_select = TRUE;
1069-
if (strstr((char *)p_cot, "noinsert") != NULL)
1070-
compl_no_insert = TRUE;
1071-
if (strstr((char *)p_cot, "longest") != NULL)
1072-
compl_longest = TRUE;
1073-
if (strstr((char *)p_cot, "fuzzy") != NULL)
1074-
compl_fuzzy_match = TRUE;
1054+
return curbuf->b_cot_flags != 0 ? curbuf->b_cot_flags : cot_flags;
10751055
}
10761056

10771057

@@ -1118,7 +1098,7 @@ ins_compl_del_pum(void)
11181098
pum_wanted(void)
11191099
{
11201100
// 'completeopt' must contain "menu" or "menuone"
1121-
if (vim_strchr(p_cot, 'm') == NULL)
1101+
if ((get_cot_flags() & COT_ANY_MENU) == 0)
11221102
return FALSE;
11231103

11241104
// The display looks bad on a B&W display.
@@ -1152,7 +1132,7 @@ pum_enough_matches(void)
11521132
compl = compl->cp_next;
11531133
} while (!is_first_match(compl));
11541134

1155-
if (strstr((char *)p_cot, "menuone") != NULL)
1135+
if (get_cot_flags() & COT_MENUONE)
11561136
return (i >= 1);
11571137
return (i >= 2);
11581138
}
@@ -1246,6 +1226,9 @@ ins_compl_build_pum(void)
12461226
int cur = -1;
12471227
int lead_len = 0;
12481228
int max_fuzzy_score = 0;
1229+
int cur_cot_flags = get_cot_flags();
1230+
int compl_no_select = (cur_cot_flags & COT_NOSELECT) != 0;
1231+
int compl_fuzzy_match = (cur_cot_flags & COT_FUZZY) != 0;
12491232

12501233
// Need to build the popup menu list.
12511234
compl_match_arraysize = 0;
@@ -2469,9 +2452,8 @@ ins_compl_prep(int c)
24692452
if (ctrl_x_mode_not_defined_yet()
24702453
|| (ctrl_x_mode_normal() && !compl_started))
24712454
{
2472-
compl_get_longest = compl_longest;
2455+
compl_get_longest = (get_cot_flags() & COT_LONGEST) != 0;
24732456
compl_used_match = TRUE;
2474-
24752457
}
24762458

24772459
if (ctrl_x_mode_not_defined_yet())
@@ -2943,6 +2925,10 @@ set_completion(colnr_T startcol, list_T *list)
29432925
int save_w_wrow = curwin->w_wrow;
29442926
int save_w_leftcol = curwin->w_leftcol;
29452927
int flags = CP_ORIGINAL_TEXT;
2928+
int cur_cot_flags = get_cot_flags();
2929+
int compl_longest = (cur_cot_flags & COT_LONGEST) != 0;
2930+
int compl_no_insert = (cur_cot_flags & COT_NOINSERT) != 0;
2931+
int compl_no_select = (cur_cot_flags & COT_NOSELECT) != 0;
29462932

29472933
// If already doing completions stop it.
29482934
if (ctrl_x_mode_not_default())
@@ -4140,6 +4126,9 @@ find_next_completion_match(
41404126
{
41414127
int found_end = FALSE;
41424128
compl_T *found_compl = NULL;
4129+
int cur_cot_flags = get_cot_flags();
4130+
int compl_no_select = (cur_cot_flags & COT_NOSELECT) != 0;
4131+
int compl_fuzzy_match = (cur_cot_flags & COT_FUZZY) != 0;
41434132

41444133
while (--todo >= 0)
41454134
{
@@ -4257,6 +4246,9 @@ ins_compl_next(
42574246
int advance;
42584247
int started = compl_started;
42594248
buf_T *orig_curbuf = curbuf;
4249+
int cur_cot_flags = get_cot_flags();
4250+
int compl_no_insert = (cur_cot_flags & COT_NOINSERT) != 0;
4251+
int compl_fuzzy_match = (cur_cot_flags & COT_FUZZY) != 0;
42604252

42614253
// When user complete function return -1 for findstart which is next
42624254
// time of 'always', compl_shown_match become NULL.
@@ -4411,7 +4403,7 @@ ins_compl_check_keys(int frequency, int in_compl_func)
44114403
}
44124404
}
44134405
}
4414-
if (compl_pending != 0 && !got_int && !compl_no_insert)
4406+
if (compl_pending != 0 && !got_int && !(cot_flags & COT_NOINSERT))
44154407
{
44164408
int todo = compl_pending > 0 ? compl_pending : -compl_pending;
44174409

src/option.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6224,6 +6224,10 @@ unset_global_local_option(char_u *name, void *from)
62246224
clear_string_option(&buf->b_p_inc);
62256225
break;
62266226
# endif
6227+
case PV_COT:
6228+
clear_string_option(&buf->b_p_cot);
6229+
buf->b_cot_flags = 0;
6230+
break;
62276231
case PV_DICT:
62286232
clear_string_option(&buf->b_p_dict);
62296233
break;
@@ -6333,6 +6337,7 @@ get_varp_scope(struct vimoption *p, int scope)
63336337
case PV_DEF: return (char_u *)&(curbuf->b_p_def);
63346338
case PV_INC: return (char_u *)&(curbuf->b_p_inc);
63356339
#endif
6340+
case PV_COT: return (char_u *)&(curbuf->b_p_cot);
63366341
case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
63376342
case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
63386343
#ifdef FEAT_COMPL_FUNC
@@ -6413,6 +6418,8 @@ get_varp(struct vimoption *p)
64136418
case PV_INC: return *curbuf->b_p_inc != NUL
64146419
? (char_u *)&(curbuf->b_p_inc) : p->var;
64156420
#endif
6421+
case PV_COT: return *curbuf->b_p_cot != NUL
6422+
? (char_u *)&(curbuf->b_p_cot) : p->var;
64166423
case PV_DICT: return *curbuf->b_p_dict != NUL
64176424
? (char_u *)&(curbuf->b_p_dict) : p->var;
64186425
case PV_TSR: return *curbuf->b_p_tsr != NUL
@@ -7205,6 +7212,8 @@ buf_copy_options(buf_T *buf, int flags)
72057212
COPY_OPT_SCTX(buf, BV_INEX);
72067213
# endif
72077214
#endif
7215+
buf->b_p_cot = empty_option;
7216+
buf->b_cot_flags = 0;
72087217
buf->b_p_dict = empty_option;
72097218
buf->b_p_tsr = empty_option;
72107219
#ifdef FEAT_COMPL_FUNC

src/option.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,20 @@ EXTERN int p_confirm; // 'confirm'
513513
#endif
514514
EXTERN int p_cp; // 'compatible'
515515
EXTERN char_u *p_cot; // 'completeopt'
516+
EXTERN unsigned cot_flags; // flags from 'completeopt'
517+
// Keep in sync with p_cot_values in optionstr.c
518+
#define COT_MENU 0x001
519+
#define COT_MENUONE 0x002
520+
#define COT_ANY_MENU 0x003 // combination of menu flags
521+
#define COT_LONGEST 0x004 // FALSE: insert full match,
522+
// TRUE: insert longest prefix
523+
#define COT_PREVIEW 0x008
524+
#define COT_POPUP 0x010
525+
#define COT_POPUPHIDDEN 0x020
526+
#define COT_ANY_PREVIEW 0x038 // combination of preview flags
527+
#define COT_NOINSERT 0x040 // FALSE: select & insert, TRUE: noinsert
528+
#define COT_NOSELECT 0x080 // FALSE: select & insert, TRUE: noselect
529+
#define COT_FUZZY 0x100 // TRUE: fuzzy match enabled
516530
#ifdef BACKSLASH_IN_FILENAME
517531
EXTERN char_u *p_csl; // 'completeslash'
518532
#endif
@@ -1127,6 +1141,7 @@ enum
11271141
, BV_CMS
11281142
#endif
11291143
, BV_COM
1144+
, BV_COT
11301145
, BV_CPT
11311146
, BV_DICT
11321147
, BV_TSR

src/optiondefs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
# define PV_CMS OPT_BUF(BV_CMS)
5151
#endif
5252
#define PV_COM OPT_BUF(BV_COM)
53+
#define PV_COT OPT_BOTH(OPT_BUF(BV_COT))
5354
#define PV_CPT OPT_BUF(BV_CPT)
5455
#define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
5556
#define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
@@ -654,7 +655,7 @@ static struct vimoption options[] =
654655
#endif
655656
SCTX_INIT},
656657
{"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
657-
(char_u *)&p_cot, PV_NONE, did_set_completeopt, expand_set_completeopt,
658+
(char_u *)&p_cot, PV_COT, did_set_completeopt, expand_set_completeopt,
658659
{(char_u *)"menu,preview", (char_u *)0L}
659660
SCTX_INIT},
660661
{"completepopup", "cpp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_COLON,

src/optionstr.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ didset_string_options(void)
144144
(void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
145145
(void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
146146
(void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
147+
(void)opt_strings_flags(p_cot, p_cot_values, &cot_flags, TRUE);
147148
#ifdef FEAT_SESSION
148149
(void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
149150
(void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
@@ -301,6 +302,7 @@ check_buf_options(buf_T *buf)
301302
check_string_option(&buf->b_p_lop);
302303
check_string_option(&buf->b_p_ft);
303304
check_string_option(&buf->b_p_cinw);
305+
check_string_option(&buf->b_p_cot);
304306
check_string_option(&buf->b_p_cpt);
305307
#ifdef FEAT_COMPL_FUNC
306308
check_string_option(&buf->b_p_cfu);
@@ -1601,10 +1603,21 @@ expand_set_complete(optexpand_T *args, int *numMatches, char_u ***matches)
16011603
char *
16021604
did_set_completeopt(optset_T *args UNUSED)
16031605
{
1604-
if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
1606+
char_u *cot = p_cot;
1607+
unsigned *flags = &cot_flags;
1608+
1609+
if (args->os_flags & OPT_LOCAL)
1610+
{
1611+
cot = curbuf->b_p_cot;
1612+
flags = &curbuf->b_cot_flags;
1613+
}
1614+
1615+
if (check_opt_strings(cot, p_cot_values, TRUE) != OK)
1616+
return e_invalid_argument;
1617+
1618+
if (opt_strings_flags(cot, p_cot_values, flags, TRUE) != OK)
16051619
return e_invalid_argument;
16061620

1607-
completeopt_was_set();
16081621
return NULL;
16091622
}
16101623

src/popupmenu.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,7 @@ pum_set_selected(int n, int repeat UNUSED)
760760
int context = pum_height / 2;
761761
#ifdef FEAT_QUICKFIX
762762
int prev_selected = pum_selected;
763+
unsigned cur_cot_flags = get_cot_flags();
763764
#endif
764765
#if defined(FEAT_PROP_POPUP) && defined(FEAT_QUICKFIX)
765766
int has_info = FALSE;
@@ -831,7 +832,7 @@ pum_set_selected(int n, int repeat UNUSED)
831832
if (pum_array[pum_selected].pum_info != NULL
832833
&& Rows > 10
833834
&& repeat <= 1
834-
&& vim_strchr(p_cot, 'p') != NULL)
835+
&& (cur_cot_flags & COT_ANY_PREVIEW))
835836
{
836837
win_T *curwin_save = curwin;
837838
tabpage_T *curtab_save = curtab;
@@ -842,9 +843,9 @@ pum_set_selected(int n, int repeat UNUSED)
842843
# endif
843844
# ifdef FEAT_PROP_POPUP
844845
has_info = TRUE;
845-
if (strstr((char *)p_cot, "popuphidden") != NULL)
846+
if (cur_cot_flags & COT_POPUPHIDDEN)
846847
use_popup = USEPOPUP_HIDDEN;
847-
else if (strstr((char *)p_cot, "popup") != NULL)
848+
else if (cur_cot_flags & COT_POPUP)
848849
use_popup = USEPOPUP_NORMAL;
849850
else
850851
use_popup = USEPOPUP_NONE;

0 commit comments

Comments
 (0)