diff options
| author | Karl Heuer | 1995-12-15 21:11:52 +0000 |
|---|---|---|
| committer | Karl Heuer | 1995-12-15 21:11:52 +0000 |
| commit | 1540e4e9cc1ca84acba6e3aaf848e50c0f0156c7 (patch) | |
| tree | 18a180b3dcecd39b9c1f636ee6ec317525b47557 | |
| parent | 1bdabbcd2581b028662fc49ef6e101475d34d686 (diff) | |
| download | emacs-1540e4e9cc1ca84acba6e3aaf848e50c0f0156c7.tar.gz emacs-1540e4e9cc1ca84acba6e3aaf848e50c0f0156c7.zip | |
(set-auto-mode): Recognize `#!/bin/env INTERPRETER' hack.
| -rw-r--r-- | lisp/files.el | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/lisp/files.el b/lisp/files.el index 0f8f69c6bc4..11ed8883cb3 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -1108,12 +1108,14 @@ If `enable-local-variables' is nil, this function does not check for a | |||
| 1108 | (funcall mode) | 1108 | (funcall mode) |
| 1109 | ;; If we can't deduce a mode from the file name, | 1109 | ;; If we can't deduce a mode from the file name, |
| 1110 | ;; look for an interpreter specified in the first line. | 1110 | ;; look for an interpreter specified in the first line. |
| 1111 | ;; As a special case, allow for things like "#!/bin/env perl", | ||
| 1112 | ;; which finds the interpreter anywhere in $PATH. | ||
| 1111 | (let ((interpreter | 1113 | (let ((interpreter |
| 1112 | (save-excursion | 1114 | (save-excursion |
| 1113 | (goto-char (point-min)) | 1115 | (goto-char (point-min)) |
| 1114 | (if (looking-at "#! *\\([^ \t\n]+\\)") | 1116 | (if (looking-at "#! *\\([^ \t\n]*/bin/env +\\)?\\([^ \t\n]+\\)") |
| 1115 | (buffer-substring (match-beginning 1) | 1117 | (buffer-substring (match-beginning 2) |
| 1116 | (match-end 1)) | 1118 | (match-end 2)) |
| 1117 | ""))) | 1119 | ""))) |
| 1118 | elt) | 1120 | elt) |
| 1119 | ;; Map interpreter name to a mode. | 1121 | ;; Map interpreter name to a mode. |