Skip to content

Do not trigger filetypeindent/filetypeplugin autocmds by default #691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 50 additions & 5 deletions plug.vim
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ let s:TYPE = {
\ }
let s:loaded = get(s:, 'loaded', {})
let s:triggers = get(s:, 'triggers', {})
let s:need_filetypeplugin_au = 0
let s:need_filetypeindent_au = 0
let s:autocmd_queue_for_vimenter = []

function! plug#begin(...)
if a:0 > 0
Expand Down Expand Up @@ -209,6 +212,21 @@ function! plug#end()
if exists('g:did_load_filetypes')
filetype off
endif

let warn = []
if exists('g:did_load_ftplugin')
let warn += ['plugin']
let s:need_filetypeindent_au = 1
endif
if exists('g:did_indent_on')
let warn += ['indent']
let s:need_filetypeplugin_au = 1
endif
if !empty(warn)
redraw
call s:warn('echom', printf('[vim-plug] "filetype %s on" should not be used manually with vim-plug, please remove it from your vimrc.', join(warn)))
endif

for name in g:plugs_order
if !has_key(g:plugs, name)
continue
Expand Down Expand Up @@ -281,7 +299,21 @@ function! plug#end()
if has('syntax') && !exists('g:syntax_on')
syntax enable
end

" NOTE: v:vim_did_enter might not exist with older Vims, and handling it
" manually can be used in tests.
let s:vim_did_enter = 0
function! s:plug_on_vimenter()
let s:vim_did_enter = 1
for event in s:autocmd_queue_for_vimenter
call s:doautocmd(event)
endfor
endfunction
augroup PlugLOD
autocmd VimEnter * call s:plug_on_vimenter()
augroup END
else
let s:vim_did_enter = 1
call s:reload_plugins()
endif
endfunction
Expand Down Expand Up @@ -419,6 +451,12 @@ function! s:reorg_rtp()
endfunction

function! s:doautocmd(...)
if !s:vim_did_enter
if index(s:autocmd_queue_for_vimenter, a:000) == -1
call add(s:autocmd_queue_for_vimenter, a:000)
endif
return
endif
if exists('#'.join(a:000, '#'))
execute 'doautocmd' ((v:version > 703 || has('patch442')) ? '<nomodeline>' : '') join(a:000)
endif
Expand All @@ -429,9 +467,7 @@ function! s:dobufread(names)
let path = s:rtp(g:plugs[name]).'/**'
for dir in ['ftdetect', 'ftplugin']
if len(finddir(dir, path))
if exists('#BufRead')
doautocmd BufRead
endif
call s:doautocmd('BufRead')
return
endif
endfor
Expand Down Expand Up @@ -502,8 +538,17 @@ function! s:lod_ft(pat, names)
let syn = 'syntax/'.a:pat.'.vim'
call s:lod(a:names, ['plugin', 'after/plugin'], syn, 'after/'.syn)
execute 'autocmd! PlugLOD FileType' a:pat
call s:doautocmd('filetypeplugin', 'FileType')
call s:doautocmd('filetypeindent', 'FileType')

" Executing this is only necessary if "filetype plugin indent on" was used
" before plug#end, and can be skipped when Vim has not entered always.
if s:vim_did_enter
if s:need_filetypeplugin_au
call s:doautocmd('filetypeplugin', 'FileType')
endif
if s:need_filetypeindent_au
call s:doautocmd('filetypeindent', 'FileType')
endif
endif
endfunction

function! s:lod_cmd(cmd, bang, l1, l2, args, names)
Expand Down
4 changes: 4 additions & 0 deletions test/regressions.vader
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Execute (#112 On-demand loading should not suppress messages from ftplugin):
Plug '$PLUG_FIXTURES/ftplugin-msg', { 'for': 'c' }
call plug#end()

" Trigger VimEnter (simulate Vim being started), so that s:lod handles
" filetypeindent/filetypeplugin."
doautocmd VimEnter

redir => out
tabnew a.c
redir END
Expand Down
2 changes: 1 addition & 1 deletion test/workflow.vader
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ Execute (Filetype-based on-demand loading):
AssertEqual ['xxx/ftdetect', 'xxx/after/ftdetect'], g:xxx

setf xxx
AssertEqual ['xxx/ftdetect', 'xxx/after/ftdetect', 'xxx/plugin', 'xxx/after/plugin', 'xxx/syntax', 'xxx/after/syntax', 'xxx/ftplugin', 'xxx/after/ftplugin', 'xxx/indent', 'xxx/after/indent'], g:xxx
AssertEqual ['xxx/ftdetect', 'xxx/after/ftdetect', 'xxx/plugin', 'xxx/after/plugin', 'xxx/syntax', 'xxx/after/syntax'], g:xxx

" syntax/xxx.vim and after/syntax/xxx.vim should not be loaded (#410)
setf yyy
Expand Down