Patch 7.4.1754
Problem:    When 'filetype' was set and reloading a buffer which does not
            cause it to be set, the syntax isn't loaded. (KillTheMule)
Solution:   Remember whether the FileType event was fired and fire it if not.
            (Anton Lindqvist, closes #747)
Files:      src/fileio.c, src/testdir/test_syntax.vim


*** ../vim-7.4.1753/src/fileio.c        2016-02-23 14:52:31.881232212 +0100
--- src/fileio.c        2016-04-20 12:12:16.042106189 +0200
***************
*** 143,148 ****
--- 143,160 ----
  static char *e_auchangedbuf = N_("E812: Autocommands changed buffer or buffer 
name");
  #endif
  
+ #ifdef FEAT_AUTOCMD
+ /*
+  * Set by the apply_autocmds_group function if the given event is equal to
+  * EVENT_FILETYPE. Used by the readfile function in order to determine if
+  * EVENT_BUFREADPOST triggered the EVENT_FILETYPE.
+  *
+  * Relying on this value requires one to reset it prior calling
+  * apply_autocmds_group.
+  */
+ static int au_did_filetype INIT(= FALSE);
+ #endif
+ 
      void
  filemess(
      buf_T     *buf,
***************
*** 305,310 ****
--- 317,326 ----
      int               using_b_fname;
  #endif
  
+ #ifdef FEAT_AUTOCMD
+     au_did_filetype = FALSE; /* reset before triggering any autocommands */
+ #endif
+ 
      curbuf->b_no_eol_lnum = 0;        /* in case it was set by the previous 
read */
  
      /*
***************
*** 2669,2676 ****
--- 2685,2701 ----
            apply_autocmds_exarg(EVENT_FILTERREADPOST, NULL, sfname,
                                                          FALSE, curbuf, eap);
        else if (newfile)
+       {
            apply_autocmds_exarg(EVENT_BUFREADPOST, NULL, sfname,
                                                          FALSE, curbuf, eap);
+           if (!au_did_filetype && *curbuf->b_p_ft != NUL)
+               /*
+                * EVENT_FILETYPE was not triggered but the buffer already has a
+                * filetype. Trigger EVENT_FILETYPE using the existing filetype.
+                */
+               apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
+                       TRUE, curbuf);
+       }
        else
            apply_autocmds_exarg(EVENT_FILEREADPOST, sfname, sfname,
                                                            FALSE, NULL, eap);
***************
*** 9537,9542 ****
--- 9562,9570 ----
      if (event == EVENT_BUFWIPEOUT && buf != NULL)
        aubuflocal_remove(buf);
  
+     if (retval == OK && event == EVENT_FILETYPE)
+       au_did_filetype = TRUE;
+ 
      return retval;
  }
  
*** ../vim-7.4.1753/src/testdir/test_syntax.vim 2016-01-19 22:28:54.615592984 
+0100
--- src/testdir/test_syntax.vim 2016-04-20 12:30:11.247055867 +0200
***************
*** 65,67 ****
--- 65,82 ----
  
    quit!
  endfunc
+ 
+ func Test_syntax_after_reload()
+   split Xsomefile
+   call setline(1, ['hello', 'there'])
+   w!
+   only!
+   setl filetype=hello
+   au FileType hello let g:gotit = 1
+   call assert_false(exists('g:gotit'))
+   edit other
+   buf Xsomefile
+   call assert_equal('hello', &filetype)
+   call assert_true(exists('g:gotit'))
+   call delete('Xsomefile')
+ endfunc
*** ../vim-7.4.1753/src/version.c       2016-04-20 12:01:49.548584830 +0200
--- src/version.c       2016-04-20 12:15:42.959967869 +0200
***************
*** 750,751 ****
--- 750,753 ----
  {   /* Add new patch number below this line */
+ /**/
+     1754,
  /**/

-- 
GUARD #1:  What -- a swallow carrying a coconut?
ARTHUR:    It could grip it by the husk!
GUARD #1:  It's not a question of where he grips it!  It's a simple question
           of weight ratios!  A five ounce bird could not carry a 1 pound
           coconut.
                                  The Quest for the Holy Grail (Monty Python)

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui