changeset 5600:777597fbd048

(set-auto-mode): Handle (REGEXP FUNCTION t) elements.
author Richard M. Stallman <rms@gnu.org>
date Sat, 15 Jan 1994 15:55:59 +0000
parents 3b1a6c7f949e
children 8353962cfd74
files lisp/files.el
diffstat 1 files changed, 28 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/files.el	Sat Jan 15 15:20:34 1994 +0000
+++ b/lisp/files.el	Sat Jan 15 15:55:59 1994 +0000
@@ -830,8 +830,11 @@
 				  ("\\.ml\\'" . lisp-mode)))
   "\
 Alist of filename patterns vs corresponding major mode functions.
-Each element looks like (REGEXP . FUNCTION).
-Visiting a file whose name matches REGEXP causes FUNCTION to be called.")
+Each element looks like (REGEXP . FUNCTION) or (REGEXP FUNCTION).
+Visiting a file whose name matches REGEXP causes FUNCTION to be called.
+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 inhibit-local-variables-regexps '("\\.tar$")
   "List of regexps; if one matches a file name, don't look for local vars.")
@@ -843,7 +846,7 @@
 (defun set-auto-mode ()
   "Select major mode appropriate for current buffer.
 This checks for a -*- mode tag in the buffer's text, or
-compares the filename against the entries in auto-mode-alist.  It does
+compares the filename against the entries in `auto-mode-alist'.  It does
 not check for the \"mode:\" local variable in the Local Variables
 section of the file; for that, use `hack-local-variables'.
 
@@ -901,18 +904,28 @@
 	     (setq done t)))
       ;; If we didn't find a mode from a -*- line, try using the file name.
       (if (and (not done) buffer-file-name)
-	  (let ((alist auto-mode-alist)
-		(name buffer-file-name)
-		mode)
-	    (let ((case-fold-search (eq system-type 'vax-vms)))
-	      ;; Remove backup-suffixes from file name.
-	      (setq name (file-name-sans-versions name))
-	      ;; Find first matching alist entry.
-	      (while (and (not mode) alist)
-		(if (string-match (car (car alist)) name)
-		    (setq mode (cdr (car alist))))
-		(setq alist (cdr alist))))
-	    (if mode (funcall mode)))))))
+	  (let ((name buffer-file-name)
+		(case-fold-search (eq system-type 'vax-vms))
+		(keep-going t))
+	    ;; Remove backup-suffixes from file name.
+	    (setq name (file-name-sans-versions name))
+	    (while keep-going
+	      (setq keep-going nil)
+	      (let ((alist auto-mode-alist)
+		    (mode nil))
+		;; Find first matching alist entry.
+		(while (and (not mode) alist)
+		  (if (string-match (car (car alist)) name)
+		      (if (and (consp (cdr (car alist)))
+			       (nth 2 (car alist)))
+			  (progn
+			    (setq mode (car (cdr (car alist)))
+				  name (substring name 0 (match-beginning 0))
+				  keep-going t))
+			(setq mode (cdr (car alist))
+			      keep-going nil)))
+		  (setq alist (cdr alist)))
+		(if mode (funcall mode))))))))))
 
 (defun hack-local-variables-prop-line ()
   ;; Set local variables specified in the -*- line.