From db6e93c48df551e2906c9e0f4472f9e54cea3dd9 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Mon, 1 Aug 2022 15:35:08 +0200 Subject: feat(api): add replace_keycodes to nvim_set_keymap (#19598) --- runtime/lua/vim/keymap.lua | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) (limited to 'runtime/lua/vim/keymap.lua') diff --git a/runtime/lua/vim/keymap.lua b/runtime/lua/vim/keymap.lua index f4c2b507a9..3592855606 100644 --- a/runtime/lua/vim/keymap.lua +++ b/runtime/lua/vim/keymap.lua @@ -42,11 +42,10 @@ local keymap = {} --- listed in |nvim_set_keymap()|, this table also accepts the following keys: --- - buffer: (number or boolean) Add a mapping to the given buffer. When "true" --- or 0, use the current buffer. ---- - replace_keycodes: (boolean, default true) When both this and expr is "true", ---- |nvim_replace_termcodes()| is applied to the result of Lua expr maps. --- - remap: (boolean) Make the mapping recursive. This is the --- inverse of the "noremap" option from |nvim_set_keymap()|. --- Default `false`. +--- - replace_keycodes: (boolean) defaults to true. ---@see |nvim_set_keymap()| function keymap.set(mode, lhs, rhs, opts) vim.validate({ @@ -60,22 +59,9 @@ function keymap.set(mode, lhs, rhs, opts) local is_rhs_luaref = type(rhs) == 'function' mode = type(mode) == 'string' and { mode } or mode - if is_rhs_luaref and opts.expr then - local user_rhs = rhs - rhs = function() - local res = user_rhs() - if res == nil then - -- TODO(lewis6991): Handle this in C? - return '' - elseif opts.replace_keycodes ~= false then - return vim.api.nvim_replace_termcodes(res, true, true, true) - else - return res - end - end + if opts.expr and opts.replace_keycodes ~= false then + opts.replace_keycodes = true end - -- clear replace_keycodes from opts table - opts.replace_keycodes = nil if opts.remap == nil then -- default remap value is false -- cgit From 0a049c322fda5f2bb124429086c2713ff99c7142 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 2 Aug 2022 11:13:22 +0800 Subject: test: improve mapping tests and docs (#19619) --- runtime/lua/vim/keymap.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'runtime/lua/vim/keymap.lua') diff --git a/runtime/lua/vim/keymap.lua b/runtime/lua/vim/keymap.lua index 3592855606..0549f63180 100644 --- a/runtime/lua/vim/keymap.lua +++ b/runtime/lua/vim/keymap.lua @@ -31,12 +31,10 @@ local keymap = {} --- vim.keymap.set('n', 'asdf', function() return require('jkl').my_fun() end) --- --- ----@param mode string|table Same mode short names as |nvim_set_keymap()|. +---@param mode string|table Same mode short names as |nvim_set_keymap()|. --- Can also be list of modes to create mapping on multiple modes. ----@param lhs string Left-hand side |{lhs}| of the mapping. +---@param lhs string Left-hand side |{lhs}| of the mapping. ---@param rhs string|function Right-hand side |{rhs}| of the mapping. Can also be a Lua function. ---- If a Lua function and `opts.expr == true`, returning `nil` is ---- equivalent to an empty string. -- ---@param opts table A table of |:map-arguments| such as "silent". In addition to the options --- listed in |nvim_set_keymap()|, this table also accepts the following keys: -- cgit From b8dcbcc732baf84fc48d6b272c3ade0bcb129b3b Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 3 Aug 2022 03:47:16 +0200 Subject: docs: fix typos (#19588) Co-authored-by: zeertzjq Co-authored-by: notomo --- runtime/lua/vim/keymap.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/lua/vim/keymap.lua') diff --git a/runtime/lua/vim/keymap.lua b/runtime/lua/vim/keymap.lua index 0549f63180..7265beb56b 100644 --- a/runtime/lua/vim/keymap.lua +++ b/runtime/lua/vim/keymap.lua @@ -43,7 +43,7 @@ local keymap = {} --- - remap: (boolean) Make the mapping recursive. This is the --- inverse of the "noremap" option from |nvim_set_keymap()|. --- Default `false`. ---- - replace_keycodes: (boolean) defaults to true. +--- - replace_keycodes: (boolean) defaults to true if "expr" is true. ---@see |nvim_set_keymap()| function keymap.set(mode, lhs, rhs, opts) vim.validate({ -- cgit