junegunn / vim-plug

:hibiscus: Minimalist Vim Plugin Manager
https://junegunn.github.io/vim-plug/
MIT License
33.89k stars 1.9k forks source link

Generic On-Demand Loading #1232

Closed igbanam closed 5 months ago

igbanam commented 1 year ago

We currently have on-demand loading for Plug triggers and for filetypes. I think it may be beneficial to have some generic on-demand loading.

Usage would be something like so

vim9script

# snipped ✂️  for brevity

Plug 'igbanam/bob.vim', { 'when': 'InBazelProject' }

def g:InBazelProject(): bool
  # function body ... snipped ✂️ 
enddef

This is just one example. Ideally, people should be able to craft any set of preconditions to load a plugin. The only requirement maybe could be that the function referenced in the 'when' clause must meet two strict requirements

  1. Must receive no arguments
  2. Must be global — i.e. g:FuncName
  3. Must return a bool

 


junegunn commented 5 months ago

When should vim-plug call the function? For that to work, vim-plug needs to call the function on every Vim event, and that is neither possible nor practical.

To load a plugin on a custom event, see https://github.com/junegunn/vim-plug/wiki/tips#loading-plugins-manually