summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pairs.lua54
1 files changed, 27 insertions, 27 deletions
diff --git a/pairs.lua b/pairs.lua
index 581b7ae..54e068c 100644
--- a/pairs.lua
+++ b/pairs.lua
@@ -31,8 +31,8 @@ for alias, key in pairs({
b = "(",
}) do builtin_textobjects[alias] = builtin_textobjects[key] end
-local function get_pair(key)
- return M.map[vis.win.syntax] and M.map[vis.win.syntax][key]
+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 not key:match("%w") and {key, key}
@@ -83,8 +83,8 @@ local precedence = {
[vis.lexers.STRING] = {},
}
-local function selection_range(pos)
- for selection in vis.win:selections_iterator() do
+local function selection_range(win, pos)
+ for selection in win:selections_iterator() do
if selection.pos == pos then
return selection.range
end
@@ -110,9 +110,9 @@ local function match_at(str, pattern, pos)
end
end
-local function escaping_context(data, range)
- if not vis.win.syntax then return {} end
- local rules = vis.lexers.lexers[vis.win.syntax]._RULES
+local function escaping_context(win, range, data)
+ if not win.syntax then return {} end
+ local rules = vis.lexers.lexers[win.syntax]._RULES
local p
for _, name in ipairs({vis.lexers.COMMENT, vis.lexers.STRING}) do
if rules[name] then
@@ -141,13 +141,13 @@ local function escaping_context(data, range)
end
end
-local function get_range(key, file_data, pos)
- local d = get_pair(key)
+local function get_range(key, win, pos, file_data)
+ local d = get_pair(key, win)
if not d then return end
local offsets, correction
repeat
- local sel_range = selection_range(pos)
- local c = escaping_context(file_data, sel_range)
+ local sel_range = selection_range(win, pos)
+ local c = escaping_context(win, sel_range, file_data)
local range = c.range or {1, #file_data}
if c.newpos then
pos = c.newpos
@@ -182,35 +182,35 @@ local function get_range(key, file_data, pos)
return unpack(offsets)
end
-local function get_delimiters(key, pos)
- local d = get_pair(key)
+local function get_delimiters(key, win, pos)
+ local d = get_pair(key, win)
if not d or type(d[1]) == "string" and type(d[2]) == "string" then return d end
- local content = vis.win.file:content(0, vis.win.file.size)
- local start, finish = get_range(key, content, pos)
+ local content = win.file:content(0, win.file.size)
+ local start, finish = get_range(key, win, pos, content)
if start and finish then
- return {vis.win.file:content(start[1], start[2] - start[1]), vis.win.file:content(finish[1], finish[2] - finish[1]), d[3], d[4]}
+ return {win.file:content(start[1], start[2] - start[1]), win.file:content(finish[1], finish[2] - finish[1]), d[3], d[4]}
elseif #d > 2 then
return {nil, nil, d[3], d[4]}
end
end
-local function outer(content, pos)
- local start, finish = get_range(M.key, content, pos)
+local function outer(win, pos, content)
+ local start, finish = get_range(M.key, win, pos, content)
if not (start and finish) then return end
return start[1], finish[2]
end
-local function inner(content, pos)
- local start, finish = get_range(M.key, content, pos)
+local function inner(win, pos, content)
+ local start, finish = get_range(M.key, win, pos, content)
if not (start and finish) then return end
return start[2], finish[1]
end
-local function opening(content, pos)
- local start, _ = get_range(M.key, content, pos)
+local function opening(win, pos, content)
+ local start, _ = get_range(M.key, win, pos, content)
if start then
if pos == start[2] - 1 then
- start, _ = get_range(M.key, content, start[1] - 1)
+ start, _ = get_range(M.key, win, start[1] - 1, content)
end
if start then
local exclusive = (vis.mode == vis.modes.OPERATOR_PENDING or vis.mode == vis.modes.VISUAL and pos < start[2] - 1) and 1 or 0
@@ -220,11 +220,11 @@ local function opening(content, pos)
return pos
end
-local function closing(content, pos)
- local _, finish = get_range(M.key, content, pos)
+local function closing(win, pos, content)
+ local _, finish = get_range(M.key, win, pos, content)
if finish then
if pos == finish[1] then
- _, finish = get_range(M.key, content, finish[2])
+ _, finish = get_range(M.key, win, finish[2], content)
end
if finish then
local exclusive = (vis.mode == vis.modes.VISUAL and pos > finish[1]) and 1 or 0
@@ -252,7 +252,7 @@ local function prep(func)
return function(win, pos)
if bail_early() then return pos end
local content = win.file:content(0, win.file.size)
- return func(content, pos)
+ return func(win, pos, content)
end
end