From d217ffa0b6f37d64996ba9fb66cd196108e71169 Mon Sep 17 00:00:00 2001 From: Squibid Date: Thu, 24 Apr 2025 14:38:25 -0500 Subject: [PATCH] make dep only require nvim 0.8, and make the lazy utils better --- lua/dep.lua | 4 ++-- lua/dep/log.lua | 2 +- lua/dep/package.lua | 2 +- lua/lazy/utils.lua | 28 +++++++++++++++++++--------- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/lua/dep.lua b/lua/dep.lua index 1b63ed5..098eff4 100644 --- a/lua/dep.lua +++ b/lua/dep.lua @@ -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)) diff --git a/lua/dep/log.lua b/lua/dep/log.lua index a7a49ab..a127d77 100644 --- a/lua/dep/log.lua +++ b/lua/dep/log.lua @@ -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 diff --git a/lua/dep/package.lua b/lua/dep/package.lua index 918d5c1..17f87b6 100644 --- a/lua/dep/package.lua +++ b/lua/dep/package.lua @@ -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 diff --git a/lua/lazy/utils.lua b/lua/lazy/utils.lua index 8dc960e..2551926 100644 --- a/lua/lazy/utils.lua +++ b/lua/lazy/utils.lua @@ -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()