actually fixed reloading

This commit is contained in:
iris committed 2022-08-03 14:53:35 -04:00
1 parent ea0cdc2c9e
commit b2b8e5f539
7 files changed
+56 -32

No files matched your search

+33 -8
View File
@@ -1,20 +1,45 @@
local opts = { noremap = true, silent = true }
local utils = {}
utils.map = function(mode, from, to) vim.keymap.set(mode, from, to, opts) end
utils.nmap = function(from, to) vim.keymap.set('n', from, to, opts) end
utils.cmd = function(content) return '<cmd>' .. content .. '<cr>' end
-- mapping
local mapping = {}
mapping.map = function(mode, from, to) vim.keymap.set(mode, from, to, opts) end
mapping.nmap = function(from, to) vim.keymap.set('n', from, to, opts) end
mapping.cmd = function(content) return '<cmd>' .. content .. '<cr>' end
-- layout (mapping)
local layout = {}
layout.map = function(from, to)
vim.keymap.set('n', from, to, opts)
vim.keymap.set('x', from, to, opts)
end
layout.swap = function(a, b)
utils.layout.map(a, b)
utils.layout.map(b, a)
layout.map(a, b)
layout.map(b, a)
end
utils.layout = layout
mapping.layout = layout
return utils
-- loading stuff
local load = {}
load.post_write = function(group, path, fn)
vim.api.nvim_create_autocmd('BufWritePost', {
group = group,
pattern = '**/lua/config/' .. path,
callback = fn,
})
end
load.unload = function(mod) package.loaded[mod] = nil end
load.reload = function(mod) load.unload(mod) require(mod) end
--- @param path string
load.path_for = function(path)
local i = path:find("lua/config/")
if i == nil then return nil end
local mod = path:sub(i + 4):gsub("/", "."):sub(0, -5)
return mod
end
return {
mapping = mapping,
layout = layout,
load = load,
}