diff options
| author | Richard M. Stallman <rms@gnu.org> | 1994-02-16 07:06:10 +0000 |
|---|---|---|
| committer | Richard M. Stallman <rms@gnu.org> | 1994-02-16 07:06:10 +0000 |
| commit | c907d15634537a32bb5f54ea036221af92f7e2c7 (patch) | |
| tree | 1dca450d62d7b5852b6645d6896f212a2be137b9 /lisp/files.el | |
| parent | 6a588f9a70107f1bdcbfa033470418131b45c067 (diff) | |
| download | emacs-c907d15634537a32bb5f54ea036221af92f7e2c7.tar.gz | |
(interpreter-mode-alist): New variable.
(set-auto-mode): Use that for chosing a mode.
Diffstat (limited to 'lisp/files.el')
| -rw-r--r-- | lisp/files.el | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/lisp/files.el b/lisp/files.el index d441cafcb56..00cc617d927 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -839,6 +839,20 @@ If the element has the form (REGEXP FUNCTION), then after calling 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 @@ If `enable-local-variables' is nil, this function does not check for a (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. |
