diff options
| author | Kévin Le Gouguec | 2024-02-10 17:37:35 +0100 |
|---|---|---|
| committer | Eli Zaretskii | 2024-02-17 10:31:14 +0200 |
| commit | ecb9641ecb5f42899042ff9c164ec7dbb8e166fe (patch) | |
| tree | a07f79c3c309488ed5d7c90760759d15f6974250 | |
| parent | de6f7f3c86ea0e52e8f9825585c726a7f93fa9cf (diff) | |
| download | emacs-ecb9641ecb5f42899042ff9c164ec7dbb8e166fe.tar.gz emacs-ecb9641ecb5f42899042ff9c164ec7dbb8e166fe.zip | |
Support more complex env invocations in shebang lines
This is not an exact re-implementation of what env accepts, but
hopefully it should be "good enough".
Example of known limitation: we assume that arguments for
--long-options will be set with '=', but that is not
necessarily the case. '--unset' (mandatory argument) can be
passed as '--unset=VAR' or '--unset VAR', but
'--default-signal' (optional argument) requires an '=' sign.
For bug#64939.
* lisp/files.el (auto-mode-interpreter-regexp): Account for
supplementary arguments passed beside -S/--split-string.
* test/lisp/files-tests.el (files-tests-auto-mode-interpreter):
Test some of these combinations.
| -rw-r--r-- | lisp/files.el | 8 | ||||
| -rw-r--r-- | test/lisp/files-tests.el | 8 |
2 files changed, 14 insertions, 2 deletions
diff --git a/lisp/files.el b/lisp/files.el index f67b650cb92..5098d49048e 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -3274,7 +3274,13 @@ and `inhibit-local-variables-suffixes'. If | |||
| 3274 | ;; Optional group 1: env(1) invocation. | 3274 | ;; Optional group 1: env(1) invocation. |
| 3275 | "\\(" | 3275 | "\\(" |
| 3276 | "[^ \t\n]*/bin/env[ \t]*" | 3276 | "[^ \t\n]*/bin/env[ \t]*" |
| 3277 | "\\(?:-S[ \t]*\\|--split-string\\(?:=\\|[ \t]*\\)\\)?" | 3277 | ;; Within group 1: possible -S/--split-string. |
| 3278 | "\\(?:" | ||
| 3279 | ;; -S/--split-string | ||
| 3280 | "\\(?:-[0a-z]*S[ \t]*\\|--split-string=\\)" | ||
| 3281 | ;; More env arguments. | ||
| 3282 | "\\(?:-[^ \t\n]+[ \t]+\\)*" | ||
| 3283 | "\\)?" | ||
| 3278 | "\\)?" | 3284 | "\\)?" |
| 3279 | ;; Group 2: interpreter. | 3285 | ;; Group 2: interpreter. |
| 3280 | "\\([^ \t\n]+\\)")) | 3286 | "\\([^ \t\n]+\\)")) |
diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index 23516ff0d7d..0a5c3b897e4 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el | |||
| @@ -1687,8 +1687,14 @@ set to." | |||
| 1687 | (files-tests--check-shebang "#!/usr/bin/env python" 'python-base-mode) | 1687 | (files-tests--check-shebang "#!/usr/bin/env python" 'python-base-mode) |
| 1688 | (files-tests--check-shebang "#!/usr/bin/env python3" 'python-base-mode) | 1688 | (files-tests--check-shebang "#!/usr/bin/env python3" 'python-base-mode) |
| 1689 | ;; Invocation through env, with supplementary arguments. | 1689 | ;; Invocation through env, with supplementary arguments. |
| 1690 | (files-tests--check-shebang "#!/usr/bin/env --split-string=bash -eux" 'sh-base-mode 'bash) | ||
| 1691 | (files-tests--check-shebang "#!/usr/bin/env --split-string=-iv --default-signal bash -eux" 'sh-base-mode 'bash) | ||
| 1690 | (files-tests--check-shebang "#!/usr/bin/env -S awk -v FS=\"\\t\" -v OFS=\"\\t\" -f" 'awk-mode) | 1692 | (files-tests--check-shebang "#!/usr/bin/env -S awk -v FS=\"\\t\" -v OFS=\"\\t\" -f" 'awk-mode) |
| 1691 | (files-tests--check-shebang "#!/usr/bin/env -S make -f" 'makefile-mode)) | 1693 | (files-tests--check-shebang "#!/usr/bin/env -S make -f" 'makefile-mode) |
| 1694 | (files-tests--check-shebang "#!/usr/bin/env -S-vi bash -eux" 'sh-base-mode 'bash) | ||
| 1695 | (files-tests--check-shebang "#!/usr/bin/env -ivS --default-signal=INT bash -eux" 'sh-base-mode 'bash) | ||
| 1696 | (files-tests--check-shebang "#!/usr/bin/env -ivS --default-signal bash -eux" 'sh-base-mode 'bash) | ||
| 1697 | (files-tests--check-shebang "#!/usr/bin/env -vS -uFOOBAR bash -eux" 'sh-base-mode 'bash)) | ||
| 1692 | 1698 | ||
| 1693 | (ert-deftest files-test-dir-locals-auto-mode-alist () | 1699 | (ert-deftest files-test-dir-locals-auto-mode-alist () |
| 1694 | "Test an `auto-mode-alist' entry in `.dir-locals.el'" | 1700 | "Test an `auto-mode-alist' entry in `.dir-locals.el'" |