Skip to content

Commit 0208b3e

Browse files
girishjichrisbra
authored andcommitted
patch 9.1.1779: completion: 'autocomplete' cannot be enabled per buffer
Problem: completion: 'autocomplete' cannot be enabled per buffer (Tomasz N) Solution: Make 'autocomplete' global or local to buffer (Girish Palya) fixes: #18320 closes: #18333 Signed-off-by: Girish Palya <girishji@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 2f3b7ea commit 0208b3e

File tree

12 files changed

+41
-14
lines changed

12 files changed

+41
-14
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: 2025 Sep 15
1+
*options.txt* For Vim version 9.1. Last change: 2025 Sep 20
22

33

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

914914
*'autocomplete'* *'ac'* *'noautocomplete'* *'noac'*
915915
'autocomplete' 'ac' boolean (default off)
916-
global
916+
global or local to buffer |global-local|
917917
{only available on platforms with timing support}
918918
When on, Vim shows a completion menu as you type, similar to using
919919
|i_CTRL-N|, but triggered automatically. See |ins-autocompletion|.

runtime/optwin.vim

Lines changed: 2 additions & 1 deletion
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: 2025 Sep 02
4+
" Last Change: 2025 Sep 20
55
" Former Maintainer: Bram Moolenaar <Bram@vim.org>
66

77
" If there already is an option window, jump to that one.
@@ -876,6 +876,7 @@ if has("insert_expand")
876876
call append("$", "\t" .. s:local_to_buffer)
877877
call <SID>OptionL("cpt")
878878
call <SID>AddOption("autocomplete", gettext("automatic completion in insert mode"))
879+
call append("$", "\t" .. s:global_or_local)
879880
call <SID>BinOptionG("ac", &ac)
880881
call <SID>AddOption("autocompletetimeout", gettext("initial decay timeout for 'autocomplete' algorithm"))
881882
call append("$", " \tset act=" . &act)

src/buffer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2534,6 +2534,7 @@ free_buf_options(
25342534
#endif
25352535
clear_string_option(&buf->b_p_tsr);
25362536
clear_string_option(&buf->b_p_qe);
2537+
buf->b_p_ac = -1;
25372538
buf->b_p_ar = -1;
25382539
buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
25392540
clear_string_option(&buf->b_p_lw);

src/edit.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ edit(
694694
{
695695
ins_compl_delete();
696696
if (ins_compl_has_preinsert()
697-
&& ins_compl_has_autocomplete())
697+
&& ins_compl_autocomplete_enabled())
698698
(void)ins_compl_insert(FALSE, TRUE);
699699
else
700700
(void)ins_compl_insert(FALSE, FALSE);
@@ -987,7 +987,7 @@ edit(
987987
case Ctrl_H:
988988
did_backspace = ins_bs(c, BACKSPACE_CHAR, &inserted_space);
989989
auto_format(FALSE, TRUE);
990-
if (did_backspace && p_ac && !char_avail()
990+
if (did_backspace && ins_compl_has_autocomplete() && !char_avail()
991991
&& curwin->w_cursor.col > 0)
992992
{
993993
c = char_before_cursor();
@@ -1418,7 +1418,8 @@ edit(
14181418
foldOpenCursor();
14191419
#endif
14201420
// Trigger autocompletion
1421-
if (p_ac && !char_avail() && vim_isprintc(c))
1421+
if (ins_compl_has_autocomplete() && !char_avail()
1422+
&& vim_isprintc(c))
14221423
{
14231424
update_screen(UPD_VALID); // Show character immediately
14241425
out_flush();

src/insexpand.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2375,7 +2375,7 @@ ins_compl_preinsert_effect(void)
23752375
* Returns TRUE if autocompletion is active.
23762376
*/
23772377
int
2378-
ins_compl_has_autocomplete(void)
2378+
ins_compl_autocomplete_enabled(void)
23792379
{
23802380
return compl_autocomplete;
23812381
}
@@ -2449,6 +2449,16 @@ ins_compl_need_restart(void)
24492449
&& compl_opt_refresh_always);
24502450
}
24512451

2452+
/*
2453+
* Return TRUE if 'autocomplete' option is set
2454+
*/
2455+
int
2456+
ins_compl_has_autocomplete(void)
2457+
{
2458+
// Use buffer-local setting if defined (>= 0), otherwise use global
2459+
return curbuf->b_p_ac >= 0 ? curbuf->b_p_ac : p_ac;
2460+
}
2461+
24522462
/*
24532463
* Called after changing "compl_leader".
24542464
* Show the popup menu with a different set of matches.
@@ -2498,8 +2508,7 @@ ins_compl_new_leader(void)
24982508
save_w_wrow = curwin->w_wrow;
24992509
save_w_leftcol = curwin->w_leftcol;
25002510
compl_restarting = TRUE;
2501-
if (p_ac)
2502-
compl_autocomplete = TRUE;
2511+
compl_autocomplete = ins_compl_has_autocomplete();
25032512
if (ins_complete(Ctrl_N, FALSE) == FAIL)
25042513
compl_cont_status = 0;
25052514
compl_restarting = FALSE;

src/option.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ set_init_1(int clean_arg)
695695
#endif
696696

697697
curbuf->b_p_initialized = TRUE;
698+
curbuf->b_p_ac = -1;
698699
curbuf->b_p_ar = -1; // no local 'autoread' value
699700
curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
700701
check_buf_options(curbuf);
@@ -2207,6 +2208,8 @@ do_set_option_bool(
22072208
// For 'autoread' -1 means to use global value.
22082209
if ((int *)varp == &curbuf->b_p_ar && opt_flags == OPT_LOCAL)
22092210
value = -1;
2211+
else if ((int *)varp == &curbuf->b_p_ac && opt_flags == OPT_LOCAL)
2212+
value = -1;
22102213
else
22112214
value = *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
22122215
}
@@ -6441,6 +6444,9 @@ unset_global_local_option(char_u *name, void *from)
64416444
case PV_PATH:
64426445
clear_string_option(&buf->b_p_path);
64436446
break;
6447+
case PV_AC:
6448+
buf->b_p_ac = -1;
6449+
break;
64446450
case PV_AR:
64456451
buf->b_p_ar = -1;
64466452
break;
@@ -6593,6 +6599,7 @@ get_varp_scope(struct vimoption *p, int scope)
65936599
case PV_EP: return (char_u *)&(curbuf->b_p_ep);
65946600
case PV_KP: return (char_u *)&(curbuf->b_p_kp);
65956601
case PV_PATH: return (char_u *)&(curbuf->b_p_path);
6602+
case PV_AC: return (char_u *)&(curbuf->b_p_ac);
65966603
case PV_AR: return (char_u *)&(curbuf->b_p_ar);
65976604
case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
65986605
case PV_TC: return (char_u *)&(curbuf->b_p_tc);
@@ -6669,6 +6676,8 @@ get_varp(struct vimoption *p)
66696676
? (char_u *)&curbuf->b_p_kp : p->var;
66706677
case PV_PATH: return *curbuf->b_p_path != NUL
66716678
? (char_u *)&(curbuf->b_p_path) : p->var;
6679+
case PV_AC: return curbuf->b_p_ac >= 0
6680+
? (char_u *)&(curbuf->b_p_ac) : p->var;
66726681
case PV_AR: return curbuf->b_p_ar >= 0
66736682
? (char_u *)&(curbuf->b_p_ar) : p->var;
66746683
case PV_TAGS: return *curbuf->b_p_tags != NUL
@@ -7501,6 +7510,7 @@ buf_copy_options(buf_T *buf, int flags)
75017510

75027511
// options that are normally global but also have a local value
75037512
// are not copied, start using the global value
7513+
buf->b_p_ac = -1;
75047514
buf->b_p_ar = -1;
75057515
buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
75067516
buf->b_p_bkc = empty_option;

src/option.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,7 @@ EXTERN int p_xtermcodes; // 'xtermcodes'
11681168
enum
11691169
{
11701170
BV_AI = 0
1171+
, BV_AC
11711172
, BV_AR
11721173
, BV_BH
11731174
, BV_BKC

src/optiondefs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
// Definition of the PV_ values for buffer-local options.
2828
// The BV_ values are defined in option.h.
29+
#define PV_AC OPT_BOTH(OPT_BUF(BV_AC))
2930
#define PV_AI OPT_BUF(BV_AI)
3031
#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
3132
#define PV_BKC OPT_BOTH(OPT_BUF(BV_BKC))
@@ -390,7 +391,7 @@ static struct vimoption options[] =
390391
SCTX_INIT},
391392
#ifdef ELAPSED_FUNC
392393
{"autocomplete", "ac", P_BOOL|P_VI_DEF,
393-
(char_u *)&p_ac, PV_NONE, NULL,
394+
(char_u *)&p_ac, PV_AC, NULL,
394395
NULL, {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
395396
{"autocompletedelay", "acl", P_NUM|P_VI_DEF,
396397
(char_u *)&p_acl, PV_NONE, NULL, NULL,

src/proto/insexpand.pro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ colnr_T ins_compl_col(void);
4949
int ins_compl_len(void);
5050
int ins_compl_has_preinsert(void);
5151
int ins_compl_preinsert_effect(void);
52-
int ins_compl_has_autocomplete(void);
52+
int ins_compl_autocomplete_enabled(void);
5353
int ins_compl_bs(void);
5454
void ins_compl_addleader(int c);
5555
void ins_compl_addfrommatch(void);
@@ -76,4 +76,5 @@ void ins_compl_check_keys(int frequency, int in_compl_func);
7676
int ins_complete(int c, int enable_pum);
7777
void ins_compl_enable_autocomplete(void);
7878
void free_insexpand_stuff(void);
79+
int ins_compl_has_autocomplete(void);
7980
/* vim: set ft=c : */

src/structs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3285,6 +3285,7 @@ struct file_buffer
32853285
sctx_T b_p_script_ctx[BV_COUNT]; // SCTXs for buffer-local options
32863286
#endif
32873287

3288+
int b_p_ac; // 'autocomplete'
32883289
int b_p_ai; // 'autoindent'
32893290
int b_p_ai_nopaste; // b_p_ai saved for paste mode
32903291
char_u *b_p_bkc; // 'backupcopy'

0 commit comments

Comments
 (0)