diff options
| author | Michiel van den Heuvel <michielvdnheuvel@gmail.com> | 2024-05-28 12:49:55 +0200 |
|---|---|---|
| committer | Randy Palamar <randy@rnpnr.xyz> | 2024-05-30 05:52:27 -0600 |
| commit | a7aac1044856abc4d1f133c6563fc604d7fe6295 (patch) | |
| tree | 8b77c14267785920d49f9ec3e44b9e699c420fda /lua/vis.lua | |
| parent | 9bfb31fcbee028eaecce75a743f2a0bd50b5807c (diff) | |
| download | vis-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/vis.lua')
| -rw-r--r-- | lua/vis.lua | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/lua/vis.lua b/lua/vis.lua index 5473f17..d06bbaf 100644 --- a/lua/vis.lua +++ b/lua/vis.lua @@ -131,7 +131,8 @@ else local load_lexer = vis.lexers.load vis.lexers.load = function (name, alt_name, cache) if cache and lexers[alt_name or name] then return lexers[alt_name or name] end - local lexer = load_lexer(name, alt_name) + local status, lexer = pcall(load_lexer, name, alt_name) + if not status then return nil end if cache then lexers[alt_name or name] = lexer end return lexer end @@ -276,6 +277,7 @@ vis.types.window.set_syntax = function(win, syntax) win.syntax = nil return true end + win.syntax = syntax if not lexers.load then return false end local lexer = lexers.load(syntax) @@ -297,7 +299,6 @@ vis.types.window.set_syntax = function(win, syntax) if style ~= nil then win:style_define(id, style) end end - win.syntax = syntax return true end |
