summaryrefslogtreecommitdiffstats
path: root/init.lua
diff options
context:
space:
mode:
authorGeorgi Kirilov <>2022-12-03 13:53:15 +0800
committerGeorgi Kirilov <>2023-10-10 05:52:27 +0800
commit589d7c25f907f05019e42245e83266207352a310 (patch)
treeca1baef589a26371b421db1c5d6879bd6860dce7 /init.lua
parent6fe7be3267bb124786bed422738d5c76421cfc82 (diff)
downloadvis-pairs-589d7c25f907f05019e42245e83266207352a310.tar.gz
minimize the number of mappings
Aliases using closing delimiters are provided by vis anyway.
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua30
1 files changed, 16 insertions, 14 deletions
diff --git a/init.lua b/init.lua
index ee3c526..ce21980 100644
--- a/init.lua
+++ b/init.lua
@@ -24,24 +24,24 @@ local builtin_textobjects = {
}
local builtin_motions = {
- ["["] = { ["("] = true, ["{"] = true },
- ["]"] = { [")"] = true, ["}"] = true },
+ ["["] = { ["("] = builtin_textobjects["("], ["{"] = builtin_textobjects["{"] },
+ ["]"] = { [")"] = builtin_textobjects["("], ["}"] = builtin_textobjects["{"] },
}
-local aliases = {}
-for key, pair in pairs(builtin_textobjects) do aliases[pair[2]] = key ~= pair[2] and pair or nil end
-for alias, pair in pairs(aliases) do builtin_textobjects[alias] = pair end
-for alias, key in pairs({
- B = "{",
- b = "(",
- }) do
- builtin_textobjects[alias] = builtin_textobjects[key]
-end
+local alias = {
+ ["]"] = "[",
+ ["}"] = "{",
+ [">"] = "<",
+ [")"] = "(",
+ B = "{",
+ b = "(",
+}
local function get_pair(key, win)
return M.map[win.syntax] and M.map[win.syntax][key]
or M.map[1] and M.map[1][key]
or builtin_textobjects[key]
+ or builtin_textobjects[alias[key]]
or not key:match("%w") and {key, key}
end
@@ -313,7 +313,7 @@ local function new(execute, register, prefix, handler, help)
table.insert(mappings, win_map(execute == vis.textobject, prefix, binding, help))
local builtin = execute == vis.motion and builtin_motions[prefix] or builtin_textobjects
for key, _ in pairs(builtin) do
- local d = builtin_textobjects[key]
+ local d = builtin[key]
local simple = type(d[1]) == "string" and type(d[2]) == "string" and d[1]..d[2]
local hlp = (execute == vis.motion and help or "") .. (d.name or (simple or "pattern-delimited") .." block")
if execute ~= vis.textobject then
@@ -341,6 +341,7 @@ vis.events.subscribe(vis.events.WIN_OPEN, function(win)
local p = M.map[win.syntax] and M.map[win.syntax][key]
or M.map[1] and M.map[1][key]
or builtin_textobjects[key]
+ or builtin_textobjects[alias[key]]
local left, len = pos - direction, #key
if p and (key == p[1] or key == p[2]) then
M.key = p[1]
@@ -407,8 +408,8 @@ vis.events.subscribe(vis.events.INIT, function()
end
for key, d in pairs(M.map[1]) do
builtin_textobjects[key] = {d[1], d[2], name = d.name}
- builtin_motions[M.prefix.opening][key] = true
- builtin_motions[M.prefix.closing][key] = true
+ builtin_motions[M.prefix.opening][key] = builtin_textobjects[key]
+ builtin_motions[M.prefix.closing][key] = builtin_textobjects[key]
end
M.motion = {
@@ -428,6 +429,7 @@ vis.events.subscribe(vis.events.INIT, function()
local p = M.map[win.syntax] and M.map[win.syntax][key]
or M.map[1] and M.map[1][key]
or builtin_textobjects[key]
+ or builtin_textobjects[alias[key]]
if not p then return end
if M.no_autopairs[key] and M.no_autopairs[key][win.syntax or ""] then return end
for selection in win:selections_iterator() do