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. --- tests/extensions/fake-lexers/lexer.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'tests/extensions/fake-lexers/lexer.lua') diff --git a/tests/extensions/fake-lexers/lexer.lua b/tests/extensions/fake-lexers/lexer.lua index adf7d5b..0632744 100644 --- a/tests/extensions/fake-lexers/lexer.lua +++ b/tests/extensions/fake-lexers/lexer.lua @@ -1,9 +1,9 @@ -- A miniature stand-in for the Scintillua lexer module, just enough for the -- syntax-highlight checks to drive every path through the filter without the -- real collection installed. load() hands out one of the toy lexers below by --- name and detect() recognises a single filename suffix, so a check can tell --- the detection path apart from the extension path by which lexer ends up --- running. Anything the filter treats as optional, a lexer that will not +-- name and detect() recognises a single filename suffix or a shebang naming +-- fake, so a check can tell the detection path apart from the extension path +-- by which lexer ends up running. Anything the filter treats as optional, a lexer that will not -- load or one that raises while lexing, has a name here too. local M = {} @@ -67,10 +67,13 @@ function M.load(name) return lexer end -function M.detect(filename) +function M.detect(filename, line) if filename:match("%.viadetect$") then return "fake" end + if line ~= nil and line:match("^#!.*fake") then + return "fake" + end return nil end -- cgit