aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/keymap.lua
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2024-10-18 11:33:12 +0100
committerLewis Russell <me@lewisr.dev>2024-10-21 11:32:06 +0100
commit3572319b4cb1a4163624a5fe328886f1928dbc4a (patch)
tree5e190a6d9ca8a2e0f998ef578f895efee9450fb4 /runtime/lua/vim/keymap.lua
parent6fd13eeddaf5db89c1b81cc7d3d3f1a7da5401a7 (diff)
downloadrneovim-3572319b4cb1a4163624a5fe328886f1928dbc4a.tar.gz
rneovim-3572319b4cb1a4163624a5fe328886f1928dbc4a.tar.bz2
rneovim-3572319b4cb1a4163624a5fe328886f1928dbc4a.zip
feat(vim.validate): improve fast form and deprecate spec form
Problem: `vim.validate()` takes two forms when it only needs one. Solution: - Teach the fast form all the features of the spec form. - Deprecate the spec form. - General optimizations for both forms. - Add a `message` argument which can be used alongside or in place of the `optional` argument.
Diffstat (limited to 'runtime/lua/vim/keymap.lua')
-rw-r--r--runtime/lua/vim/keymap.lua18
1 files changed, 7 insertions, 11 deletions
diff --git a/runtime/lua/vim/keymap.lua b/runtime/lua/vim/keymap.lua
index 50ca0d2d0e..4c19435ef8 100644
--- a/runtime/lua/vim/keymap.lua
+++ b/runtime/lua/vim/keymap.lua
@@ -42,12 +42,10 @@ local keymap = {}
---@see |mapcheck()|
---@see |mapset()|
function keymap.set(mode, lhs, rhs, opts)
- vim.validate({
- mode = { mode, { 's', 't' } },
- lhs = { lhs, 's' },
- rhs = { rhs, { 's', 'f' } },
- opts = { opts, 't', true },
- })
+ vim.validate('mode', mode, { 'string', 'table' })
+ vim.validate('lhs', lhs, 'string')
+ vim.validate('rhs', rhs, { 'string', 'function' })
+ vim.validate('opts', opts, 'table', true)
opts = vim.deepcopy(opts or {}, true)
@@ -107,11 +105,9 @@ end
---@param opts? vim.keymap.del.Opts
---@see |vim.keymap.set()|
function keymap.del(modes, lhs, opts)
- vim.validate({
- mode = { modes, { 's', 't' } },
- lhs = { lhs, 's' },
- opts = { opts, 't', true },
- })
+ vim.validate('mode', modes, { 'string', 'table' })
+ vim.validate('lhs', lhs, 'string')
+ vim.validate('opts', opts, 'table', true)
opts = opts or {}
modes = type(modes) == 'string' and { modes } or modes