aboutsummaryrefslogtreecommitdiff
path: root/lua/plugins/textobject-lexer.lua
diff options
context:
space:
mode:
authorMichiel van den Heuvel <michielvdnheuvel@gmail.com>2024-05-28 12:49:55 +0200
committerRandy Palamar <randy@rnpnr.xyz>2024-05-30 05:52:27 -0600
commita7aac1044856abc4d1f133c6563fc604d7fe6295 (patch)
tree8b77c14267785920d49f9ec3e44b9e699c420fda /lua/plugins/textobject-lexer.lua
parent9bfb31fcbee028eaecce75a743f2a0bd50b5807c (diff)
downloadvis-a7aac1044856abc4d1f133c6563fc604d7fe6295.tar.gz
vis-a7aac1044856abc4d1f133c6563fc604d7fe6295.tar.xz
Fail silently when syntax has no lexer
This'll patch vis.lexers.load to return nil when the lexer could not be found. Previously it would've errored out, which the load in lexer.lua still will as this is used in lexers themselves. Another possibility is to only patch set_syntax in vis.lua and the WIN_HIGHLIGHT handler in vis-std.lua, but as most references to vis.lexers.load already handle a nil return, this seems better.
Diffstat (limited to 'lua/plugins/textobject-lexer.lua')
-rw-r--r--lua/plugins/textobject-lexer.lua6
1 files changed, 5 insertions, 1 deletions
diff --git a/lua/plugins/textobject-lexer.lua b/lua/plugins/textobject-lexer.lua
index 2f9d757..eba65e2 100644
--- a/lua/plugins/textobject-lexer.lua
+++ b/lua/plugins/textobject-lexer.lua
@@ -8,13 +8,17 @@ vis:textobject_new("ii", function(win, pos)
return nil
end
+ local lexer = vis.lexers.load(win.syntax, nil, true)
+ if not lexer 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