updates
This commit is contained in:
12
lua/utils/keymaps/converters/from_table/init.lua
Normal file
12
lua/utils/keymaps/converters/from_table/init.lua
Normal file
@@ -0,0 +1,12 @@
|
||||
local M = {}
|
||||
local map = vim.keymap.set
|
||||
local opts = { noremap = true, silent = true }
|
||||
|
||||
function M.set_keybindings(bindings)
|
||||
for _, binding in ipairs(bindings) do
|
||||
map(binding.mode, binding.key, binding.cmd, binding.opts or opts)
|
||||
end
|
||||
return bindings
|
||||
end
|
||||
|
||||
return M
|
||||
48
lua/utils/keymaps/converters/whichkey/init.lua
Normal file
48
lua/utils/keymaps/converters/whichkey/init.lua
Normal file
@@ -0,0 +1,48 @@
|
||||
local M = {}
|
||||
|
||||
local whichkey = require("which-key")
|
||||
vim.notify = require("notify")
|
||||
|
||||
---Helper function to add mappings to which-key
|
||||
---@parm mappings table : List of mappings to add to which-key
|
||||
---@parm group table : Group to add mappings to (optional)
|
||||
---@return nil
|
||||
---@usage addToWhichKey(mappings, group)
|
||||
---@example addToWhichKey({{key = "n", cmd = "next", mode = "n", desc = "Next Line", group = "Navigation"}, {key = "t", group = "example"})
|
||||
function M.addToWhichKey(mappings, group)
|
||||
local wk_mappings = {}
|
||||
if group then
|
||||
whichkey.add({ group.key, group = group.group })
|
||||
end
|
||||
if not mappings and not group then
|
||||
vim.notify("Error: Mappings is nil", "error")
|
||||
return
|
||||
elseif not mappings and group then
|
||||
return
|
||||
end
|
||||
for _, mapping in ipairs(mappings) do
|
||||
if not mapping.key or mapping.key == "" then
|
||||
vim.notify("Error: Key is empty or nil", "error")
|
||||
return
|
||||
end
|
||||
|
||||
if not mapping.cmd or mapping.cmd == "" then
|
||||
vim.notify("Error: Command is empty or nil for key: " .. mapping.key, "error")
|
||||
return
|
||||
end
|
||||
|
||||
if not mapping.mode or mapping.mode == "" then
|
||||
vim.notify("Error: Mode is empty or nil for key: " .. mapping.key, "error")
|
||||
return
|
||||
end
|
||||
|
||||
wk_mappings[1] = mapping.key
|
||||
wk_mappings[2] = mapping.cmd
|
||||
wk_mappings.mode = mapping.mode
|
||||
wk_mappings.desc = mapping.desc or "No Description"
|
||||
wk_mappings.group = mapping.group or "No Group"
|
||||
whichkey.add(wk_mappings)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
4
lua/utils/keymaps/init.lua
Normal file
4
lua/utils/keymaps/init.lua
Normal file
@@ -0,0 +1,4 @@
|
||||
return {
|
||||
require('utils.keymaps.converters.whichkey'),
|
||||
require('utils.keymaps.converters.from_table'),
|
||||
}
|
||||
Reference in New Issue
Block a user