make dep only require nvim 0.8, and make the lazy utils better

This commit is contained in:
2025-04-24 14:38:25 -05:00
parent 296dc11c93
commit d217ffa0b6
4 changed files with 23 additions and 13 deletions

View File

@ -54,6 +54,7 @@ function lazy:auto(event, opts)
self:cleanup()
end
-- create the auto command and save it
table.insert(self.auto_ids, vim.api.nvim_create_autocmd(event, opts))
end
@ -63,12 +64,21 @@ end
---@param opts vim.keymap.set.Opts? options
function lazy:keymap(mode, bind, opts)
opts = opts or {}
-- move the rerun arg to a seperate variable because keymap.set doesn't like
-- options it doesn't know of
local rerun = opts['rerun'] or true
opts['rerun'] = nil
vim.keymap.set(mode, bind, opts['callback'] or function()
-- register keymap unload
self:cleanup()
-- register keymap unload
local keys = vim.api.nvim_replace_termcodes(bind, true, false, true)
vim.api.nvim_feedkeys(keys, mode, false)
-- call the keymap after the user has mapped it
if rerun then
local keys = vim.api.nvim_replace_termcodes(bind, true, false, true)
vim.api.nvim_input(keys)
end
end, opts)
table.insert(self.keybind_ids, { ['mode'] = mode, ['bind'] = bind })
@ -77,16 +87,16 @@ end
--- cleanup all the callbacks, and load the plugin
function lazy:cleanup()
-- cleanup user commands
for _, v in pairs(self.command_ids) do
vim.api.nvim_del_user_command(v)
for _, command_id in pairs(self.command_ids) do
vim.api.nvim_del_user_command(command_id)
end
-- cleanup auto commands
for _, v in pairs(self.auto_ids) do
vim.api.nvim_del_autocmd(v)
for _, auto_id in pairs(self.auto_ids) do
vim.api.nvim_del_autocmd(auto_id)
end
-- cleanup keymaps
for _, v in pairs(self.keybind_ids) do
vim.keymap.del(v['mode'], v['bind'], {})
for _, keybind_id in pairs(self.keybind_ids) do
vim.keymap.del(keybind_id.mode, keybind_id.bind, {})
end
-- load the plugin
self:load()