[vim] 70/139: 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)

James McCoy jamessan at debian.org
Fri May 6 04:00:04 UTC 2016


This is an automated email from the git hooks/post-receive script.

jamessan pushed a commit to branch debian/sid
in repository vim.

commit c3691332f72169c486066200c0f3935418364900
Author: Bram Moolenaar <Bram at vim.org>
Date:   Wed Apr 20 12:49:49 2016 +0200

    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)
---
 src/fileio.c                | 28 ++++++++++++++++++++++++++++
 src/testdir/test_syntax.vim | 15 +++++++++++++++
 src/version.c               |  2 ++
 3 files changed, 45 insertions(+)

diff --git a/src/fileio.c b/src/fileio.c
index ed8d45b..0ddd079 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -143,6 +143,18 @@ static void vim_settempdir(char_u *tempdir);
 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,6 +317,10 @@ readfile(
     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,8 +2685,17 @@ failed:
 	    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,6 +9562,9 @@ BYPASS_AU:
     if (event == EVENT_BUFWIPEOUT && buf != NULL)
 	aubuflocal_remove(buf);
 
+    if (retval == OK && event == EVENT_FILETYPE)
+	au_did_filetype = TRUE;
+
     return retval;
 }
 
diff --git a/src/testdir/test_syntax.vim b/src/testdir/test_syntax.vim
index 297e835..4b88fe3 100644
--- a/src/testdir/test_syntax.vim
+++ b/src/testdir/test_syntax.vim
@@ -65,3 +65,18 @@ func Test_syn_iskeyword()
 
   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
diff --git a/src/version.c b/src/version.c
index 774ac52..20197c5 100644
--- a/src/version.c
+++ b/src/version.c
@@ -749,6 +749,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1754,
+/**/
     1753,
 /**/
     1752,

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-vim/vim.git



More information about the pkg-vim-maintainers mailing list