Summary Files Commits Branches @commit @diff @stats
path: root / lua / mappings.lua
diff options
context:
space:
mode:
Commitfb7c1decd11ae49eee31fe94ca39c59cadff8168 (patch)
Author
 Syndamia <kamen@syndamia.com>
2024-03-11 11:14:53 +0200
Committer
 Syndamia <kamen@syndamia.com>
2024-03-11 11:14:53 +0200
Filesc012200d760a204baaa1bb833a438802f47d6a5c /lua/mappings.lua
anderson-fb7c1decd11ae49eee31fe94ca39c59cadff8168.tar
anderson-fb7c1decd11ae49eee31fe94ca39c59cadff8168.tar.gz
anderson-fb7c1decd11ae49eee31fe94ca39c59cadff8168.zip
Parentd2b0e501275a7f79dc27538fd4c1a17af4ba0017 (diff)
[mappings] Keys can now be used for standalone purposes
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, ...)