]> granicus.if.org Git - vim/commitdiff
patch 8.0.0677: setting 'filetype' may switch buffers v8.0.0677
authorBram Moolenaar <Bram@vim.org>
Sun, 25 Jun 2017 19:17:25 +0000 (21:17 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 25 Jun 2017 19:17:25 +0000 (21:17 +0200)
Problem:    Setting 'filetype' internally may cause the current buffer and
            window to change unexpectedly.
Solution:   Set curbuf_lock. (closes #1734)

src/ex_cmds.c
src/ex_getln.c
src/quickfix.c
src/testdir/test_quickfix.vim
src/version.c

index bb9a927763c3084f1d09bb1b8b64ede8b8ecd12f..39f658a6e4f80652a2104095b0ee8f2636e778f2 100644 (file)
@@ -6835,7 +6835,11 @@ fix_help_buffer(void)
 #ifdef FEAT_AUTOCMD
     /* Set filetype to "help" if still needed. */
     if (STRCMP(curbuf->b_p_ft, "help") != 0)
+    {
+       ++curbuf_lock;
        set_option_value((char_u *)"ft", 0L, (char_u *)"help", OPT_LOCAL);
+       --curbuf_lock;
+    }
 #endif
 
 #ifdef FEAT_SYN_HL
index 194b3bf3d8b75aacfced4d9c41699d68f32a0e50..ba8fde65e94973a336a7791aa3f64c9c62b87304 100644 (file)
@@ -6878,6 +6878,8 @@ open_cmdwin(void)
 # ifdef FEAT_AUTOCMD
     /* Do execute autocommands for setting the filetype (load syntax). */
     unblock_autocmds();
+    /* But don't allow switching to another buffer. */
+    ++curbuf_lock;
 # endif
 
     /* Showing the prompt may have set need_wait_return, reset it. */
@@ -6893,6 +6895,9 @@ open_cmdwin(void)
        }
        set_option_value((char_u *)"ft", 0L, (char_u *)"vim", OPT_LOCAL);
     }
+# ifdef FEAT_AUTOCMD
+    --curbuf_lock;
+# endif
 
     /* Reset 'textwidth' after setting 'filetype' (the Vim filetype plugin
      * sets 'textwidth' to 78). */
index 40b6fe93d692c012d67894889529daa9eefc745a..084d82ec0eedffee081c91cce67273d453a0a6ed 100644 (file)
@@ -3425,6 +3425,9 @@ qf_fill_buffer(qf_info_T *qi, buf_T *buf, qfline_T *old_last)
        /* Set the 'filetype' to "qf" each time after filling the buffer.
         * This resembles reading a file into a buffer, it's more logical when
         * using autocommands. */
+#ifdef FEAT_AUTOCMD
+       ++curbuf_lock;
+#endif
        set_option_value((char_u *)"ft", 0L, (char_u *)"qf", OPT_LOCAL);
        curbuf->b_p_ma = FALSE;
 
@@ -3435,6 +3438,7 @@ qf_fill_buffer(qf_info_T *qi, buf_T *buf, qfline_T *old_last)
        apply_autocmds(EVENT_BUFWINENTER, (char_u *)"quickfix", NULL,
                                                               FALSE, curbuf);
        keep_filetype = FALSE;
+       --curbuf_lock;
 #endif
        /* make sure it will be redrawn */
        redraw_curbuf_later(NOT_VALID);
index c23e597e3d56dcaef0d8104988dbb3bbf9dee9d9..755ea745c11d361049f32da7ca3ed34ee29b021c 100644 (file)
@@ -2190,7 +2190,7 @@ endfunc
 func Test_cclose_from_copen()
     augroup QF_Test
        au!
-       au FileType qf :cclose
+        au FileType qf :call assert_fails(':cclose', 'E788')
     augroup END
     copen
     augroup QF_Test
@@ -2227,3 +2227,19 @@ func Test_Qf_Size()
   call XsizeTests('c')
   call XsizeTests('l')
 endfunc
+
+func Test_cclose_in_autocmd()
+  " Problem is only triggered if "starting" is zero, so that the OptionsSet
+  " event will be triggered.
+  call test_override('starting', 1)
+  augroup QF_Test
+    au!
+    au FileType qf :call assert_fails(':cclose', 'E788')
+  augroup END
+  copen
+  augroup QF_Test
+    au!
+  augroup END
+  augroup! QF_Test
+  call test_override('starting', 0)
+endfunc
index ab3185e0b2fd6197c018c68d87adf3717afac31a..3dd0527aad0dc3f604b5cdb83b8c15638b666f43 100644 (file)
@@ -764,6 +764,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    677,
 /**/
     676,
 /**/