aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1994-02-16 07:06:10 +0000
committerRichard M. Stallman1994-02-16 07:06:10 +0000
commitc907d15634537a32bb5f54ea036221af92f7e2c7 (patch)
tree1dca450d62d7b5852b6645d6896f212a2be137b9
parent6a588f9a70107f1bdcbfa033470418131b45c067 (diff)
downloademacs-c907d15634537a32bb5f54ea036221af92f7e2c7.tar.gz
emacs-c907d15634537a32bb5f54ea036221af92f7e2c7.zip
(interpreter-mode-alist): New variable.
(set-auto-mode): Use that for chosing a mode.
-rw-r--r--lisp/files.el34
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
839FUNCTION, we delete the suffix that matched REGEXP and search the list 839FUNCTION, we delete the suffix that matched REGEXP and search the list
840again for another match.") 840again for another match.")
841 841
842(defconst interpreter-mode-alist
843 '(("perl" . perl-mode)
844 ("scope" . tcl-mode)
845 ("wish" . tcl-mode)
846 ("shell" . tcl-mode)
847 ("form" . tcl-mode)
848 ("tcl" . tcl-mode))
849 "Alist mapping interpreter names to major modes.
850This alist applies to files whose first line starts with `#!'.
851Each element looks like (INTERPRETER . MODE).
852The car of each element is compared with
853the name of the interpreter specified in the first line.
854If it matches, mode MODE is selected.")
855
842(defconst inhibit-local-variables-regexps '("\\.tar$") 856(defconst inhibit-local-variables-regexps '("\\.tar$")
843 "List of regexps; if one matches a file name, don't look for local vars.") 857 "List of regexps; if one matches a file name, don't look for local vars.")
844 858
@@ -928,7 +942,25 @@ If `enable-local-variables' is nil, this function does not check for a
928 (setq mode (cdr (car alist)) 942 (setq mode (cdr (car alist))
929 keep-going nil))) 943 keep-going nil)))
930 (setq alist (cdr alist))) 944 (setq alist (cdr alist)))
931 (if mode (funcall mode))))))))) 945 (if mode
946 (funcall mode)
947 ;; If we can't deduce a mode from the file name,
948 ;; look for an interpreter specified in the first line.
949 (let ((interpreter
950 (save-excursion
951 (goto-char (point-min))
952 (if (looking-at "#! *")
953 (progn
954 (goto-char (match-end 0))
955 (buffer-substring (point)
956 (progn (end-of-line) (point))))
957 "")))
958 elt)
959 ;; Map interpreter name to a mode.
960 (setq elt (assoc (file-name-nondirectory interpreter)
961 interpreter-mode-alist))
962 (if elt
963 (funcall (cdr elt))))))))))))
932 964
933(defun hack-local-variables-prop-line () 965(defun hack-local-variables-prop-line ()
934 ;; Set local variables specified in the -*- line. 966 ;; Set local variables specified in the -*- line.