Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Drop the highlighter's extension fallback
The table of extensions and the second lookup served only a Scintillua
with no detect(), which now leaves every file uncoloured but escaped.
The fake detect() names a lexer after the file's suffix, so every test
lexer is reached through it.
Diffstat (limited to 'custom')
| -rw-r--r-- | custom/extensions/syntax-highlight.lua | 55 |
1 file changed, 8 insertions, 47 deletions
diff --git a/custom/extensions/syntax-highlight.lua b/custom/extensions/syntax-highlight.lua index 6605d71..639ad3f 100644 --- a/custom/extensions/syntax-highlight.lua +++ b/custom/extensions/syntax-highlight.lua @@ -74,25 +74,6 @@ local css = { pseudoelement = "hl-func", } --- Extension to lexer name fixes for the fallback path, reached only when --- this Scintillua has no detect(). Most extensions already equal their lexer --- name and these are the frequent exceptions. -local ext_lexer = { - py = "python", - js = "javascript", - ts = "typescript", - rb = "ruby", - pl = "perl", - pm = "perl", - sh = "bash", - md = "markdown", - htm = "html", - yml = "yaml", - rs = "rust", - c = "ansi_c", - h = "ansi_c", -} - local scintillua = nil local filename = "" @@ -170,37 +151,17 @@ local function load_scintillua() return nil end --- Loading a lexer runs its Lua, and one written for another Scintillua can --- raise, so a failure here just leaves this file uncoloured. -local function load_lexer_name(name) - if name == nil then - return nil - end - local ok, lexer = pcall(scintillua.load, name) - if ok and lexer then - return lexer - end - 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. local function lexer_for(name, text) - if type(scintillua.detect) == "function" then - -- The first line goes along, so a script with no extension is still - -- known by its shebang. - local ok, lang = pcall(scintillua.detect, name, string.match(text, "^[^\n]*")) - if ok and lang then - local lexer = load_lexer_name(lang) - if lexer then - return lexer - end - end - end - local ext = string.match(name, "%.([^.]+)$") - if not ext then + local ok, lang = pcall(scintillua.detect, name, string.match(text, "^[^\n]*")) + if not ok or not lang then return nil end - ext = string.lower(ext) - return load_lexer_name(ext_lexer[ext]) or load_lexer_name(ext) + local loaded, lexer = pcall(scintillua.load, lang) + return loaded and lexer or nil end local function highlight(text) |
