diff --git a/README.md b/README.md index 4d26ae2..0dfc7c6 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ require("lazy").setup({ | **dev** | `boolean?` | When `true`, a local plugin directory will be used instead. See `config.dev` | | **lazy** | `boolean?` | When `true`, the plugin will only be loaded when needed. Lazy-loaded plugins are automatically loaded when their Lua modules are `required`, or when one of the lazy-loading handlers triggers | | **enabled** | `boolean?` or `fun():boolean` | When `false`, or if the `function` returns false, then this plugin will not be included in the spec | -| **cond** | `boolean?` or `fun():boolean` | When `false`, or if the `function` returns false, then this plugin will not be loaded. Useful to disable some plugins in vscode, or firenvim for example. | +| **cond** | `boolean?` or `fun(LazyPlugin):boolean` | When `false`, or if the `function` returns false, then this plugin will not be loaded. Useful to disable some plugins in vscode, or firenvim for example. | | **dependencies** | `LazySpec[]` | A list of plugin names or plugin specs that should be loaded when the plugin loads. Dependencies are always lazy-loaded unless specified otherwise. When specifying a name, make sure the plugin spec has been defined somewhere else. | | **init** | `fun(LazyPlugin)` | `init` functions are always executed during startup | | **opts** | `table` or `fun(LazyPlugin, opts:table)` | `opts` should be a table (will be merged with parent specs), return a table (replaces parent specs) or should change a table. The table will be passed to the `Plugin.config()` function. Setting this value will imply `Plugin.config()` | @@ -303,6 +303,9 @@ return { defaults = { lazy = false, -- should plugins be lazy-loaded? version = nil, + -- default `cond` you can use to globally disable a lot of plugins + -- when running inside vscode for example + cond = nil, ---@type boolean|fun(self:LazyPlugin):boolean|nil -- version = "*", -- enable this to try installing the latest stable versions of plugins }, -- leave nil when passing the spec as the first argument to setup() diff --git a/lua/lazy/core/config.lua b/lua/lazy/core/config.lua index 5b43d72..043cac8 100644 --- a/lua/lazy/core/config.lua +++ b/lua/lazy/core/config.lua @@ -9,6 +9,9 @@ M.defaults = { defaults = { lazy = false, -- should plugins be lazy-loaded? version = nil, + -- default `cond` you can use to globally disable a lot of plugins + -- when running inside vscode for example + cond = nil, ---@type boolean|fun(self:LazyPlugin):boolean|nil -- version = "*", -- enable this to try installing the latest stable versions of plugins }, -- leave nil when passing the spec as the first argument to setup() diff --git a/lua/lazy/core/loader.lua b/lua/lazy/core/loader.lua index 6ac898c..118a61f 100644 --- a/lua/lazy/core/loader.lua +++ b/lua/lazy/core/loader.lua @@ -266,8 +266,12 @@ function M._load(plugin, reason, opts) return Util.error("Plugin " .. plugin.name .. " is not installed") end - if plugin.cond ~= nil and not (opts and opts.force) then - if plugin.cond == false or (type(plugin.cond) == "function" and not plugin.cond()) then + local cond = plugin.cond + if cond == nil then + cond = Config.options.defaults.cond + end + if cond ~= nil and not (opts and opts.force) then + if cond == false or (type(cond) == "function" and not cond(plugin)) then plugin._.cond = false return end