repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

neovim: map.lua throws an error, when used wrongly

8abaee34f10b38cd182a56b956f2454f42ad5a04

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (1)

neovim/lua/std/map.lua

Modified
1 1 local available_modes = {
2 - normal_visual_select_operator_pending = "",
3 - N = "",
2 + normal_visual_select_operator_pending = '',
3 + N = '',
5 - normal = "n",
6 - n = "n",
5 + normal = 'n',
6 + n = 'n',
8 - insert = "i",
9 - i = "i",
8 + insert = 'i',
9 + i = 'i',
11 - visual = "x",
12 - x = "x",
11 + visual = 'x',
12 + x = 'x',
14 - visual_select = "v",
15 - v = "v",
14 + visual_select = 'v',
15 + v = 'v',
17 - select = "s",
18 - s = "s",
17 + select = 's',
18 + s = 's',
20 - operator_pending = "o",
21 - o = "o",
20 + operator_pending = 'o',
21 + o = 'o',
23 - ["!"] = "!",
24 - insert_command_line = "!",
23 + ['!'] = '!',
24 + insert_command_line = '!',
26 - command_line = "c",
27 - c = "c",
26 + command_line = 'c',
27 + c = 'c',
29 - terminal = "t",
30 - t = "t",
29 + terminal = 't',
30 + t = 't',
33 -local bind = function(self, map)
34 - vim.validate({
35 - map = { map, "table" },
36 - ["map.keys"] = { map.keys, { "string", "table" } },
37 - ["map.command"] = { map.command, { "function", "string" } },
38 - })
33 +local bind = function ( self, map )
34 + vim.validate {
35 + map = { map, 'table' },
36 + ['map.keys'] = { map.keys, { 'string', 'table' } },
37 + ['map.command'] = { map.command, { 'function', 'string' } },
38 + }
40 40 local keys = map.keys
41 41 local command = map.command
43 43 map.options = map.options or {}
45 45 if map.category and map.description then
46 - map.description = map.category .. ": " .. map.description
46 + map.description = map.category .. ': ' .. map.description
49 - local options = vim.tbl_extend("keep", map.options, {
49 + local options = vim.tbl_extend( 'keep', map.options, {
50 50 silent = true,
51 51 desc = map.description,
52 52 buffer = map.buffer,
53 53 remap = map.remap,
54 - })
54 + } )
56 - if vim.tbl_isempty(self.modes) then
56 + if vim.tbl_isempty( self.modes ) then
57 57 self.modes[1] = available_modes.normal_visual_select_operator_pending
60 60 -- vim.print('vim.keymap', self.modes, keys, command, options)
62 - if type(keys) == "table" then
63 - for _, key in ipairs(keys) do
64 - vim.keymap.set(self.modes, key, command, options)
62 + if type( keys ) == 'table' then
63 + for _, key in ipairs( keys ) do
64 + vim.keymap.set( self.modes, key, command, options )
67 - vim.keymap.set(self.modes, keys, command, options)
67 + vim.keymap.set( self.modes, keys, command, options )
70 70 self.modes = {}
72 - return function()
72 + return function ()
73 73 local delete_options = options.buffer and { buffer = options.buffer } or {}
74 - if type(keys) == "table" then
75 - for _, key in ipairs(keys) do
76 - vim.keymap.del(self.modes, key, delete_options)
74 + if type( keys ) == 'table' then
75 + for _, key in ipairs( keys ) do
76 + vim.keymap.del( self.modes, key, delete_options )
79 - vim.keymap.del(self.modes, keys, delete_options)
79 + vim.keymap.del( self.modes, keys, delete_options )
84 -local add_mode = function(self, key)
84 +local add_mode = function ( self, key )
85 85 local new_mode = available_modes[key]
86 86 if new_mode == nil then
87 - error("unknown keymap mode requested: " .. key)
87 + error( 'unknown keymap mode requested: ' .. key )
89 89 if not self.modes[new_mode] then
90 - table.insert(self.modes, new_mode)
90 + table.insert( self.modes, new_mode )
92 92 return self
95 95 --- @overload fun(map:table): function
96 -local map = setmetatable({
97 - modes = {},
98 -}, {
99 - __index = add_mode,
100 - __call = bind,
101 -})
96 +local map = setmetatable(
97 + {
98 + modes = {},
99 + },
101 + __index = add_mode,
102 + __newindex = function ( ... ) error( 'Assigments are not supported for std.map.\n' .. vim.inspect(...), 2) end,
103 + __call = bind,
103 107 return map