From 0287f84a3ab6b767cc99b91356a96f2162c6a099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Le=20Gouguec?= Date: Sun, 12 Nov 2023 17:46:34 +0100 Subject: [PATCH 3/3] Recognize shebang lines that pass -S/--split-string to env * lisp/files.el (auto-mode-interpreter-regexp): Add optional -S switch to the ignored group capturing the env invocation. * test/lisp/files-tests.el (files-test-auto-mode-interpreter): Add a couple of testcases; one from (info "(coreutils) env invocation"), the other from a personal project. --- lisp/files.el | 4 +++- test/lisp/files-tests.el | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lisp/files.el b/lisp/files.el index dc301bea3c5..56bdcf9d08b 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -3252,7 +3252,9 @@ auto-mode-interpreter-regexp (rx "#!" (* ascii-blank) (? (group (* non-blank) "/bin/env" - (* ascii-blank))) + (* ascii-blank) + (? (or (: "-S" (* ascii-blank)) + (: "--split-string" (or ?= (* ascii-blank))))))) (group (+ non-blank))))) "Regexp matching interpreters, for file mode determination. This regular expression is matched against the first line of a file diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index 233efded945..3e499fff468 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -1677,6 +1677,8 @@ files-tests-auto-mode-interpreter (files-tests--check-shebang "#!/usr/bin/env bash" 'sh-mode) (files-tests--check-shebang "#!/usr/bin/env python" 'python-base-mode) (files-tests--check-shebang "#!/usr/bin/env python3" 'python-base-mode) + (files-tests--check-shebang "#!/usr/bin/env -S awk -v FS=\"\\t\" -v OFS=\"\\t\" -f" 'awk-mode) + (files-tests--check-shebang "#!/usr/bin/env -S make -f" 'makefile-mode) (files-tests--check-shebang "#!/usr/bin/make -f" 'makefile-mode)) (ert-deftest files-test-dir-locals-auto-mode-alist () -- 2.42.1