diff options
author | James McCoy <jamessan@jamessan.com> | 2016-12-08 09:42:32 -0500 |
---|---|---|
committer | James McCoy <jamessan@jamessan.com> | 2016-12-08 10:27:32 -0500 |
commit | d1473880bcd6fdd8cc72b5595903081e59c6d2d1 (patch) | |
tree | ede18f1190213c10e35636e0d41ede1125513624 /src/nvim/fileio.c | |
parent | 49d29526587b587d08e2883b060c756637e891a2 (diff) | |
download | rneovim-d1473880bcd6fdd8cc72b5595903081e59c6d2d1.tar.gz rneovim-d1473880bcd6fdd8cc72b5595903081e59c6d2d1.tar.bz2 rneovim-d1473880bcd6fdd8cc72b5595903081e59c6d2d1.zip |
vim-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 vim/vim#747)
https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Diffstat (limited to 'src/nvim/fileio.c')
-rw-r--r-- | src/nvim/fileio.c | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 934d81dcd0..2c0bdb6655 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -187,6 +187,14 @@ struct bw_info { static char *e_auchangedbuf = N_( "E812: Autocommands changed buffer or buffer name"); +// 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 bool au_did_filetype INIT(= false); + void filemess(buf_T *buf, char_u *name, char_u *s, int attr) { int msg_scroll_save; @@ -329,6 +337,8 @@ readfile ( int using_b_ffname; int using_b_fname; + au_did_filetype = false; // reset before triggering any autocommands + curbuf->b_no_eol_lnum = 0; /* in case it was set by the previous read */ /* @@ -1961,12 +1971,18 @@ failed: if (filtering) apply_autocmds_exarg(EVENT_FILTERREADPOST, NULL, sfname, FALSE, curbuf, eap); - else if (newfile) + else if (newfile) { apply_autocmds_exarg(EVENT_BUFREADPOST, NULL, sfname, FALSE, curbuf, eap); - else + 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); + } if (msg_scrolled == n) msg_scroll = m; if (aborting()) /* autocmds may abort script processing */ @@ -6865,6 +6881,10 @@ BYPASS_AU: if (event == EVENT_BUFWIPEOUT && buf != NULL) aubuflocal_remove(buf); + if (retval == OK && event == EVENT_FILETYPE) { + au_did_filetype = true; + } + return retval; } |