diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Find a script's lexer from its shebang line
Scintillua's detect reads the first line as well as the name, and
without it hooks, bin scripts and anything else lacking an extension
stayed plain.
Diffstat (limited to 'custom')
| -rw-r--r-- | custom/extensions/syntax-highlight.lua | 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 file changed, 5 insertions, 3 deletions
diff --git a/custom/extensions/syntax-highlight.lua b/custom/extensions/syntax-highlight.lua index 2bff263..544fce1 100644 --- a/custom/extensions/syntax-highlight.lua +++ b/custom/extensions/syntax-highlight.lua @@ -162,9 +162,11 @@ local function load_lexer_name(name) return nil end -local function lexer_for(name) +local function lexer_for(name, text) if type(scintillua.detect) == "function" then - local ok, lang = pcall(scintillua.detect, name) + -- The first line goes along, so a script with no extension is still + -- known by its shebang. + local ok, lang = pcall(scintillua.detect, name, text:match("^[^\n]*")) if ok and lang then local lexer = load_lexer_name(lang) if lexer then @@ -181,7 +183,7 @@ local function lexer_for(name) end local function highlight(text) - local lexer = lexer_for(filename) + local lexer = lexer_for(filename, text) if not lexer then return nil end |
