[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#64939: 30.0.50; The default auto-mode-interpreter-regexp does not ma
From: |
Wilhelm Kirschbaum |
Subject: |
bug#64939: 30.0.50; The default auto-mode-interpreter-regexp does not match env with flags |
Date: |
Sat, 29 Jul 2023 23:38:07 +0200 |
User-agent: |
mu4e 1.9.3; emacs 30.0.50 |
A file without an extension will load ruby-mode if the first
line is:
#!/usr/bin/env ruby
but not when the first line is:
#!/usr/bin/env -S ruby -e 'puts 123'
Is there any reason why the latter should not be matched by the
default
`auto-mode-interpreter-regexp' value in 'files.el'?
A more useful example I stumbled on today while working on a
language
server after adding:
`(add-to-list 'interpreter-mode-alist '("elixir"
. elixir-ts-mode))'
#!/usr/bin/env -S elixir --erl "-kernel standard_io_encoding
latin1"
Node.start(:"next-ls-#{System.system_time()}", :shortnames)
....
Wilhelm
This is a very naive solution to the above, but I am probably
missing some
knowledge here and will break for anyone setting the var to
something
custom.
modified lisp/files.el
@@ -3243,7 +3243,7 @@ inhibit-local-variables-p
(defvar auto-mode-interpreter-regexp
(purecopy "#![ \t]?\\([^ \t\n]*\
-/bin/env[ \t]\\)?\\([^ \t\n]+\\)")
+/bin/env[ \t]\\)?\\(-\\{1,2\\}[a-zA-Z1-9=]+[ \t]+\\)?\\([^
\t\n]+\\)")
"Regexp matching interpreters, for file mode determination.
This regular expression is matched against the first line of a
file
to determine the file's mode in `set-auto-mode'. If it matches,
the file
@@ -3445,7 +3445,7 @@ set-auto-mode
(setq mode (save-excursion
(goto-char (point-min))
(if (looking-at
auto-mode-interpreter-regexp)
- (match-string 2))))
+ (match-string 3))))
;; Map interpreter name to a mode, signaling we're done
at the
;; same time.
(setq done (assoc-default
modified lisp/progmodes/sh-script.el
@@ -1481,7 +1481,7 @@ sh--guess-shell
(cond ((save-excursion
(goto-char (point-min))
(looking-at auto-mode-interpreter-regexp))
- (match-string 2))
+ (match-string 3))
((not buffer-file-name) sh-shell-file)
;; Checks that use `buffer-file-name' follow.
((string-match "\\.m?spec\\'" buffer-file-name) "rpm")
bug#64939: 30.0.50; The default auto-mode-interpreter-regexp does not match env with flags, Eli Zaretskii, 2023/07/30