diff options
author | ii14 <59243201+ii14@users.noreply.github.com> | 2022-08-01 15:35:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-01 21:35:08 +0800 |
commit | db6e93c48df551e2906c9e0f4472f9e54cea3dd9 (patch) | |
tree | a62b94332e6f23a49adce724759a4c23edf7cf03 /runtime | |
parent | 9f5d5aa3da30aab40bbb38fddfc70257444d50a8 (diff) | |
download | rneovim-db6e93c48df551e2906c9e0f4472f9e54cea3dd9.tar.gz rneovim-db6e93c48df551e2906c9e0f4472f9e54cea3dd9.tar.bz2 rneovim-db6e93c48df551e2906c9e0f4472f9e54cea3dd9.zip |
feat(api): add replace_keycodes to nvim_set_keymap (#19598)
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/doc/api.txt | 4 | ||||
-rw-r--r-- | runtime/doc/lua.txt | 5 | ||||
-rw-r--r-- | runtime/lua/vim/keymap.lua | 20 |
3 files changed, 7 insertions, 22 deletions
diff --git a/runtime/doc/api.txt b/runtime/doc/api.txt index 1426404da9..aaafa21a59 100644 --- a/runtime/doc/api.txt +++ b/runtime/doc/api.txt @@ -1508,7 +1508,9 @@ nvim_set_keymap({mode}, {lhs}, {rhs}, {*opts}) *nvim_set_keymap()* used to give a description to the mapping. When called from Lua, also accepts a "callback" key that takes a Lua function to call when the mapping - is executed. + is executed. "replace_keycodes" can be used with + "expr" to replace keycodes, see + |nvim_replace_termcodes()|. nvim_set_var({name}, {value}) *nvim_set_var()* Sets a global (g:) variable. diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt index 3302a00b6a..6dfb0b5791 100644 --- a/runtime/doc/lua.txt +++ b/runtime/doc/lua.txt @@ -2228,13 +2228,10 @@ set({mode}, {lhs}, {rhs}, {opts}) *vim.keymap.set()* • 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 also: ~ |nvim_set_keymap()| 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 |