Tuesday, July 9, 2013

Re: Programmatically detecting whether plugin scripts loaded?

On 09/07/13 07:55, David Barnett wrote:
> Is there any way to detect programmatically from a vim script whether
> vim has started loading plugin scripts? It would be useful for plugin
> managers etc. to be able to detect what phase of startup their code is
> being called from.
>
> Also, would there be any unwanted consequences if vim detected
> directories added to &runtimepath after startup and sourced those plugin
> scripts, too? For instance:
>
> == .vim/plugin/x.vim ==
> set rtp+=~/y/plugin/y.vim
>
> never ends up sourcing ~/y/plugin/y.vim. Should it?

No it shouldn't. Remember: ":runtime plugin/*.vim" happens automatically
once only, and that is near the end of startup, shortly before the
GUIEnter event in gvim, or shortly before the VimEnter event in Console
Vim; it is bypassed if you start Vim with --noplugin or with -u NONE, or
if before plugins are loaded (e.g. in your vimrc; and preferably in some
:if branch) you ":set noloadplugins" (or ":set nolpl" for short, and of
course without quotes).

Once Vim has started loading plugins, modifying 'runtimepath' may have
an effect on where filetype plugins, syntax scripts, indent scripts,
autoload scripts, etc., will be looked for; it is too late to influence
the loading of global plugins, since that has already begun and will not
be done again in this Vim session.

Also, 'runtimepath' is a list of directories, not of files. If
~/.vim/plugin/x.vim decides that some script should be run from some
place not in 'runtimepath', it should ":source" it; or if the script is
at some unusual place but still under 'runtimepath' you could use the
":runtime" command: to take a real-world example, you could have the
following one-line global plugin:

== $VIM/vimfiles/plugin/matchit.vim ==
runtime macros/matchit.vim

-- BTW, for the matchit help it is a little trickier: you could have a
symlink $VIM/latest pointing to the latest $VIMRUNTIME (currently
vim74a, but not so long ago it was vim73) and create a symlink
$VIM/vimfiles/doc/matchit.txt -> ../../latest/macros/matchit.txt --
don't forget to run :helptags on your $VIM/vimfiles/doc

The fact that at line 7, matchit.txt still says "For Vim version 6.3."
is not really an error: as $VIMRUNTIME/macros/matchit.vim tells us, that
plugin hasn't changed since Vim 6.3.



One possible way (untested, and among others) to know when global
plugins are loaded would be to have the following two one-line scripts:

== ~/.vim/plugin/A.vim ==
doau PluginStart

== ~/.vim/after/plugin/zzzzzzzz.vim ==
doau PluginEnd

(defining two new events). On Windows, replace /.vim/ by /vimfiles/, as
usual. Caveat: this particular trick does of course not work on Vim
executables compiled with -autocmd

>
> David

Best regards,
Tony.
--
A hard man is good to find.

--
--
You received this message from the "vim_use" 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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: