Skip to content

Commit

Permalink
vim-patch-8.0.0649 and vim-patch-8.0.0650: autocmd open help 2 times
Browse files Browse the repository at this point in the history
  • Loading branch information
nimitbhardwaj committed Feb 16, 2018
1 parent 09b51bb commit e913442
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
12 changes: 10 additions & 2 deletions runtime/filetype.vim
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion src/nvim/ex_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 9 additions & 4 deletions src/nvim/option.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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];
Expand Down
16 changes: 16 additions & 0 deletions test/functional/autocmd/filetype_spec.lua
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit e913442

Please sign in to comment.