Mercurial > emacs
comparison lisp/files.el @ 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 | 8fd47a5040cb |
children | 64fa4e0f3fce |
comparison
equal
deleted
inserted
replaced
5955:459bb5807c0b | 5956:586a37656a31 |
---|---|
837 Visiting a file whose name matches REGEXP causes FUNCTION to be called. | 837 Visiting a file whose name matches REGEXP causes FUNCTION to be called. |
838 If the element has the form (REGEXP FUNCTION), then after calling | 838 If the element has the form (REGEXP FUNCTION), then after calling |
839 FUNCTION, we delete the suffix that matched REGEXP and search the list | 839 FUNCTION, we delete the suffix that matched REGEXP and search the list |
840 again for another match.") | 840 again 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. | |
850 This alist applies to files whose first line starts with `#!'. | |
851 Each element looks like (INTERPRETER . MODE). | |
852 The car of each element is compared with | |
853 the name of the interpreter specified in the first line. | |
854 If 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 |
845 (defvar user-init-file | 859 (defvar user-init-file |
846 "" ; set by command-line | 860 "" ; set by command-line |
926 name (substring name 0 (match-beginning 0)) | 940 name (substring name 0 (match-beginning 0)) |
927 keep-going t)) | 941 keep-going t)) |
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. |
935 ;; Ignore any specification for `mode:'; | 967 ;; Ignore any specification for `mode:'; |
936 ;; set-auto-mode should already have handled that. | 968 ;; set-auto-mode should already have handled that. |