Mercurial > emacs
changeset 5956:586a37656a31
(interpreter-mode-alist): New variable.
(set-auto-mode): Use that for chosing a mode.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 16 Feb 1994 07:06:10 +0000 |
parents | 459bb5807c0b |
children | 334f7ce7c8db |
files | lisp/files.el |
diffstat | 1 files changed, 33 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/files.el Tue Feb 15 22:38:00 1994 +0000 +++ b/lisp/files.el Wed Feb 16 07:06:10 1994 +0000 @@ -839,6 +839,20 @@ FUNCTION, we delete the suffix that matched REGEXP and search the list again for another match.") +(defconst interpreter-mode-alist + '(("perl" . perl-mode) + ("scope" . tcl-mode) + ("wish" . tcl-mode) + ("shell" . tcl-mode) + ("form" . tcl-mode) + ("tcl" . tcl-mode)) + "Alist mapping interpreter names to major modes. +This alist applies to files whose first line starts with `#!'. +Each element looks like (INTERPRETER . MODE). +The car of each element is compared with +the name of the interpreter specified in the first line. +If it matches, mode MODE is selected.") + (defconst inhibit-local-variables-regexps '("\\.tar$") "List of regexps; if one matches a file name, don't look for local vars.") @@ -928,7 +942,25 @@ (setq mode (cdr (car alist)) keep-going nil))) (setq alist (cdr alist))) - (if mode (funcall mode))))))))) + (if mode + (funcall mode) + ;; If we can't deduce a mode from the file name, + ;; look for an interpreter specified in the first line. + (let ((interpreter + (save-excursion + (goto-char (point-min)) + (if (looking-at "#! *") + (progn + (goto-char (match-end 0)) + (buffer-substring (point) + (progn (end-of-line) (point)))) + ""))) + elt) + ;; Map interpreter name to a mode. + (setq elt (assoc (file-name-nondirectory interpreter) + interpreter-mode-alist)) + (if elt + (funcall (cdr elt)))))))))))) (defun hack-local-variables-prop-line () ;; Set local variables specified in the -*- line.