mirror of
https://github.com/folke/lazy.nvim.git
synced 2025-06-28 11:24:14 +00:00
feat: LazyKeysBase Support opts and rhs_maker
opts, a table of key options for vim.keymap.set. rhs_maker, a function that returns a rhs. run after plugin loads, it could produce rhs dynamically.
This commit is contained in:
parent
16603c6917
commit
b1213d426f
2 changed files with 24 additions and 3 deletions
|
@ -8,6 +8,8 @@ local Util = require("lazy.core.util")
|
||||||
---@field expr? boolean
|
---@field expr? boolean
|
||||||
---@field nowait? boolean
|
---@field nowait? boolean
|
||||||
---@field ft? string|string[]
|
---@field ft? string|string[]
|
||||||
|
---@field rhs_maker? fun():string|fun()
|
||||||
|
---@field opts? table
|
||||||
|
|
||||||
---@class LazyKeysSpec: LazyKeysBase
|
---@class LazyKeysSpec: LazyKeysBase
|
||||||
---@field [1] string lhs
|
---@field [1] string lhs
|
||||||
|
@ -24,7 +26,7 @@ local Util = require("lazy.core.util")
|
||||||
---@class LazyKeysHandler:LazyHandler
|
---@class LazyKeysHandler:LazyHandler
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local skip = { mode = true, id = true, ft = true, rhs = true, lhs = true }
|
local skip = { mode = true, id = true, ft = true, rhs = true, lhs = true , opts=true, rhs_maker=true}
|
||||||
|
|
||||||
---@param value string|LazyKeysSpec
|
---@param value string|LazyKeysSpec
|
||||||
---@param mode? string
|
---@param mode? string
|
||||||
|
@ -94,6 +96,13 @@ function M.opts(keys)
|
||||||
opts[k] = v
|
opts[k] = v
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if keys.opts then
|
||||||
|
opts=vim.tbl_deep_extend("force",opts,keys.opts)
|
||||||
|
if opts.ft then
|
||||||
|
keys.ft=opts.ft
|
||||||
|
opts.ft=nil
|
||||||
|
end
|
||||||
|
end
|
||||||
return opts
|
return opts
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -114,7 +123,15 @@ function M:_add(keys)
|
||||||
if plugins then
|
if plugins then
|
||||||
local name = M.to_string(keys)
|
local name = M.to_string(keys)
|
||||||
Util.track({ keys = name })
|
Util.track({ keys = name })
|
||||||
Loader.load(plugins, { keys = name })
|
if keys.rhs_maker then
|
||||||
|
Loader.load(plugins, { keys = name }, nil, function()
|
||||||
|
keys.rhs=keys.rhs_maker()
|
||||||
|
keys.rhs_maker=nil
|
||||||
|
self:_set(keys, buf)
|
||||||
|
end)
|
||||||
|
else
|
||||||
|
Loader.load(plugins, { keys = name })
|
||||||
|
end
|
||||||
Util.track()
|
Util.track()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -167,7 +167,8 @@ end
|
||||||
---@param plugins string|LazyPlugin|string[]|LazyPlugin[]
|
---@param plugins string|LazyPlugin|string[]|LazyPlugin[]
|
||||||
---@param reason {[string]:string}
|
---@param reason {[string]:string}
|
||||||
---@param opts? {force:boolean} when force is true, we skip the cond check
|
---@param opts? {force:boolean} when force is true, we skip the cond check
|
||||||
function M.load(plugins, reason, opts)
|
---@param afterload? function a function that runs after load
|
||||||
|
function M.load(plugins, reason, opts, afterload)
|
||||||
---@diagnostic disable-next-line: cast-local-type
|
---@diagnostic disable-next-line: cast-local-type
|
||||||
plugins = (type(plugins) == "string" or plugins.name) and { plugins } or plugins
|
plugins = (type(plugins) == "string" or plugins.name) and { plugins } or plugins
|
||||||
---@cast plugins (string|LazyPlugin)[]
|
---@cast plugins (string|LazyPlugin)[]
|
||||||
|
@ -185,6 +186,9 @@ function M.load(plugins, reason, opts)
|
||||||
end
|
end
|
||||||
if plugin and not plugin._.loaded then
|
if plugin and not plugin._.loaded then
|
||||||
M._load(plugin, reason, opts)
|
M._load(plugin, reason, opts)
|
||||||
|
if afterload then
|
||||||
|
afterload()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue