comparison lisp/files.el @ 13737:3902b2781a8f

(set-auto-mode): Recognize `#!/bin/env INTERPRETER' hack.
author Karl Heuer <kwzh@gnu.org>
date Fri, 15 Dec 1995 21:11:52 +0000
parents 40766c32c127
children 16b681bc9286
comparison
equal deleted inserted replaced
13736:4e7c5362c9bd 13737:3902b2781a8f
1106 (setq alist (cdr alist)))) 1106 (setq alist (cdr alist))))
1107 (if mode 1107 (if mode
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.
1120 (setq elt (assoc (file-name-nondirectory interpreter) 1122 (setq elt (assoc (file-name-nondirectory interpreter)
1121 interpreter-mode-alist)) 1123 interpreter-mode-alist))