]> granicus.if.org Git - vim/commitdiff
patch 8.1.1795: no syntax HL after splitting windows with :bufdo v8.1.1795
authorBram Moolenaar <Bram@vim.org>
Sat, 3 Aug 2019 11:29:46 +0000 (13:29 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 3 Aug 2019 11:29:46 +0000 (13:29 +0200)
Problem:    No syntax HL after splitting windows with :bufdo. (Yasuhiro
            Matsumoto)
Solution:   Trigger Syntax autocommands in buffers that are active.
            (closes #4761)

src/ex_cmds2.c
src/option.c
src/testdir/test_syntax.vim
src/version.c
src/vim.h

index a275fb8b70734f8706f25c7eab085095c9f25b2b..a8be96dc32b0a57f90efa709c3e81f97ced06084 100644 (file)
@@ -1447,9 +1447,15 @@ ex_listdo(exarg_T *eap)
 
 #if defined(FEAT_SYN_HL)
     if (eap->cmdidx != CMD_windo && eap->cmdidx != CMD_tabdo)
+    {
        /* Don't do syntax HL autocommands.  Skipping the syntax file is a
         * great speed improvement. */
        save_ei = au_event_disable(",Syntax");
+
+       for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+           buf->b_flags &= ~BF_SYN_SET;
+       buf = curbuf;
+    }
 #endif
 #ifdef FEAT_CLIPBOARD
     start_global_changes();
@@ -1641,9 +1647,35 @@ ex_listdo(exarg_T *eap)
 #if defined(FEAT_SYN_HL)
     if (save_ei != NULL)
     {
+       buf_T           *bnext;
+       aco_save_T      aco;
+
        au_event_restore(save_ei);
-       apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
+
+       for (buf = firstbuf; buf != NULL; buf = bnext)
+       {
+           bnext = buf->b_next;
+           if (buf->b_nwindows > 0 && (buf->b_flags & BF_SYN_SET))
+           {
+               buf->b_flags &= ~BF_SYN_SET;
+
+               // buffer was opened while Syntax autocommands were disabled,
+               // need to trigger them now.
+               if (buf == curbuf)
+                   apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
                                               curbuf->b_fname, TRUE, curbuf);
+               else
+               {
+                   aucmd_prepbuf(&aco, buf);
+                   apply_autocmds(EVENT_SYNTAX, buf->b_p_syn,
+                                                     buf->b_fname, TRUE, buf);
+                   aucmd_restbuf(&aco);
+               }
+
+               // start over, in case autocommands messed things up.
+               bnext = firstbuf;
+           }
+       }
     }
 #endif
 #ifdef FEAT_CLIPBOARD
index a804dd870449f343a1a309530fd23d8f1123bb09..bf253a461bb2eb695bc5fa84c386e3ec5848a9ad 100644 (file)
@@ -7931,6 +7931,7 @@ did_set_string_option(
            // recursively, to avoid endless recurrence.
            apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
                    value_changed || syn_recursive == 1, curbuf);
+           curbuf->b_flags |= BF_SYN_SET;
            --syn_recursive;
        }
 #endif
index c9808bec4f6ed665901433e95a1b5decdc41455b..562a44ce1600764f6e547b2b1fc916b0d0a6af32 100644 (file)
@@ -582,3 +582,41 @@ func Test_syn_wrong_z_one()
   call test_override("ALL", 0)
   bwipe!
 endfunc
+
+func Test_syntax_after_bufdo()
+  call writefile(['/* aaa comment */'], 'Xaaa.c')
+  call writefile(['/* bbb comment */'], 'Xbbb.c')
+  call writefile(['/* ccc comment */'], 'Xccc.c')
+  call writefile(['/* ddd comment */'], 'Xddd.c')
+
+  let bnr = bufnr('%')
+  new Xaaa.c
+  badd Xbbb.c
+  badd Xccc.c
+  badd Xddd.c
+  exe "bwipe " . bnr
+  let l = []
+  bufdo call add(l, bufnr('%'))
+  call assert_equal(4, len(l))
+
+  syntax on
+
+  " This used to only enable syntax HL in the last buffer.
+  bufdo tab split
+  tabrewind
+  for tab in range(1, 4)
+    norm fm
+    call assert_equal(['cComment'], map(synstack(line("."), col(".")), 'synIDattr(v:val, "name")'))
+    tabnext
+  endfor
+
+  bwipe! Xaaa.c
+  bwipe! Xbbb.c
+  bwipe! Xccc.c
+  bwipe! Xddd.c
+  syntax off
+  call delete('Xaaa.c')
+  call delete('Xbbb.c')
+  call delete('Xccc.c')
+  call delete('Xddd.c')
+endfunc
index 43999bf664d75380167507c219f5790df294c79a..10e05f4b11f87b78c31ee43cfe7bd7af017136fe 100644 (file)
@@ -773,6 +773,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1795,
 /**/
     1794,
 /**/
index 6f7a11d63017c9c7ae1d3a14f095e4dd4ba4f81f..02b4c03bc65d6d5143f70046132d1de680ecc62b 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -698,20 +698,21 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
 #define NOTDONE                        2   /* not OK or FAIL but skipped */
 
 /* flags for b_flags */
-#define BF_RECOVERED   0x01    /* buffer has been recovered */
-#define BF_CHECK_RO    0x02    /* need to check readonly when loading file
-                                  into buffer (set by ":e", may be reset by
-                                  ":buf" */
-#define BF_NEVERLOADED 0x04    /* file has never been loaded into buffer,
-                                  many variables still need to be set */
-#define BF_NOTEDITED   0x08    /* Set when file name is changed after
-                                  starting to edit, reset when file is
-                                  written out. */
-#define BF_NEW         0x10    /* file didn't exist when editing started */
-#define BF_NEW_W       0x20    /* Warned for BF_NEW and file created */
-#define BF_READERR     0x40    /* got errors while reading the file */
-#define BF_DUMMY       0x80    /* dummy buffer, only used internally */
-#define BF_PRESERVED   0x100   /* ":preserve" was used */
+#define BF_RECOVERED   0x01    // buffer has been recovered
+#define BF_CHECK_RO    0x02    // need to check readonly when loading file
+                               // into buffer (set by ":e", may be reset by
+                               // ":buf"
+#define BF_NEVERLOADED 0x04    // file has never been loaded into buffer,
+                               // many variables still need to be set
+#define BF_NOTEDITED   0x08    // Set when file name is changed after
+                               // starting to edit, reset when file is
+                               // written out.
+#define BF_NEW         0x10    // file didn't exist when editing started
+#define BF_NEW_W       0x20    // Warned for BF_NEW and file created
+#define BF_READERR     0x40    // got errors while reading the file
+#define BF_DUMMY       0x80    // dummy buffer, only used internally
+#define BF_PRESERVED   0x100   // ":preserve" was used
+#define BF_SYN_SET     0x200   // 'syntax' option was set
 
 /* Mask to check for flags that prevent normal writing */
 #define BF_WRITE_MASK  (BF_NOTEDITED + BF_NEW + BF_READERR)