summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorgi Kirilov <>2023-10-10 05:21:09 +0800
committerGeorgi Kirilov <>2023-10-10 21:35:19 +0800
commit60c81f7fb00626f27a02e7ca50375c229be3f778 (patch)
tree98e4c55a2df091b0ef29b653a1cd1c8d14ffe728
parenta5e9d0c6510044f09ccf8288fc3177b2d90d952f (diff)
downloadvis-pairs-60c81f7fb00626f27a02e7ca50375c229be3f778.tar.gz
don't call lexers.load multiple times
-rw-r--r--init.lua9
1 files changed, 5 insertions, 4 deletions
diff --git a/init.lua b/init.lua
index c7170dd..1c8cda7 100644
--- a/init.lua
+++ b/init.lua
@@ -115,9 +115,8 @@ local function match_at(str, pattern, pos)
if t then return t[1] - 1, t[#t] - 1 end
end
-local function escaping_context(win, range, data)
- if not win.syntax then return {} end
- local rules = vis.lexers.load(win.syntax)._RULES
+local function escaping_context(lexer, range, data)
+ local rules = lexer._RULES
local p
for _, name in ipairs({vis.lexers.COMMENT, vis.lexers.STRING}) do
if rules[name] then
@@ -144,11 +143,13 @@ local function escaping_context(win, range, data)
end
local function get_range(key, win, pos, file_data, count)
+ if not win.syntax then return end
local d = get_pair(key, win)
if not d then return end
+ local lexer = vis.lexers.load(win.syntax)
repeat
local sel_range = selection_range(win, pos)
- local c = escaping_context(win, sel_range, file_data)
+ local c = escaping_context(lexer, sel_range, file_data)
local range = c.range or {1, #file_data}
local correction = range[1] - 1
pos = pos - correction