aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--visrc.lua31
1 files changed, 31 insertions, 0 deletions
diff --git a/visrc.lua b/visrc.lua
index 98f4ee9..f416a82 100644
--- a/visrc.lua
+++ b/visrc.lua
@@ -29,6 +29,37 @@ vis.textobject_new = function(vis, key, textobject)
return true
end
+vis:textobject_new("ii", function(win, pos)
+
+ if win.syntax == nil then
+ return pos, pos
+ end
+
+ local before, after = pos - 4096, pos + 4096;
+ if before < 0 then
+ before = 0
+ end
+ -- TODO make sure we start at a line boundary?
+
+ local lexer = vis.lexers.load(win.syntax)
+ local data = win.file:content(before, after - before)
+ local tokens = lexer:lex(data)
+ local cur = before
+ -- print(before..", "..pos..", ".. after)
+
+ for i = 1, #tokens, 2 do
+ local name = tokens[i]
+ local token_next = before + tokens[i+1] - 1
+ -- print(name..": ["..cur..", "..token_next.."] pos: "..pos)
+ if cur <= pos and pos < token_next then
+ return cur, token_next
+ end
+ cur = token_next
+ end
+
+ return pos, pos
+end)
+
vis.events.win_open = function(win)
local files = {