aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1994-01-15 15:55:59 +0000
committerRichard M. Stallman1994-01-15 15:55:59 +0000
commit81860e46eba7ec673a69223d07566e427ea43799 (patch)
tree8547fa3d246bac70560867a151a919a6937b242c
parent9ba43e124a7c4c96b7a0efb1486a0f7e3fbbd880 (diff)
downloademacs-81860e46eba7ec673a69223d07566e427ea43799.tar.gz
emacs-81860e46eba7ec673a69223d07566e427ea43799.zip
(set-auto-mode): Handle (REGEXP FUNCTION t) elements.
-rw-r--r--lisp/files.el43
1 files changed, 28 insertions, 15 deletions
diff --git a/lisp/files.el b/lisp/files.el
index 47e2d74a16a..0422362a0ec 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -830,8 +830,11 @@ run `normal-mode' explicitly."
830 ("\\.ml\\'" . lisp-mode))) 830 ("\\.ml\\'" . lisp-mode)))
831 "\ 831 "\
832Alist of filename patterns vs corresponding major mode functions. 832Alist of filename patterns vs corresponding major mode functions.
833Each element looks like (REGEXP . FUNCTION). 833Each element looks like (REGEXP . FUNCTION) or (REGEXP FUNCTION).
834Visiting a file whose name matches REGEXP causes FUNCTION to be called.") 834Visiting a file whose name matches REGEXP causes FUNCTION to be called.
835If the element has the form (REGEXP FUNCTION), then after calling
836FUNCTION, we delete the suffix that matched REGEXP and search the list
837again for another match.")
835 838
836(defconst inhibit-local-variables-regexps '("\\.tar$") 839(defconst inhibit-local-variables-regexps '("\\.tar$")
837 "List of regexps; if one matches a file name, don't look for local vars.") 840 "List of regexps; if one matches a file name, don't look for local vars.")
@@ -843,7 +846,7 @@ Visiting a file whose name matches REGEXP causes FUNCTION to be called.")
843(defun set-auto-mode () 846(defun set-auto-mode ()
844 "Select major mode appropriate for current buffer. 847 "Select major mode appropriate for current buffer.
845This checks for a -*- mode tag in the buffer's text, or 848This checks for a -*- mode tag in the buffer's text, or
846compares the filename against the entries in auto-mode-alist. It does 849compares the filename against the entries in `auto-mode-alist'. It does
847not check for the \"mode:\" local variable in the Local Variables 850not check for the \"mode:\" local variable in the Local Variables
848section of the file; for that, use `hack-local-variables'. 851section of the file; for that, use `hack-local-variables'.
849 852
@@ -901,18 +904,28 @@ If `enable-local-variables' is nil, this function does not check for a
901 (setq done t))) 904 (setq done t)))
902 ;; If we didn't find a mode from a -*- line, try using the file name. 905 ;; If we didn't find a mode from a -*- line, try using the file name.
903 (if (and (not done) buffer-file-name) 906 (if (and (not done) buffer-file-name)
904 (let ((alist auto-mode-alist) 907 (let ((name buffer-file-name)
905 (name buffer-file-name) 908 (case-fold-search (eq system-type 'vax-vms))
906 mode) 909 (keep-going t))
907 (let ((case-fold-search (eq system-type 'vax-vms))) 910 ;; Remove backup-suffixes from file name.
908 ;; Remove backup-suffixes from file name. 911 (setq name (file-name-sans-versions name))
909 (setq name (file-name-sans-versions name)) 912 (while keep-going
910 ;; Find first matching alist entry. 913 (setq keep-going nil)
911 (while (and (not mode) alist) 914 (let ((alist auto-mode-alist)
912 (if (string-match (car (car alist)) name) 915 (mode nil))
913 (setq mode (cdr (car alist)))) 916 ;; Find first matching alist entry.
914 (setq alist (cdr alist)))) 917 (while (and (not mode) alist)
915 (if mode (funcall mode))))))) 918 (if (string-match (car (car alist)) name)
919 (if (and (consp (cdr (car alist)))
920 (nth 2 (car alist)))
921 (progn
922 (setq mode (car (cdr (car alist)))
923 name (substring name 0 (match-beginning 0))
924 keep-going t))
925 (setq mode (cdr (car alist))
926 keep-going nil)))
927 (setq alist (cdr alist)))
928 (if mode (funcall mode))))))))))
916 929
917(defun hack-local-variables-prop-line () 930(defun hack-local-variables-prop-line ()
918 ;; Set local variables specified in the -*- line. 931 ;; Set local variables specified in the -*- line.