Skip to content
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

Syntax loaded incorrectly/twice with lazy loaded filetype plugin #581

Open
blueyed opened this issue Jan 22, 2017 · 1 comment
Open

Syntax loaded incorrectly/twice with lazy loaded filetype plugin #581

blueyed opened this issue Jan 22, 2017 · 1 comment

Comments

@blueyed
Copy link
Contributor

blueyed commented Jan 22, 2017

When a plugin has a after/syntax/lua.vim file, and this plugin gets loaded 'for': ['lua'], the main syntax plugin(s) (syntax/lua.vim) will not be loaded, when b:current_syntax might exist already.

In the case of https://github.com/raymond-w-ko/vim-lua-indent/blob/master/after/syntax/lua.vim#L7 this relies on a variable lua_version being set, but it gets not set from Vim's syntax/lua.vim whenb:current_syntax is set already.

TEST CASE:

  1. Create a config.ld file, it will have ft=ld and b:current_syntax='ld'
  2. set ft=lua (manually or through a modeline)

vim-plug will call runtime syntax/lua.vim, but that finishes, because b:current_syntax is set to 'ld' already.
Then after/syntax/lua.vim from the plugin gets sourced, and throws an error because of the unknown var.

I've noticed that passing in , syn, 'after/'.syn to s:lod will even cause it to be loaded twice in the end?!

So the following would actually fix it for this use case, but breaks the "Filetype-based on-demand loading" test ('xxx/syntax', 'xxx/after/syntax' is missing from g:xxx).

diff --git i/plug.vim w/plug.vim
index 95d8eab..a0d6b1c 100644
--- i/plug.vim
+++ w/plug.vim
@@ -489,7 +489,7 @@ endfunction
 
 function! s:lod_ft(pat, names)
   let syn = 'syntax/'.a:pat.'.vim'
-  call s:lod(a:names, ['plugin', 'after/plugin'], syn, 'after/'.syn)
+  call s:lod(a:names, ['plugin', 'after/plugin'])
   execute 'autocmd! PlugLOD FileType' a:pat
   call s:doautocmd('filetypeplugin', 'FileType')
   call s:doautocmd('filetypeindent', 'FileType')

When testing it manually, the syntaxset FileType event will trigger the syntax files to be loaded automatically, but for some reason that is not happening during the tests, although the autocommand is there?!

syntaxset  FileType
    *         exe "set syntax=" . expand("<amatch>")

A test case (t/minimal.vim):

set rtp+=../$PWD

call plug#begin('~/.vim/plugged')
  exe "Plug '".expand("$PWD")."/p1', {'for': 'lua'}"
  " Plug 'raymond-w-ko/vim-lua-indent', {'for': 'lua'}
call plug#end()

With p1/after/syntax/lua.vim:

echom lua_version

Then run it with vim -Nu minimal.vim t.ld and call set ft=lua in Vim:

Error detected while processing /home/user/Vcs/vim-plug/t/p1/after/syntax/lua.vim:
line    1:
E121: Undefined variable: lua_version
E15: Invalid expression: lua_version
5

A fix for this might be to unlet! b:current_syntax in s:lod_ft, but then it will (still) cause the syntax files to be sourced twice - which seems to be wrong in the first place?!

@junegunn
Copy link
Owner

Thanks. I haven't looked closely into the issue yet, but

but for some reason that is not happening during the tests, although the autocommand is there?!

would using nested autocmd in

execute printf('autocmd FileType %s call <SID>lod_ft(%s, %s)',
help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants