From 1efa710210ded9677dce8ceb523e08e133c10e1f Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Mon, 19 Dec 2022 14:56:43 +0100 Subject: [PATCH] feat: added `module=false` to skip auto-loading of plugins on `require` --- README.md | 3 +++ lua/lazy/core/loader.lua | 2 +- lua/lazy/core/plugin.lua | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dd5922ac..4c26b296 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,9 @@ module of plugin `A`, then plugin `A` will be loaded on demand as expected. You can configure **lazy.nvim** to lazy-load all plugins by default with `config.defaults.lazy = true`. +If you don't want this behavior for a certain plugin, you can specify that with `module=false`. +You can then manually load the plugin with `:Lazy load foobar.nvim`. + Additionally, you can also lazy-load on **events**, **commands**, **file types** and **key mappings**. diff --git a/lua/lazy/core/loader.lua b/lua/lazy/core/loader.lua index 741c2afb..bd11ea8c 100644 --- a/lua/lazy/core/loader.lua +++ b/lua/lazy/core/loader.lua @@ -194,7 +194,7 @@ end function M.autoload(modname) -- check if a lazy plugin should be loaded for _, plugin in pairs(Config.plugins) do - if not plugin._.loaded then + if not (plugin._.loaded or plugin.module == false) then for _, pattern in ipairs({ ".lua", "/init.lua" }) do local path = plugin.dir .. "/lua/" .. modname:gsub("%.", "/") .. pattern if vim.loop.fs_stat(path) then diff --git a/lua/lazy/core/plugin.lua b/lua/lazy/core/plugin.lua index ee6558c3..39598b94 100644 --- a/lua/lazy/core/plugin.lua +++ b/lua/lazy/core/plugin.lua @@ -26,6 +26,7 @@ local M = {} ---@field cmd? string[] ---@field ft? string[] ---@field keys? string[] +---@field module? false ---@class LazyPluginRef ---@field branch? string