Commit 1540e4e9 authored by Karl Heuer's avatar Karl Heuer
Browse files

(set-auto-mode): Recognize `#!/bin/env INTERPRETER' hack.

parent 1bdabbcd
...@@ -1108,12 +1108,14 @@ If `enable-local-variables' is nil, this function does not check for a ...@@ -1108,12 +1108,14 @@ If `enable-local-variables' is nil, this function does not check for a
(funcall mode) (funcall mode)
;; If we can't deduce a mode from the file name, ;; If we can't deduce a mode from the file name,
;; look for an interpreter specified in the first line. ;; look for an interpreter specified in the first line.
;; As a special case, allow for things like "#!/bin/env perl",
;; which finds the interpreter anywhere in $PATH.
(let ((interpreter (let ((interpreter
(save-excursion (save-excursion
(goto-char (point-min)) (goto-char (point-min))
(if (looking-at "#! *\\([^ \t\n]+\\)") (if (looking-at "#! *\\([^ \t\n]*/bin/env +\\)?\\([^ \t\n]+\\)")
(buffer-substring (match-beginning 1) (buffer-substring (match-beginning 2)
(match-end 1)) (match-end 2))
""))) "")))
elt) elt)
;; Map interpreter name to a mode. ;; Map interpreter name to a mode.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment