diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-02-17 23:07:52 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-02-18 16:50:40 +0100 |
| commit | 515fac2087885bfc17b19a375ae8936c2885993b (patch) | |
| tree | 2607b7dea72ece943218bb80e106fabd1ccd94ee | |
| parent | 0774b6e6933ce3093e2ecda1619c876bc4b85696 (diff) | |
| download | vis-515fac2087885bfc17b19a375ae8936c2885993b.tar.gz vis-515fac2087885bfc17b19a375ae8936c2885993b.tar.xz | |
vis-lua: add text object ii to match based on syntax item/token
Roughly speaking this should match whatever is colored the same way
as the cursor.
| -rw-r--r-- | visrc.lua | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -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 = { |
