I have an "optional" plugin that depends on python (pack/habamax/opt/myplugin
)
in my settings I have the following:
if has('python') || has('python3')
do some setup
packadd myplugin
endif
This thing fails if there is no myplugin though.
Is there a way I can add to an if statement to check if myplugin exists? if packexists('myplugin')
?
I can probably have a try catch
to suppress errors but the thing is that there might be elseif
:
" if there is package myplugin and all dependencies
if has('python') || has('python3')
do some setup
packadd myplugin
else
"use another plugin without dependencies
do some setup
packadd anotherplugin
endif
@Matt,
UPDATE
Thanks for the help.
I end up using silent! packadd ...
:
" try to load myplugin first
if has('python') || has('python3')
do some setup
silent! packadd myplugin
endif
"use another plugin without dependencies
if !exists("g:myplugin_loaded")
do some setup
packadd anotherplugin
endif
else
requirement by setting a flag ifpackadd
is successful, and loading your other plugin in anif
block that checks if the flag is set.try catch
in that case?packadd
does not throw an exception. So you have topackadd
and then additionally check if there'sloaded_myplugin
flag, orexists('smth')
, or whatever else.