feat(plugin): added Plugin.cond. Fixes #89, #168

This commit is contained in:
Folke Lemaitre 2022-12-26 09:35:19 +01:00
parent 2f5c1be525
commit aed842ae1e
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
5 changed files with 12 additions and 1 deletions

View file

@ -121,6 +121,11 @@ function M.load(plugins, reason)
end
end
if try_load and plugin.cond then
try_load = plugin.cond == true or (type(plugin.cond) == "function" and plugin.cond()) or false
plugin._.cond = try_load
end
---@cast plugin LazyPlugin
if try_load and not plugin._.loaded then

View file

@ -18,6 +18,7 @@ local M = {}
---@field cloned? boolean
---@field kind? LazyPluginKind
---@field dep? boolean True if this plugin is only in the spec as a dependency
---@field cond? boolean
---@class LazyPluginHooks
---@field init? fun(LazyPlugin) Will always be run
@ -44,6 +45,7 @@ local M = {}
---@field url string?
---@field dir string
---@field enabled? boolean|(fun():boolean)
---@field cond? boolean|(fun():boolean)
---@field lazy? boolean
---@field dev? boolean If set, then link to the respective folder under your ~/projects
---@field dependencies? string[]

View file

@ -15,6 +15,7 @@ M.colors = {
fg = "#ff007c",
},
ProgressTodo = "LineNr",
NoCond = "DiagnosticError",
Special = "@punctuation.special",
HandlerRuntime = "@macro",
HandlerPlugin = "Special",

View file

@ -359,6 +359,8 @@ end
function M:plugin(plugin)
if plugin._.loaded then
self:append("", "LazySpecial"):append(plugin.name)
elseif plugin._.cond == false then
self:append("", "LazyNoCond"):append(plugin.name)
else
self:append("", "LazySpecial"):append(plugin.name)
end