]> git.eshelyaron.com Git - emacs.git/commitdiff
Support shebang lines with amended environment
authorKévin Le Gouguec <kevin.legouguec@gmail.com>
Sat, 10 Feb 2024 16:56:57 +0000 (17:56 +0100)
committerEshel Yaron <me@eshelyaron.com>
Sat, 17 Feb 2024 13:03:15 +0000 (14:03 +0100)
For bug#64939.

* lisp/files.el (auto-mode-interpreter-regexp): Account for possible
VARIABLE=[VALUE] operands.
* test/lisp/files-tests.el (files-tests-auto-mode-interpreter):
Add an example from the coreutils manual.

(cherry picked from commit c64e650fb346d92294703d22f8cd7deb7c47b49e)

lisp/files.el
test/lisp/files-tests.el

index 52b42be3f0ec2b6b2b16c04b6c53ff2996052666..fed825580d0f7a9c6b2d6c85f3792962caf4c093 100644 (file)
@@ -3274,12 +3274,15 @@ and `inhibit-local-variables-suffixes'.  If
     ;; Optional group 1: env(1) invocation.
     "\\("
     "[^ \t\n]*/bin/env[ \t]*"
-    ;; Within group 1: possible -S/--split-string.
+    ;; Within group 1: possible -S/--split-string and environment
+    ;; adjustments.
     "\\(?:"
     ;; -S/--split-string
     "\\(?:-[0a-z]*S[ \t]*\\|--split-string=\\)"
     ;; More env arguments.
     "\\(?:-[^ \t\n]+[ \t]+\\)*"
+    ;; Interpreter environment modifications.
+    "\\(?:[^ \t\n]+=[^ \t\n]*[ \t]+\\)*"
     "\\)?"
     "\\)?"
     ;; Group 2: interpreter.
index 0a5c3b897e488afbd5fa16a2fd9bb9f6ab67a06b..d4c1ef3ba674a99c849ee80861d2a31eeee647f6 100644 (file)
@@ -1694,7 +1694,9 @@ set to."
   (files-tests--check-shebang "#!/usr/bin/env -S-vi bash -eux" 'sh-base-mode 'bash)
   (files-tests--check-shebang "#!/usr/bin/env -ivS --default-signal=INT bash -eux" 'sh-base-mode 'bash)
   (files-tests--check-shebang "#!/usr/bin/env -ivS --default-signal bash -eux" 'sh-base-mode 'bash)
-  (files-tests--check-shebang "#!/usr/bin/env -vS -uFOOBAR bash -eux" 'sh-base-mode 'bash))
+  (files-tests--check-shebang "#!/usr/bin/env -vS -uFOOBAR bash -eux" 'sh-base-mode 'bash)
+  ;; Invocation through env, with modified environment.
+  (files-tests--check-shebang "#!/usr/bin/env -S PYTHONPATH=/...:${PYTHONPATH} python" 'python-base-mode))
 
 (ert-deftest files-test-dir-locals-auto-mode-alist ()
   "Test an `auto-mode-alist' entry in `.dir-locals.el'"