On Sat, 18 Dec 2010, Christian Brabandt wrote:

Hello,
while working on one of my plugins, I noticed, that the autoload-scripts of my plugin was source on startup. Consider this simple test plugin:
#v+
~$ cat plugin/testPlugin.vim
if exists("g:loaded_test") || &cp
 finish
endif

if 0
       exe test#WarningMsg("This plugin requires Vim 7.3 or higher")

I think you want 'call' here, rather than 'exe'.


       finish
endif
~$ cat autoload/test.vim
fun! test#WarningMsg(msg)"{{{1
       echohl WarningMsg
       echomsg a:msg
       echohl Normal
       let v:errmsg = a:msg
endfun "}}}
~$  vim -u NONE -U NONE -N -i NONE  +'ru plugin/testPlugin.vim|scriptnames'
 1: /home/chrisbra/.vim/plugin/testPlugin.vim
 2: /home/chrisbra/.vim/autoload/test.vim
#v-

As you can see, the autoload script is loaded, even so vim shouldn't need to. Is that the way autoloading is supposed to work or is this a bug?

It seems like a possible optimization. Replacing test#WarningMsg with nonexistent#WarningMsg, it doesn't cause any trouble, for example. (No error is caused, even though autoload/nonexistent.vim doesn't exist.) Apparently autoloading is done along with parsing?

I could see where this might cause trouble, though. Adding to the top of autoload/test.vim:

" simulate something that takes non-trivial time to initialize
sleep 10

And the test specified above takes 10 unnecessary seconds longer to run.

--
Best,
Ben

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Raspunde prin e-mail lui