nvim - support functions as keymap bindings in utils module

This commit is contained in:
2025-05-21 14:05:48 -05:00
parent 240abfc7f6
commit ed89606f4e
2 changed files with 20 additions and 6 deletions

View File

@@ -1,12 +1,18 @@
(local a (require :nfnl.core))
(fn fn? [x]
(= :function (type x)))
(fn noremap [mode from to opts]
(let [map-opts {:noremap true :silent true}
to (.. ":" to :<cr>)
to (if (fn? to)
to
(.. ":" to :<cr>))
buff-num (a.get opts :buff-num)]
(if (or (a.get opts :local?) buff-num)
(vim.api.nvim_buf_set_keymap (or buff-num 0) mode from to map-opts)
(vim.api.nvim_set_keymap mode from to map-opts))))
(vim.keymap.set mode from to
(a.merge map-opts {:buffer (or buff-num 0)}))
(vim.keymap.set mode from to map-opts))))
(fn nnoremap [from to opts] (noremap :n from to opts))

View File

@@ -1,13 +1,21 @@
-- [nfnl] fnl/dotfiles/util.fnl
local a = require("nfnl.core")
local function fn_3f(x)
return ("function" == type(x))
end
local function noremap(mode, from, to, opts)
local map_opts = {noremap = true, silent = true}
local to0 = (":" .. to .. "<cr>")
local to0
if fn_3f(to) then
to0 = to
else
to0 = (":" .. to .. "<cr>")
end
local buff_num = a.get(opts, "buff-num")
if (a.get(opts, "local?") or buff_num) then
return vim.api.nvim_buf_set_keymap((buff_num or 0), mode, from, to0, map_opts)
return vim.keymap.set(mode, from, to0, a.merge(map_opts, {buffer = (buff_num or 0)}))
else
return vim.api.nvim_set_keymap(mode, from, to0, map_opts)
return vim.keymap.set(mode, from, to0, map_opts)
end
end
local function nnoremap(from, to, opts)