2022-07-29 04:27:06 +00:00
|
|
|
local M = {}
|
|
|
|
|
2024-06-02 02:27:39 +00:00
|
|
|
---@diagnostic disable: undefined-field
|
|
|
|
|
2022-07-29 04:27:06 +00:00
|
|
|
M.create_plug_maps = function(bufnr, plug_bindings)
|
|
|
|
for _, binding in ipairs(plug_bindings) do
|
2023-10-10 15:58:38 +00:00
|
|
|
vim.keymap.set(
|
|
|
|
"",
|
|
|
|
binding.plug,
|
|
|
|
binding.rhs,
|
|
|
|
{ buffer = bufnr, desc = binding.desc, nowait = true }
|
|
|
|
)
|
2022-07-29 04:27:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
---@param bufnr number
|
|
|
|
---@param mode string
|
2023-02-03 13:08:21 +00:00
|
|
|
---@param bindings table<string, string|table>
|
2022-07-29 04:27:06 +00:00
|
|
|
---@param prefix string
|
|
|
|
M.create_maps_to_plug = function(bufnr, mode, bindings, prefix)
|
|
|
|
local maps
|
|
|
|
if mode == "i" then
|
|
|
|
maps = vim.api.nvim_buf_get_keymap(bufnr, "")
|
|
|
|
end
|
|
|
|
for lhs, rhs in pairs(bindings) do
|
|
|
|
if rhs then
|
2023-10-10 15:58:38 +00:00
|
|
|
local opts = { buffer = bufnr, remap = true, nowait = true }
|
2023-02-03 13:08:21 +00:00
|
|
|
if type(rhs) == "table" then
|
|
|
|
for k, v in pairs(rhs) do
|
|
|
|
if type(k) == "string" then
|
|
|
|
opts[k] = v
|
|
|
|
elseif k == 1 then
|
|
|
|
rhs = v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-07-29 04:27:06 +00:00
|
|
|
-- Prefix with <Plug> unless this is a <Cmd> or :Cmd mapping
|
2024-08-18 18:08:49 +00:00
|
|
|
if type(rhs) == "string" then
|
|
|
|
if not rhs:match("[<:]") then
|
2024-08-18 18:11:13 +00:00
|
|
|
rhs = "<Plug>" .. prefix .. rhs .. "<CR>"
|
|
|
|
else
|
|
|
|
rhs = rhs .. "<CR>"
|
2024-08-18 18:08:49 +00:00
|
|
|
end
|
|
|
|
if mode == "i" then
|
|
|
|
rhs = "<C-o>" .. rhs
|
2022-07-29 04:27:06 +00:00
|
|
|
end
|
|
|
|
end
|
2024-08-18 18:08:49 +00:00
|
|
|
|
2023-08-13 08:20:15 +00:00
|
|
|
---@cast rhs string
|
2023-02-03 13:08:21 +00:00
|
|
|
vim.keymap.set(mode, lhs, rhs, opts)
|
2022-07-29 04:27:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return M
|