/usr/share/vis/plugins/textobject-lexer.lua is in vis 0.4-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | -- text object matching a lexer token
local MAX_CONTEXT = 32768
vis:textobject_new("ii", function(win, pos)
if win.syntax == nil or not vis.lexers then
return nil
end
local before, after = pos - MAX_CONTEXT, pos + MAX_CONTEXT
if before < 0 then
before = 0
end
-- TODO make sure we start at a line boundary?
local lexer = vis.lexers.load(win.syntax, nil, true)
local data = win.file:content(before, after - before)
local tokens = lexer:lex(data)
local cur = before
for i = 1, #tokens, 2 do
local token_next = before + tokens[i+1] - 1
if cur <= pos and pos < token_next then
return cur, token_next
end
cur = token_next
end
return nil
end, "Current lexer token")
|