diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2018-02-17 12:09:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-17 12:09:44 +0100 |
commit | 8b543d09d834994f7e696716ce8c146ab0652011 (patch) | |
tree | c768daf477d4ef3c44f23ebdb8154af10002f206 | |
parent | 2f018b1833247aea885ad01d6ac7a6649254b9ac (diff) | |
parent | e9134421ab8f72393d469d9d7793d4a75984cb93 (diff) | |
download | rneovim-8b543d09d834994f7e696716ce8c146ab0652011.tar.gz rneovim-8b543d09d834994f7e696716ce8c146ab0652011.tar.bz2 rneovim-8b543d09d834994f7e696716ce8c146ab0652011.zip |
Merge pull request #8011 from nimitbhardwaj/vim-8.0.0649
vim-patch:8.0.0649 and vim-patch:8.0.0650
-rw-r--r-- | runtime/filetype.vim | 12 | ||||
-rw-r--r-- | src/nvim/ex_cmds.c | 4 | ||||
-rw-r--r-- | src/nvim/option.c | 13 | ||||
-rw-r--r-- | test/functional/autocmd/filetype_spec.lua | 16 |
4 files changed, 38 insertions, 7 deletions
diff --git a/runtime/filetype.vim b/runtime/filetype.vim index a2e1f23bf1..4e0f145c18 100644 --- a/runtime/filetype.vim +++ b/runtime/filetype.vim @@ -1,7 +1,7 @@ " Vim support file to detect file types " " Maintainer: Bram Moolenaar <Bram@vim.org> -" Last Change: 2017 Nov 02 +" Last Change: 2018 Feb 14 " 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() @@ -2804,8 +2807,13 @@ au BufNewFile,BufRead zsh*,zlog* call s:StarSetf('zsh') " Plain text files, needs to be far down to not override others. This avoids " the "conf" type being used if there is a line starting with '#'. -au BufNewFile,BufRead *.txt,*.text,README setf text +au BufNewFile,BufRead *.text,README setf text +" Help files match *.txt but should have a last line that is a modeline. +au BufNewFile,BufRead *.txt + \ if getline('$') !~ 'vim:.*ft=help' + \| setf text + \| endif " Use the filetype detect plugins. They may overrule any of the previously " detected filetypes. diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 2873f76ce0..48d1d42e2e 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -4864,7 +4864,9 @@ void fix_help_buffer(void) char_u *rt; // Set filetype to "help". - set_option_value("ft", 0L, "help", OPT_LOCAL); + if (STRCMP(curbuf->b_p_ft, "help") != 0) { + set_option_value("ft", 0L, "help", OPT_LOCAL); + } if (!syntax_present(curwin)) { for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) { diff --git a/src/nvim/option.c b/src/nvim/option.c index c805e41ec5..2341371f65 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2455,6 +2455,7 @@ did_set_string_option ( int did_chartab = FALSE; char_u **gvarp; bool free_oldval = (options[opt_idx].flags & P_ALLOCED); + int ft_changed = false; /* Get the global option to compare with, otherwise we would have to check * two values for all local options. */ @@ -3174,6 +3175,8 @@ did_set_string_option ( } else if (gvarp == &p_ft) { if (!valid_filetype(*varp)) { errmsg = e_invarg; + } else { + ft_changed = STRCMP(oldval, *varp) != 0; } } else if (gvarp == &p_syn) { if (!valid_filetype(*varp)) { @@ -3256,10 +3259,12 @@ did_set_string_option ( apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname, TRUE, curbuf); } 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, - curbuf->b_fname, TRUE, curbuf); + // 'filetype' is set, trigger the FileType autocommand + if (!(opt_flags & OPT_MODELINE) || ft_changed) { + did_filetype = true; + apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, + curbuf->b_fname, true, curbuf); + } } if (varp == &(curwin->w_s->b_p_spl)) { char_u fname[200]; diff --git a/test/functional/autocmd/filetype_spec.lua b/test/functional/autocmd/filetype_spec.lua new file mode 100644 index 0000000000..e6fa7ab6bb --- /dev/null +++ b/test/functional/autocmd/filetype_spec.lua @@ -0,0 +1,16 @@ +local helpers = require('test.functional.helpers')(after_each) + +local eval = helpers.eval +local clear = helpers.clear +local command = helpers.command + +describe('autocmd FileType', function() + before_each(clear) + + it("is triggered by :help only once", function() + command("let g:foo = 0") + command("autocmd FileType help let g:foo = g:foo + 1") + command("help help") + assert.same(1, eval('g:foo')) + end) +end) |