mirror of
https://github.com/stevenproctor/dotfiles.git
synced 2026-01-28 08:39:56 -06:00
nvim - support functions as keymap bindings in utils module
This commit is contained in:
@@ -1,12 +1,18 @@
|
|||||||
(local a (require :nfnl.core))
|
(local a (require :nfnl.core))
|
||||||
|
|
||||||
|
(fn fn? [x]
|
||||||
|
(= :function (type x)))
|
||||||
|
|
||||||
(fn noremap [mode from to opts]
|
(fn noremap [mode from to opts]
|
||||||
(let [map-opts {:noremap true :silent true}
|
(let [map-opts {:noremap true :silent true}
|
||||||
to (.. ":" to :<cr>)
|
to (if (fn? to)
|
||||||
|
to
|
||||||
|
(.. ":" to :<cr>))
|
||||||
buff-num (a.get opts :buff-num)]
|
buff-num (a.get opts :buff-num)]
|
||||||
(if (or (a.get opts :local?) 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.keymap.set mode from to
|
||||||
(vim.api.nvim_set_keymap mode from to map-opts))))
|
(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))
|
(fn nnoremap [from to opts] (noremap :n from to opts))
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,21 @@
|
|||||||
-- [nfnl] fnl/dotfiles/util.fnl
|
-- [nfnl] fnl/dotfiles/util.fnl
|
||||||
local a = require("nfnl.core")
|
local a = require("nfnl.core")
|
||||||
|
local function fn_3f(x)
|
||||||
|
return ("function" == type(x))
|
||||||
|
end
|
||||||
local function noremap(mode, from, to, opts)
|
local function noremap(mode, from, to, opts)
|
||||||
local map_opts = {noremap = true, silent = true}
|
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")
|
local buff_num = a.get(opts, "buff-num")
|
||||||
if (a.get(opts, "local?") or buff_num) then
|
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
|
else
|
||||||
return vim.api.nvim_set_keymap(mode, from, to0, map_opts)
|
return vim.keymap.set(mode, from, to0, map_opts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local function nnoremap(from, to, opts)
|
local function nnoremap(from, to, opts)
|
||||||
|
|||||||
Reference in New Issue
Block a user