Friday, March 4, 2016

Re: Packages

On 4 March 2016, Bram Moolenaar <Bram@moolenaar.net> wrote:
>
> Lcd wrote:
>
> > On 4 March 2016, Nikolay Aleksandrovich Pavlov <zyx.vim@gmail.com>
> > wrote:
> > > 2016-03-04 14:25 GMT+03:00 LCD 47 <lcd047@gmail.com>:
> > > > A tangentially related question. Assume I need to check
> > > > that a plugin named "foo" is installed and enabled. Assume also
> > > > "foo" contains
> > >
> > > If you need to check that it is installed and *enabled* then you
> > > should not do anything you are not already doing.
> >
> > So if
> >
> > globpath(&runtimepath, "autoload/foo.vim", 1) != ""
> >
> > returns true, I can assume "foo" is installed and enabled?
>
> If it was added with automatic mechanisms, yes. If the path appears
> in 'runtimepath' the related plugin would have been loaded. That is,
> after initialization (loading plugins) is done.
>
> This won't work if initialization hasn't finished yet.

I'm not worried about race conditions at startup. My plugin has a
modular structure itself, and tries to decide whether to enable each
module only when said module is used for the first time. The earliest
this can happen is when triggered from a BufRead, but it typically
happens much later. Startup race conditions have never been a problem.

The API of my plugin requires the test for "foo" to be done as a
separate operation. This excludes try / catch solutions, and changing
that would involve breaking all third party plugins that depend on the
API. Also the particular "foo" I have in mind is quite heavy. And
since plugins can't be unloaded, loading "foo" for no good reason would
be a really bad move. It's guaranteed to slow down everything a little
bit.

> This won't work if the user adds a directory to 'runtimepath' without
> loading the plugin.

I'm not really worried about that, either.

> The best way to avoid this kind of uncertainty is to set a global
> variable:
>
> let g:fooPluginLoaded = 1
>
> Or with the version, like what Charles uses:
>
> let g:loaded_netrwPlugin = "v155"
>
> Only then can you be 100% sure that the plugin was actually sourced.
[...]

Sadly, "foo" is a third party plugin and I have no control over it.
As it happens it does have a g:loaded_foo, but _that_ is initialised
only after "foo" is loaded. Not good. :(

/lcd

--
--
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/d/optout.

No comments: