]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1779: completion: 'autocomplete' cannot be enabled per buffer v9.1.1779
authorGirish Palya <girishji@gmail.com>
Sat, 20 Sep 2025 14:54:27 +0000 (14:54 +0000)
committerChristian Brabandt <cb@256bit.org>
Sat, 20 Sep 2025 14:54:27 +0000 (14:54 +0000)
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>
12 files changed:
runtime/doc/options.txt
runtime/optwin.vim
src/buffer.c
src/edit.c
src/insexpand.c
src/option.c
src/option.h
src/optiondefs.h
src/proto/insexpand.pro
src/structs.h
src/testdir/test_ins_complete.vim
src/version.c

index 9643dd86add63429a389b62b148c92f045eff22c..7dad0c4ae3473426bcbd6a2352c8be1f7630d5ab 100644 (file)
@@ -1,4 +1,4 @@
-*options.txt*  For Vim version 9.1.  Last change: 2025 Sep 15
+*options.txt*  For Vim version 9.1.  Last change: 2025 Sep 20
 
 
                  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|.
 
                        *'autocomplete'* *'ac'* *'noautocomplete'* *'noac'*
 'autocomplete' 'ac'    boolean (default off)
-                       global
+                       global or local to buffer |global-local|
                        {only available on platforms with timing support}
        When on, Vim shows a completion menu as you type, similar to using
        |i_CTRL-N|, but triggered automatically.  See |ins-autocompletion|.
index cf743aa7a7a7dfca190e639855e8104341d38ece..5b5727aa676b592a86c03d3136a6a431d912577b 100644 (file)
@@ -1,7 +1,7 @@
 " These commands create the option window.
 "
 " Maintainer:  The Vim Project <https://github.com/vim/vim>
-" Last Change: 2025 Sep 02
+" Last Change: 2025 Sep 20
 " Former Maintainer:   Bram Moolenaar <Bram@vim.org>
 
 " If there already is an option window, jump to that one.
@@ -876,6 +876,7 @@ if has("insert_expand")
   call append("$", "\t" .. s:local_to_buffer)
   call <SID>OptionL("cpt")
   call <SID>AddOption("autocomplete", gettext("automatic completion in insert mode"))
+  call append("$", "\t" .. s:global_or_local)
   call <SID>BinOptionG("ac", &ac)
   call <SID>AddOption("autocompletetimeout", gettext("initial decay timeout for 'autocomplete' algorithm"))
   call append("$", " \tset act=" . &act)
index 0feafc590d52f1ab0071ed42e3216df070948394..29908c4aa8dd09db61d2268e1c46acd676cc4ff0 100644 (file)
@@ -2534,6 +2534,7 @@ free_buf_options(
 #endif
     clear_string_option(&buf->b_p_tsr);
     clear_string_option(&buf->b_p_qe);
+    buf->b_p_ac = -1;
     buf->b_p_ar = -1;
     buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
     clear_string_option(&buf->b_p_lw);
index 41e1c00703da2dfea56b060210b5409d242c5380..400d047b8c211f3e3ac6e4189e6400e22a89c37f 100644 (file)
@@ -694,7 +694,7 @@ edit(
                {
                    ins_compl_delete();
                    if (ins_compl_has_preinsert()
-                           && ins_compl_has_autocomplete())
+                           && ins_compl_autocomplete_enabled())
                        (void)ins_compl_insert(FALSE, TRUE);
                    else
                        (void)ins_compl_insert(FALSE, FALSE);
@@ -987,7 +987,7 @@ doESCkey:
        case Ctrl_H:
            did_backspace = ins_bs(c, BACKSPACE_CHAR, &inserted_space);
            auto_format(FALSE, TRUE);
-           if (did_backspace && p_ac && !char_avail()
+           if (did_backspace && ins_compl_has_autocomplete() && !char_avail()
                    && curwin->w_cursor.col > 0)
            {
                c = char_before_cursor();
@@ -1418,7 +1418,8 @@ normalchar:
            foldOpenCursor();
 #endif
            // Trigger autocompletion
-           if (p_ac && !char_avail() && vim_isprintc(c))
+           if (ins_compl_has_autocomplete() && !char_avail()
+                   && vim_isprintc(c))
            {
                update_screen(UPD_VALID); // Show character immediately
                out_flush();
index 0beea079d4245a12540e30060ad3bbde678643e5..bb814af708d1d45266c708669c34abc3fec7cd5b 100644 (file)
@@ -2375,7 +2375,7 @@ ins_compl_preinsert_effect(void)
  * Returns TRUE if autocompletion is active.
  */
     int
-ins_compl_has_autocomplete(void)
+ins_compl_autocomplete_enabled(void)
 {
     return compl_autocomplete;
 }
@@ -2449,6 +2449,16 @@ ins_compl_need_restart(void)
                                                  && compl_opt_refresh_always);
 }
 
+/*
+ * Return TRUE if 'autocomplete' option is set
+ */
+    int
+ins_compl_has_autocomplete(void)
+{
+    // Use buffer-local setting if defined (>= 0), otherwise use global
+    return curbuf->b_p_ac >= 0 ? curbuf->b_p_ac : p_ac;
+}
+
 /*
  * Called after changing "compl_leader".
  * Show the popup menu with a different set of matches.
@@ -2498,8 +2508,7 @@ ins_compl_new_leader(void)
        save_w_wrow = curwin->w_wrow;
        save_w_leftcol = curwin->w_leftcol;
        compl_restarting = TRUE;
-       if (p_ac)
-           compl_autocomplete = TRUE;
+       compl_autocomplete = ins_compl_has_autocomplete();
        if (ins_complete(Ctrl_N, FALSE) == FAIL)
            compl_cont_status = 0;
        compl_restarting = FALSE;
index f258836ec4aee98a9c4d35803290a9d2b78070e5..4f74de51420b64f7648f50636f82d9a40ee2188c 100644 (file)
@@ -695,6 +695,7 @@ set_init_1(int clean_arg)
 #endif
 
     curbuf->b_p_initialized = TRUE;
+    curbuf->b_p_ac = -1;
     curbuf->b_p_ar = -1;       // no local 'autoread' value
     curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
     check_buf_options(curbuf);
@@ -2207,6 +2208,8 @@ do_set_option_bool(
        // For 'autoread' -1 means to use global value.
        if ((int *)varp == &curbuf->b_p_ar && opt_flags == OPT_LOCAL)
            value = -1;
+       else if ((int *)varp == &curbuf->b_p_ac && opt_flags == OPT_LOCAL)
+           value = -1;
        else
            value = *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
     }
@@ -6441,6 +6444,9 @@ unset_global_local_option(char_u *name, void *from)
        case PV_PATH:
            clear_string_option(&buf->b_p_path);
            break;
+       case PV_AC:
+           buf->b_p_ac = -1;
+           break;
        case PV_AR:
            buf->b_p_ar = -1;
            break;
@@ -6593,6 +6599,7 @@ get_varp_scope(struct vimoption *p, int scope)
            case PV_EP:   return (char_u *)&(curbuf->b_p_ep);
            case PV_KP:   return (char_u *)&(curbuf->b_p_kp);
            case PV_PATH: return (char_u *)&(curbuf->b_p_path);
+           case PV_AC:   return (char_u *)&(curbuf->b_p_ac);
            case PV_AR:   return (char_u *)&(curbuf->b_p_ar);
            case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
            case PV_TC:   return (char_u *)&(curbuf->b_p_tc);
@@ -6669,6 +6676,8 @@ get_varp(struct vimoption *p)
                                    ? (char_u *)&curbuf->b_p_kp : p->var;
        case PV_PATH:   return *curbuf->b_p_path != NUL
                                    ? (char_u *)&(curbuf->b_p_path) : p->var;
+       case PV_AC:     return curbuf->b_p_ac >= 0
+                                   ? (char_u *)&(curbuf->b_p_ac) : p->var;
        case PV_AR:     return curbuf->b_p_ar >= 0
                                    ? (char_u *)&(curbuf->b_p_ar) : p->var;
        case PV_TAGS:   return *curbuf->b_p_tags != NUL
@@ -7501,6 +7510,7 @@ buf_copy_options(buf_T *buf, int flags)
 
            // options that are normally global but also have a local value
            // are not copied, start using the global value
+           buf->b_p_ac = -1;
            buf->b_p_ar = -1;
            buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
            buf->b_p_bkc = empty_option;
index ce75d6862e64ecbd8d91b16c25fe061a069ad929..9e6aed355662fcf0ded783f5b24b4d0275a2f55a 100644 (file)
@@ -1168,6 +1168,7 @@ EXTERN int        p_xtermcodes;   // 'xtermcodes'
 enum
 {
     BV_AI = 0
+    , BV_AC
     , BV_AR
     , BV_BH
     , BV_BKC
index 1db29305e7aafafc9b74cc10edc911759b2471f4..572b7aff13cb47a33251a3703b46f99ce930f24e 100644 (file)
@@ -26,6 +26,7 @@
 
 // Definition of the PV_ values for buffer-local options.
 // The BV_ values are defined in option.h.
+#define PV_AC          OPT_BOTH(OPT_BUF(BV_AC))
 #define PV_AI          OPT_BUF(BV_AI)
 #define PV_AR          OPT_BOTH(OPT_BUF(BV_AR))
 #define PV_BKC         OPT_BOTH(OPT_BUF(BV_BKC))
@@ -390,7 +391,7 @@ static struct vimoption options[] =
                            SCTX_INIT},
 #ifdef ELAPSED_FUNC
     {"autocomplete",  "ac", P_BOOL|P_VI_DEF,
-                           (char_u *)&p_ac, PV_NONE, NULL,
+                           (char_u *)&p_ac, PV_AC, NULL,
                            NULL, {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
     {"autocompletedelay", "acl", P_NUM|P_VI_DEF,
                            (char_u *)&p_acl, PV_NONE, NULL, NULL,
index b1656dacc30ec54b7d2f8e47e486f8b5c04fefcb..3dfa9c019475d44d4d6bf222118e00b03dd4ad55 100644 (file)
@@ -49,7 +49,7 @@ colnr_T ins_compl_col(void);
 int ins_compl_len(void);
 int ins_compl_has_preinsert(void);
 int ins_compl_preinsert_effect(void);
-int ins_compl_has_autocomplete(void);
+int ins_compl_autocomplete_enabled(void);
 int ins_compl_bs(void);
 void ins_compl_addleader(int c);
 void ins_compl_addfrommatch(void);
@@ -76,4 +76,5 @@ void ins_compl_check_keys(int frequency, int in_compl_func);
 int ins_complete(int c, int enable_pum);
 void ins_compl_enable_autocomplete(void);
 void free_insexpand_stuff(void);
+int ins_compl_has_autocomplete(void);
 /* vim: set ft=c : */
index 0968b3c9a9e6a15365fc42d07c9973859fbc3dbe..3efcabda751aa6a77b9cc28c036bf02730fbc0db 100644 (file)
@@ -3285,6 +3285,7 @@ struct file_buffer
     sctx_T     b_p_script_ctx[BV_COUNT]; // SCTXs for buffer-local options
 #endif
 
+    int                b_p_ac;         // 'autocomplete'
     int                b_p_ai;         // 'autoindent'
     int                b_p_ai_nopaste; // b_p_ai saved for paste mode
     char_u     *b_p_bkc;       // 'backupcopy'
index b48f0deec62801d09b3af4673470f91aa6306191..6f6232f963668ad7f45f13c3549ac9d5bb31403e 100644 (file)
@@ -5454,7 +5454,7 @@ func Test_scriptlocal_autoload_func()
   call test_override("char_avail", 1)
   new
   inoremap <buffer> <F2> <Cmd>let b:matches = complete_info(["matches"]).matches<CR>
-  set autocomplete
+  setlocal autocomplete
 
   setlocal complete=.,Fcompl#Func
   call feedkeys("im\<F2>\<Esc>0", 'xt!')
@@ -5465,7 +5465,6 @@ func Test_scriptlocal_autoload_func()
   call assert_equal(['foo', 'foobar'], b:matches->mapnew('v:val.word'))
 
   setlocal complete&
-  set autocomplete&
   bwipe!
   call test_override("char_avail", 0)
   let &rtp = save_rtp
@@ -5563,7 +5562,7 @@ func Test_autocompletedelay()
 
   let lines =<< trim [SCRIPT]
     call setline(1, ['foo', 'foobar', 'foobarbaz'])
-    set autocomplete
+    setlocal autocomplete
   [SCRIPT]
   call writefile(lines, 'XTest_autocomplete_delay', 'D')
   let buf = RunVimInTerminal('-S XTest_autocomplete_delay', {'rows': 10})
index 53fef7dd9e6c638815528437d77ae01106ec4c97..2246dcf1f289f691371b29e75a4a45e150e2cdc1 100644 (file)
@@ -724,6 +724,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1779,
 /**/
     1778,
 /**/