packer.nvim icon indicating copy to clipboard operation
packer.nvim copied to clipboard

Suppress "config" until the plugin is installed

Open kyoh86 opened this issue 2 years ago • 4 comments

Describe the feature

If config is called while a plugin specified by packer is not yet installed, it usually results in a "module not found" error because the plugin is required inside. I understand that calling PackerInstall or PackerSync will resolve this. However, I often encounter this error when I start neovim for the first time with init.vim from my dotfiles repository in a brand new environment, or when I copy and paste some plugin configuration (often written as a template in the README, etc.) and it irritates me. Is it possible to prevent config functions from being called for plugins that are not yet installed?

kyoh86 avatar Nov 07 '22 16:11 kyoh86

It could be a callback that would be called once all the plugins are installed (just like how the config callback is for individual plugins).

utilyre avatar Dec 14 '22 20:12 utilyre

I think this error should only happen when you PackerCompile without a PackerInstall first so you should just do that

max397574 avatar Dec 14 '22 20:12 max397574

I think this error should only happen when you PackerCompile without a PackerInstall first so you should just do that

Yeah, I could do that. Although what I'm looking to achieve is keeping the sequence that config files are required and not getting errors on a fresh install.

utilyre avatar Dec 14 '22 21:12 utilyre

As a workaround, I make packer_bootstrap from the README a global variable (rather than local) and wrap my config parameters in this mess:

use {
    'lewis6991/gitsigns.nvim',
    requires = 'nvim-lua/plenary.nvim',
    config = function() if not packer_bootstrap then
        require('gitsigns').setup()
    end end
}

This at least allows a fresh startup to complete installing everything, without attempting to run the configure hooks.

callahad avatar Dec 14 '22 21:12 callahad