summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorgi Kirilov <>2020-11-22 15:10:50 +0200
committerGeorgi Kirilov <>2023-10-04 18:24:59 +0800
commit4bcb76cfa376606d522131642c7083741f2e98c4 (patch)
tree925d94b49b01b6dd14c70740ae74a2824bec6919
parent898b6c386c17b870d2765be0433c654a7edfe006 (diff)
downloadvis-pairs-4bcb76cfa376606d522131642c7083741f2e98c4.tar.gz
Collaborate with vis-fenced-insert and vis-parkour
-rw-r--r--pairs.lua26
1 files changed, 20 insertions, 6 deletions
diff --git a/pairs.lua b/pairs.lua
index 79329c5..7ec317c 100644
--- a/pairs.lua
+++ b/pairs.lua
@@ -325,8 +325,9 @@ vis.events.subscribe(vis.events.WIN_OPEN, function(win)
for _, map_keys in ipairs(mappings) do
map_keys(win)
end
- local function delete_pair(direction)
+ local function delete_pair(direction, do_delete)
return function()
+ local locations = {}
for selection in win:selections_iterator() do
local pos = selection.pos
if pos - direction < 0 then return end
@@ -343,17 +344,26 @@ vis.events.subscribe(vis.events.WIN_OPEN, function(win)
len = #p[1] + #p[2]
end
end
- win.file:delete(left, len)
- selection.pos = left
+ locations[selection.number] = len - 1
+ if do_delete then
+ win.file:delete(left, len)
+ selection.pos = left
+ end
end
+ return locations
end
end
- if M.autopairs then
- win:map(vis.modes.INSERT, "<Backspace>", delete_pair(1))
- win:map(vis.modes.INSERT, "<Delete>", delete_pair(0))
+ M.unpair[win] = delete_pair(1)
+ if M.autopairs and (not vis_parkour or vis_parkour(win)) then
+ win:map(vis.modes.INSERT, "<Backspace>", delete_pair(1, true))
+ win:map(vis.modes.INSERT, "<Delete>", delete_pair(0, true))
end
end)
+vis.events.subscribe(vis.events.WIN_CLOSE, function(win)
+ M.unpair[win] = nil
+end)
+
vis.events.subscribe(vis.events.INIT, function()
local function cmp(_, _, c1, c2) return c1 == c2 end
local function casecmp(_, _, c1, c2) return c1:lower() == c2:lower() end
@@ -406,6 +416,7 @@ vis.events.subscribe(vis.events.INIT, function()
if M.autopairs then
vis.events.subscribe(vis.events.INPUT, function(key)
local win = vis.win
+ if vis_parkour and vis_parkour(win) then return end
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]
@@ -434,6 +445,9 @@ M = {
get_range_outer = outer,
prefix = {outer = "a", inner = "i", opening = "[", closing = "]"},
autopairs = true,
+ unpair = {}
}
+vis_pairs = M
+
return M