wbthomason / packer.nvim

A use-package inspired plugin manager for Neovim. Uses native packages, supports Luarocks dependencies, written in Lua, allows for expressive config
MIT License
7.72k stars 262 forks source link

Suppress "config" until the plugin is installed #1120

Open kyoh86 opened 1 year ago

kyoh86 commented 1 year ago

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?

utilyre commented 1 year ago

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).

max397574 commented 1 year ago

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

utilyre commented 1 year ago

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.

callahad commented 1 year ago

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.