patch 8.0.0649: when opening a help file the filetype is set several times v8.0.0649
authorBram Moolenaar <Bram@vim.org>
Thu, 22 Jun 2017 12:16:31 +0000 (14:16 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 22 Jun 2017 12:16:31 +0000 (14:16 +0200)
Problem:    When opening a help file the filetype is set several times.
Solution:   When setting the filetype to the same value from a modeline, don't
            trigger FileType autocommands.  Don't set the filetype to "help"
            when it's already set correctly.

runtime/filetype.vim
src/ex_cmds.c
src/option.c
src/version.c

index 635e1c3ce7b092e3aa536b19684d3af56debcef3..d676329bdd5dc5ed23b66e573418f5acb0d0e406 100644 (file)
@@ -1,7 +1,7 @@
 " Vim support file to detect file types
 "
 " Maintainer:  Bram Moolenaar <Bram@vim.org>
-" Last Change: 2017 Jun 12
+" Last Change: 2017 Jun 20
 
 " Listen very carefully, I will say this only once
 if exists("did_load_filetypes")
@@ -48,6 +48,9 @@ func! s:StarSetf(ft)
   endif
 endfunc
 
+" Vim help file
+au BufNewFile,BufRead $VIMRUNTIME/doc/*.txt    setf help
+
 " Abaqus or Trasys
 au BufNewFile,BufRead *.inp                    call s:Check_inp()
 
index 59531bea0cca881ee6d53d55e9579aa2a0077097..adf1e3bd20f782f83491339ff32ca26cf8f5b418 100644 (file)
@@ -6832,8 +6832,9 @@ fix_help_buffer(void)
     char_u     *rt;
     int                mustfree;
 
-    /* set filetype to "help". */
-    set_option_value((char_u *)"ft", 0L, (char_u *)"help", OPT_LOCAL);
+    /* Set filetype to "help" if still needed. */
+    if (STRCMP(curbuf->b_p_ft, "help") != 0)
+       set_option_value((char_u *)"ft", 0L, (char_u *)"help", OPT_LOCAL);
 
 #ifdef FEAT_SYN_HL
     if (!syntax_present(curwin))
index 2a92bc5ae89f92e14feb4a2f4374175ff5fe86be..154c28b5a8f996347566df2f8536001e2603ba19 100644 (file)
@@ -6009,6 +6009,9 @@ did_set_string_option(
     /* set when changing an option that only requires a redraw in the GUI */
     int                redraw_gui_only = FALSE;
 #endif
+#ifdef FEAT_AUTOCMD
+    int                ft_changed = FALSE;
+#endif
 
     /* Get the global option to compare with, otherwise we would have to check
      * two values for all local options. */
@@ -7418,6 +7421,8 @@ did_set_string_option(
     {
        if (!valid_filetype(*varp))
            errmsg = e_invarg;
+       else
+           ft_changed = STRCMP(oldval, *varp) != 0;
     }
 #endif
 
@@ -7531,10 +7536,15 @@ did_set_string_option(
 # endif
        else if (varp == &(curbuf->b_p_ft))
        {
-           /* 'filetype' is set, trigger the FileType autocommand */
-           did_filetype = TRUE;
-           apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
+           /* 'filetype' is set, trigger the FileType autocommand.
+            * Skip this when called from a modeline and the filetype was
+            * already set to this value. */
+           if (!(opt_flags & OPT_MODELINE) || ft_changed)
+           {
+               did_filetype = TRUE;
+               apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
                                               curbuf->b_fname, TRUE, curbuf);
+           }
        }
 #endif
 #ifdef FEAT_SPELL
index b221ce25981639b3f107a13f88f366a58d5bcdd6..47e1da5eca2569d59c608cd34ed964ad085ba4a5 100644 (file)
@@ -764,6 +764,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    649,
 /**/
     648,
 /**/