Skip to content

Commit aed842a

Browse files
committed
feat(plugin): added Plugin.cond. Fixes #89, #168
1 parent 2f5c1be commit aed842a

File tree

5 files changed

+12
-1
lines changed

5 files changed

+12
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ require("lazy").setup({
8787
| **name** | `string?` | A custom name for the plugin used for the local plugin directory and as the display name |
8888
| **dev** | `boolean?` | When `true`, a local plugin directory will be used instead. See `config.dev` |
8989
| **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 |
90-
| **enabled** | `boolean?` or `fun():boolean` | When `false`, or if the `function` returns false, then this plugin will not be used |
90+
| **enabled** | `boolean?` or `fun():boolean` | When `false`, or if the `function` returns false, then this plugin will not be included in the spec |
91+
| **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. |
9192
| **dependencies** | `LazySpec[]` | A list of plugin specs that should be loaded when the plugin loads. Dependencies are always lazy-loaded unless specified otherwise |
9293
| **init** | `fun(LazyPlugin)` | `init` functions are always executed during startup |
9394
| **config** | `fun(LazyPlugin)` or `true` or `table` | `config` is executed when the plugin loads. You can also set to `true` or pass a `table`, that will be passed to `require("plugin").setup(opts)` |

lua/lazy/core/loader.lua

+5
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ function M.load(plugins, reason)
121121
end
122122
end
123123

124+
if try_load and plugin.cond then
125+
try_load = plugin.cond == true or (type(plugin.cond) == "function" and plugin.cond()) or false
126+
plugin._.cond = try_load
127+
end
128+
124129
---@cast plugin LazyPlugin
125130

126131
if try_load and not plugin._.loaded then

lua/lazy/core/plugin.lua

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ local M = {}
1818
---@field cloned? boolean
1919
---@field kind? LazyPluginKind
2020
---@field dep? boolean True if this plugin is only in the spec as a dependency
21+
---@field cond? boolean
2122

2223
---@class LazyPluginHooks
2324
---@field init? fun(LazyPlugin) Will always be run
@@ -44,6 +45,7 @@ local M = {}
4445
---@field url string?
4546
---@field dir string
4647
---@field enabled? boolean|(fun():boolean)
48+
---@field cond? boolean|(fun():boolean)
4749
---@field lazy? boolean
4850
---@field dev? boolean If set, then link to the respective folder under your ~/projects
4951
---@field dependencies? string[]

lua/lazy/view/colors.lua

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ M.colors = {
1515
fg = "#ff007c",
1616
},
1717
ProgressTodo = "LineNr",
18+
NoCond = "DiagnosticError",
1819
Special = "@punctuation.special",
1920
HandlerRuntime = "@macro",
2021
HandlerPlugin = "Special",

lua/lazy/view/render.lua

+2
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ end
359359
function M:plugin(plugin)
360360
if plugin._.loaded then
361361
self:append("", "LazySpecial"):append(plugin.name)
362+
elseif plugin._.cond == false then
363+
self:append("", "LazyNoCond"):append(plugin.name)
362364
else
363365
self:append("", "LazySpecial"):append(plugin.name)
364366
end

0 commit comments

Comments
 (0)