A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/neovim/neovim/commit/58140a94283b1c6e45099c89e66a0c94e9d90931 below:

return nil from an expr keymap · neovim/neovim@58140a9 · GitHub

File tree Expand file treeCollapse file tree 2 files changed

+15

-3

lines changed

Filter options

Expand file treeCollapse file tree 2 files changed

+15

-3

lines changed Original file line number Diff line number Diff line change

@@ -2007,7 +2007,9 @@ set({mode}, {lhs}, {rhs}, {opts}) *vim.keymap.set()*

2007 2007

create mapping on multiple modes.

2008 2008

{lhs} string Left-hand side |{lhs}| of the mapping.

2009 2009

{rhs} string|function Right-hand side |{rhs}| of the

2010 -

mapping. Can also be a Lua function.

2010 +

mapping. Can also be a Lua function. If a Lua

2011 +

function and `opts.expr == true`, returning `nil`

2012 +

or `false` is equivalent to an empty string.

2011 2013

{opts} table A table of |:map-arguments| such as

2012 2014

"silent". In addition to the options listed in

2013 2015

|nvim_set_keymap()|, this table also accepts the

Original file line number Diff line number Diff line change

@@ -35,6 +35,8 @@ local keymap = {}

35 35

--- Can also be list of modes to create mapping on multiple modes.

36 36

---@param lhs string Left-hand side |{lhs}| of the mapping.

37 37

---@param rhs string|function Right-hand side |{rhs}| of the mapping. Can also be a Lua function.

38 +

--- If a Lua function and `opts.expr == true`, returning `nil` or `false`

39 +

--- is equivalent to an empty string.

38 40

--

39 41

---@param opts table A table of |:map-arguments| such as "silent". In addition to the options

40 42

--- listed in |nvim_set_keymap()|, this table also accepts the following keys:

@@ -56,10 +58,18 @@ function keymap.set(mode, lhs, rhs, opts)

56 58

local is_rhs_luaref = type(rhs) == "function"

57 59

mode = type(mode) == 'string' and {mode} or mode

58 60 59 -

if is_rhs_luaref and opts.expr and opts.replace_keycodes ~= false then

61 +

if is_rhs_luaref and opts.expr then

60 62

local user_rhs = rhs

61 63

rhs = function ()

62 -

return vim.api.nvim_replace_termcodes(user_rhs(), true, true, true)

64 +

local res = user_rhs()

65 +

if not res then

66 +

-- TODO(lewis6991): Handle this in C?

67 +

return ''

68 +

elseif opts.replace_keycodes ~= false then

69 +

return vim.api.nvim_replace_termcodes(res, true, true, true)

70 +

else

71 +

return res

72 +

end

63 73

end

64 74

end

65 75

-- clear replace_keycodes from opts table

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4