Summary Files Commits Branches @commit @diff @stats
path: root / lua / mappings.lua
diff options
context:
space:
mode:
1 files changed, 26 insertions, 18 deletions
-rw-r--r--lua/mappings.lua44
diff --git a/lua/mappings.lua b/lua/mappings.lua
index 2fd6830..1cd7c0d 100644
--- a/lua/mappings.lua
+++ b/lua/mappings.lua
@@ -1,5 +1,29 @@
--[=[ Helpers ]=]--
+keys = {}
+setmetatable(keys,
+{
+ __index = function (table, index)
+ local mod, key = index:match("^(.*)_"), index:match("[^_]*$")
+ if mod == nil then
+ local upperkey = key:upper()
+ if upperkey == "ESCAPE" then key = "<Esc>"
+ elseif #key > 1 then key = "<" .. key .. ">"
+ end
+ return key
+ end
+ mod = mod:upper()
+
+ if mod == "SHIFT" then key = "<S-" .. key .. ">"
+ elseif mod == "CONTROL" then key = "<C-" .. key .. ">"
+ elseif mod == "ALT" then key = "<M-" .. key .. ">"
+ elseif mod == "SUPER" then key = "<D-" .. key .. ">"
+ elseif mod ~= nil then error("Unknown key modifier \"" .. mod .. "\"!")
+ end
+
+ return key
+ end
+})
map = { keys = { lhs = {}, rhs = "" } }
setmetatable(map,
{
@@ -12,26 +36,10 @@ setmetatable(map,
return table.keys
end
})
-setmetatable(rawget(map, "keys"),
+setmetatable(map.keys,
{
__index = function (table, index)
- local mod, key = index:match("^(.*)_"), index:match("[^_]*$")
- if mod == nil then
- if #key > 1 then
- key = "<" .. key .. ">"
- end
- table.rhs = table.rhs .. key
- return table
- end
- mod = mod:upper()
-
- if mod == "SHIFT" then table.rhs = table.rhs .. "<S-" .. key .. ">"
- elseif mod == "CONTROL" then table.rhs = table.rhs .. "<C-" .. key .. ">"
- elseif mod == "ALT" then table.rhs = table.rhs .. "<M-" .. key .. ">"
- elseif mod == "SUPER" then table.rhs = table.rhs .. "<D-" .. key .. ">"
- elseif mod ~= nil then error("Unknown key modifier \"" .. mod .. "\"!")
- end
-
+ table.rhs = table.rhs .. keys[index]
return table
end,
__call = function (table, ...)