Commit 81860e46 authored by Richard M. Stallman's avatar Richard M. Stallman
Browse files

(set-auto-mode): Handle (REGEXP FUNCTION t) elements.

parent 9ba43e12
...@@ -830,8 +830,11 @@ run `normal-mode' explicitly." ...@@ -830,8 +830,11 @@ run `normal-mode' explicitly."
("\\.ml\\'" . lisp-mode))) ("\\.ml\\'" . lisp-mode)))
"\ "\
Alist of filename patterns vs corresponding major mode functions. Alist of filename patterns vs corresponding major mode functions.
Each element looks like (REGEXP . FUNCTION). Each element looks like (REGEXP . FUNCTION) or (REGEXP FUNCTION).
Visiting a file whose name matches REGEXP causes FUNCTION to be called.") 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$") (defconst inhibit-local-variables-regexps '("\\.tar$")
"List of regexps; if one matches a file name, don't look for local vars.") "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,7 +846,7 @@ Visiting a file whose name matches REGEXP causes FUNCTION to be called.")
(defun set-auto-mode () (defun set-auto-mode ()
"Select major mode appropriate for current buffer. "Select major mode appropriate for current buffer.
This checks for a -*- mode tag in the buffer's text, or 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 not check for the \"mode:\" local variable in the Local Variables
section of the file; for that, use `hack-local-variables'. section of the file; for that, use `hack-local-variables'.
...@@ -901,18 +904,28 @@ If `enable-local-variables' is nil, this function does not check for a ...@@ -901,18 +904,28 @@ If `enable-local-variables' is nil, this function does not check for a
(setq done t))) (setq done t)))
;; If we didn't find a mode from a -*- line, try using the file name. ;; If we didn't find a mode from a -*- line, try using the file name.
(if (and (not done) buffer-file-name) (if (and (not done) buffer-file-name)
(let ((alist auto-mode-alist) (let ((name buffer-file-name)
(name buffer-file-name) (case-fold-search (eq system-type 'vax-vms))
mode) (keep-going t))
(let ((case-fold-search (eq system-type 'vax-vms)))
;; Remove backup-suffixes from file name. ;; Remove backup-suffixes from file name.
(setq name (file-name-sans-versions 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. ;; Find first matching alist entry.
(while (and (not mode) alist) (while (and (not mode) alist)
(if (string-match (car (car alist)) name) (if (string-match (car (car alist)) name)
(setq mode (cdr (car alist)))) (if (and (consp (cdr (car alist)))
(setq alist (cdr alist)))) (nth 2 (car alist)))
(if mode (funcall mode))))))) (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 () (defun hack-local-variables-prop-line ()
;; Set local variables specified in the -*- line. ;; Set local variables specified in the -*- line.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment