From d6e435706badfee9b96b3cf831c0283a28137eb0 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Fri, 16 Oct 2026 22:18:15 -1000 Subject: 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. --- custom/extensions/syntax-highlight.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'custom/extensions') 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 -- cgit