if 0
exe test#WarningMsg("This plugin requires Vim 7.3 or higher")
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?
regards,
Christian
--
Man muss bedenken, dass unter den Menschen gar viele sind, die
doch auch etwas Bedeutendes sagen wollen, ohne produktiv zu sein, und
da kommen die wunderlichsten Dinge an den Tag.
-- Goethe, Maximen und Reflektionen, Nr. 60
> 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
On Sa, 18 Dez 2010, Tom Link wrote:
> > 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?
>
> The line has to be parsed because how would you know if it isn't
> an :endif.
Yes. But that doesn't mean, it the autoload function has to be loaded,
especially since it is known that the if-expression evaluates to false.
> if 0
> exe 'call test#WarningMsg("This plugin requires Vim 7.3 or
> higher")'
> finish
> endif
Ah that works. Thanks. (And yes Benjamin, this was supposed to be a
':call'. Just a bad test ;))
regards,
Christian
On Sa, 18 Dez 2010, Benjamin R. Haskell wrote:
> On Sat, 18 Dec 2010, Christian Brabandt wrote:
>> exe test#WarningMsg("This plugin requires Vim 7.3 or higher")
>
> I think you want 'call' here, rather than 'exe'.
Yes. A left over from one of my tests. Didn't notice it, when writing
the mail. But the plugin called it correctly.
> 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.
Yes exactly. I look into the code, maybe I find a way to fix it.
regards,
Christian