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

@ -38,7 +38,7 @@ function M.registertree(speclist, overrides)
-- if erroring print out the spec and the error
if not ok then
error(string.format("%s (spec=%s)", err, vim.inspect(spec)))
error(string.format("(spec=%s)", vim.inspect(spec)))
end
end
end
@ -226,7 +226,7 @@ return function(opts)
local fullpath = vim.api.nvim_call_function(
'fnamemodify', { fname, ':p' })
w:start(fullpath, {}, vim.schedule_wrap(function(...)
vim.api.nvim_command('checktime')
vim.cmd('checktime')
w:stop()
watch_file(fname)
end))

View File

@ -18,7 +18,7 @@ local function default_log_path()
vim.loop.fs_mkdir(path, 0x1ff) -- 0777
end
return vim.fs.joinpath(path, "/dep.log")
return vim.fs.normalize(path).."/dep.log"
end
--- attempt to format a string

View File

@ -331,7 +331,7 @@ end
--- set the base directory for packages
---@param _base_dir string base directory
function package.set_base_dir(_base_dir)
base_dir = _base_dir
base_dir = vim.fs.normalize(_base_dir)
end
--- get the base directory for packages

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()