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

ftplugin/**/*.vim don't load lazily #24

Closed
ghost opened this issue Jun 21, 2014 · 31 comments
Closed

ftplugin/**/*.vim don't load lazily #24

ghost opened this issue Jun 21, 2014 · 31 comments
Labels

Comments

@ghost
Copy link

ghost commented Jun 21, 2014

I found that I need to add 'ftplugin' to the list of types in the s:lod_ft function to make vim-go plugin work properly. Without it the :GoFmt command was not available.

function! s:lod_ft(name, plug)
  if has_key(s:loaded, a:name)
    return
  endif
  call s:lod(a:plug, ['ftplugin', 'plugin', 'after'])
  let s:loaded[a:name] = 1
endfunction

My little knowledge of the vim internals doesn't allow me to make it a pull request. Can this change break something?

@junegunn
Copy link
Owner

Hi, thanks for the report.
I've just added Plug 'fatih/vim-go', { 'for': 'go' } to my .vimrc, opened a go file, and checked that GoFmt was added.

Could you show me the content of a.log file after this command?

vim --startuptime a.log a.go

@ghost
Copy link
Author

ghost commented Jun 21, 2014

Sure.

http://bpaste.net/show/393916/

@junegunn
Copy link
Owner

Okay, mine is here: http://bpaste.net/show/urXdxCbZJJsS0qgbz1ct/
You can see files are correctly loaded.

https://github.com/opennota/dotfiles/blob/master/.vimrc#L152-L153
This is your .vimrc, right? Could you try again after removing the two lines? vim-plug internally does that, so they're not required.

And by the way, which version of Vim are you running?

@junegunn
Copy link
Owner

I even tested with your .vimrc, but it seems to work fine, though I see an error:

Error detected while processing FileType Auto commands for "*":
E117: Unknown function: UltiSnips#FileTypeChanged

http://bpaste.net/show/MX9qQnsFhFwuMPa0TaQn/

@ghost
Copy link
Author

ghost commented Jun 21, 2014

Yes, I use slightly modified ultisnips (to get rid of this error).

The same with these two lines removed, except that the following lines disappeared from the log:

sourcing /usr/share/vim/vim74/syntax/nosyntax.vim
sourcing /usr/share/vim/vim74/syntax/syncolor.vim
sourcing /usr/share/vim/vim74/syntax/synload.vim
sourcing /usr/share/vim/vim74/syntax/syntax.vim
sourcing /usr/share/vim/vim74/filetype.vim
sourcing /usr/share/vim/vim74/ftplugin.vim
sourcing /usr/share/vim/vim74/indent.vim

@ghost
Copy link
Author

ghost commented Jun 21, 2014

vim --version

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jun 21 2014 12:51:58)                                                   
Included patches: 1-155                                                                                              
Modified by Gentoo-7.4.155                                                                                           
Compiled by portage@localhost                                                                                        
Huge version without GUI.  Features included (+) or not (-):                                                         
+acl             +farsi           +mouse_netterm   +syntax                                                           
+arabic          +file_in_path    +mouse_sgr       +tag_binary                                                       
+autocmd         +find_in_path    -mouse_sysmouse  +tag_old_static                                                   
-balloon_eval    +float           +mouse_urxvt     -tag_any_white                                                    
-browse          +folding         +mouse_xterm     -tcl                                                              
++builtin_terms  -footer          +multi_byte      +terminfo                                                         
+byte_offset     +fork()          +multi_lang      +termresponse                                                     
+cindent         +gettext         -mzscheme        +textobjects                                                      
+clientserver    -hangul_input    +netbeans_intg   +title                                                            
+clipboard       +iconv           +path_extra      -toolbar                                                          
+cmdline_compl   +insert_expand   +perl            +user_commands                                                    
+cmdline_hist    +jumplist        +persistent_undo +vertsplit                                                        
+cmdline_info    +keymap          +postscript      +virtualedit                                                      
+comments        +langmap         +printer         +visual
+conceal         +libcall         +profile         +visualextra
+cryptv          +linebreak       +python          +viminfo
-cscope          +lispindent      -python3         +vreplace
+cursorbind      +listcmds        +quickfix        +wildignore
+cursorshape     +localmap        +reltime         +wildmenu
+dialog_con      +lua             +rightleft       +windows
+diff            +menu            -ruby            +writebackup
+digraphs        +mksession       +scrollbind      +X11
-dnd             +modify_fname    +signs           +xfontset
-ebcdic          +mouse           +smartindent     -xim
+emacs_tags      -mouseshape      -sniff           +xsmp_interact
+eval            +mouse_dec       +startuptime     +xterm_clipboard
+ex_extra        -mouse_gpm       +statusline      -xterm_save
+extra_search    -mouse_jsbterm   -sun_workshop    -xpm
   system vimrc file: "/etc/vim/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/usr/share/vim"
Compilation: x86_64-pc-linux-gnu-gcc -c -I. -Iproto -DHAVE_CONFIG_H     -O2 -pipe -march=native -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1      
Linking: x86_64-pc-linux-gnu-gcc   -Wl,-E  -Wl,-O1 -L/usr/local/lib -Wl,--as-needed -o vim    -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE  -lm -lncurses -lelf -lnsl   -ldl  -L/usr/lib -llua -Wl,-E -Wl,-O1 -Wl,--as-needed  -L/usr/lib64/perl5/5.16.3/x86_64-linux/CORE -lperl -lnsl -ldl -lm -lcrypt -lutil -lc -L/usr/lib64/python2.7/config -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic      

@ghost
Copy link
Author

ghost commented Jun 21, 2014

I renamed ~/.vim to .vim2 and did a clean :PlugInstall. Nothing changed.

vim-plug is latest (commit 288a4f7).

@junegunn
Copy link
Owner

Thanks for clarification. I'm currently testing it on several different platforms. In the meantime, could you post the --startuptime log (vim --startuptime a.log a.go) when you have only three lines in your .vimrc?

call plug#begin()
Plug 'fatih/vim-go', { 'for': 'go' }
call plug#end()

@ghost
Copy link
Author

ghost commented Jun 21, 2014

Here: http://bpaste.net/show/394142/

@ghost
Copy link
Author

ghost commented Jun 21, 2014

FileType event happens before set rtp=.

plug.vim

function! s:add_rtp(rtp)
  let g:x = g:x . s:esc(a:rtp) . "\n"
  execute "set rtp^=".s:esc(a:rtp)
  if isdirectory(a:rtp.'after')
    execute "set rtp+=".s:esc(a:rtp.'after')
  endif
endfunction

.vimrc

let g:x = ""
au FileType go let g:x = g:x . "FileType\n"
call plug#begin()
Plug 'fatih/vim-go', { 'for': 'go' }
call plug#end()

command line

:echo g:x
FileType
/home/xxx/.vim/plugged/vim-go

@junegunn
Copy link
Owner

Oh, that's normal. That FileType event is what triggers vim-plug to load plugin files.

I just reproduced the problem on Fedora. (It worked find on OSX and Ubuntu (12 & 14)) I'll fix the problem and let you know, thanks!

@junegunn
Copy link
Owner

It was caused by filetype plugin on line in /etc/vimrc which is loaded before vim-plug. Please update vim-plug and check if the problem is resolved.

@junegunn junegunn added the bug label Jun 21, 2014
@junegunn
Copy link
Owner

You might even want to skip loading /etc/vimrc if it doesn't contain something relevant. It will slightly reduce the startup time.

http://superuser.com/questions/140913/how-to-start-vim-without-executing-etc-vimrc

@stobenski
Copy link

Excuse me, but now (after last commit 1d477a1)

au FileType * setl fo-=cro

(disable auto comment next line) works only if placed after

call plug#end()

is this normal?

@junegunn
Copy link
Owner

@Gyrfalco Did it work before the commit? I tested without it (git checkout 0.3.1), and the behavior looks consistent:

  • If it comes before plug#end() call, fo is overwritten by ftplugin (verbose set fo?), so it looks as if it doesn't work
  • If it comes after plug#end() call, it is invoked after ftplugin, so it works as expected.

@junegunn
Copy link
Owner

@Gyrfalco Okay, I see the problem. It depends on whether you have filetype plugin on before plug#end() call or not. I'll push another commit that doesn't modify autocmd order.

junegunn added a commit that referenced this issue Jun 22, 2014
junegunn added a commit that referenced this issue Jun 22, 2014
If `filetype plugin on` is called before `plug#end()`, filetype
plugin handler is invoked before ODL autocmd from vim-plug which
updates runtimepath and ftplugin files are not loaded.
@junegunn
Copy link
Owner

@opennota @Gyrfalco Could you test again with the latest version?

@ghost
Copy link
Author

ghost commented Jun 22, 2014

I have au FileType go call GoOptions() in my .vimrc, and now GoOptions() is called 6 times. Is this normal? It was 1 before (commit 288a4f7).

@junegunn
Copy link
Owner

@opennota 6 times? No. It is possible that it's called twice when vim-go is first loaded, but after that it should be loaded only once per the event.

I downloaded your .vimrc and prepended filetype plugin on to it since I don't have /etc/vimrc. The first time I open a go file, GoOptions is called twice, but then if I open another go file, it is only called once. Could you check again?

@ghost
Copy link
Author

ghost commented Jun 22, 2014

Ah, it happens when I comment out the autocmd FileType * ... line in the ftdetect/UltiSnips.vim. Without this change it is 2. When I change this line to autocmd FileType * : it is 2 again. How come that autocmd FileType * command can change the number of my function invocations?

@junegunn
Copy link
Owner

It is possible that the same autocmds are registered multiple times, check the output of autocmd filetype and autocmd filetype go. Do you see duplicate entries? It is a common convention to wrap autocmd definitions in a autocmd group so that it's not added multiple times.

augroup filetype_go
  autocmd!
  " ...
augroup END

I'm still looking for a way to avoid double-loading of ftplugins at the first time a certain filetype is loaded, without breaking the use case of @Gyrfalco.

@ghost
Copy link
Author

ghost commented Jun 22, 2014

No duplicate entries, while GoOptions() is called 6 times.

filetypeplugin  FileType
    *         call s:LoadFTPlugin()
gentoo  FileType
    crontab   set backupcopy=yes
filetypeindent  FileType
    *         call s:LoadIndent()
syntaxset  FileType
    *         exe "set syntax=" . expand("<amatch>")
FileType
    go        call GoOptions()
fugitive  FileType
    netrw     call fugitive#detect(expand('%:p'))
fugitive_blame  FileType
    fugitiveblame
              setlocal nomodeline | if exists('b:git_dir') | let &l:keywordprg = s:repo().keywordprg() | endif
fugitive_files  FileType
    git       if exists('b:git_dir') |  call s:JumpInit() | endif
SneakPluginNetrw  FileType
    netrw     autocmd SneakPluginNetrw CursorMoved <buffer> call <sid>map_netrw_key('s') | call <sid>map_netrw_key('S
') | autocmd! SneakPluginNetrw * <buffer>
airline  FileType
    *         call <sid>on_window_changed()
NERDCommenter  FileType
    *         :call s:SetUpForNewFiletype(&filetype, 1)

@junegunn
Copy link
Owner

What happens when you open the 2nd go file? How many times does GoOptions get called then?

@ghost
Copy link
Author

ghost commented Jun 22, 2014

@junegunn
1.

Without /etc/vimrc (vim -u ~/.vimrc) - still 6 for the first file.

@ghost
Copy link
Author

ghost commented Jun 22, 2014

It is

        execute printf('autocmd FileType %s call <SID>lod_ft(%s, %s, %s)',
              \ pat, string(pat), string(name), string(plug))

that is called once for each following line:

Plug 'Shougo/neocomplete.vim', {'for': 'go'}
Plug 'scrooloose/syntastic', {'for': 'go'}
Plug 'majutsushi/tagbar', {'for': 'go'}
Plug 'SirVer/ultisnips', {'for': 'go'}
Plug 'fatih/vim-go', {'for': 'go'}

5 + 1 = 6

@junegunn
Copy link
Owner

Ah yes you're right. I just reverted a commit that inadvertently broke multiple plugins for the same type. I'll come up with a way to reduce the calls.

junegunn added a commit that referenced this issue Jun 22, 2014
This reverts commit a026eb3.

Conflicts:
	plug.vim
@junegunn
Copy link
Owner

@opennota @Gyrfalco Sorry for all the confusion. Please update and test it again.

@ghost
Copy link
Author

ghost commented Jun 22, 2014

Works for me. Thank you!

@junegunn
Copy link
Owner

Thanks. I'll close this issue once @Gyrfalco confirms.

We still have this one-time, double-loading problem though, which should be harmless, but mostly unnecessary. I'll create a separate issue for it.

@stobenski
Copy link

Works for me too! Thank you very much.

@junegunn
Copy link
Owner

Thank you for all the help!

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

No branches or pull requests

2 participants