Diff options
| -rw-r--r-- | custom/extensions/syntax-highlight.lua | 21 |
1 file changed, 9 insertions, 12 deletions
diff --git a/custom/extensions/syntax-highlight.lua b/custom/extensions/syntax-highlight.lua index 639ad3f..3a4fa9b 100644 --- a/custom/extensions/syntax-highlight.lua +++ b/custom/extensions/syntax-highlight.lua @@ -151,17 +151,11 @@ local function load_scintillua() return nil end --- Detecting and loading a lexer run Scintillua's own Lua, and code written --- for another version of it can raise, so a failure in either just leaves --- this file uncoloured. The first line goes along to detect(), so a script --- with no extension is still known by its shebang. +-- The first line goes along to detect(), so a script with no extension is +-- still known by its shebang. local function lexer_for(name, text) - local ok, lang = pcall(scintillua.detect, name, string.match(text, "^[^\n]*")) - if not ok or not lang then - return nil - end - local loaded, lexer = pcall(scintillua.load, lang) - return loaded and lexer or nil + local lang = scintillua.detect(name, string.match(text, "^[^\n]*")) + return lang and scintillua.load(lang) end local function highlight(text) @@ -169,8 +163,8 @@ local function highlight(text) if not lexer then return nil end - local ok, tokens = pcall(lexer.lex, lexer, text) - if not ok or type(tokens) ~= "table" then + local tokens = lexer:lex(text) + if type(tokens) ~= "table" then return nil end local out = {} @@ -223,6 +217,9 @@ function filter_close() scintillua = load_scintillua() or false end if scintillua then + -- Every step of highlight runs Scintillua's own Lua, and code + -- written for another version of it can raise, so a failure + -- anywhere there just leaves this file uncoloured. local ok, marked = pcall(highlight, text) if ok and marked then html(marked) |
