Mercurial > emacs
changeset 57763:9fe5facda191
(set-auto-mode-0): New function.
(set-auto-mode): Use it to handle aliased modes and to be consistent between C-x C-f and C-x C-w.
author | Daniel Pfeiffer <occitan@esperanto.org> |
---|---|
date | Thu, 28 Oct 2004 06:05:17 +0000 |
parents | fc395ecab9c6 |
children | b4f2fd007dda |
files | lisp/files.el |
diffstat | 1 files changed, 34 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/files.el Thu Oct 28 02:00:28 2004 +0000 +++ b/lisp/files.el Thu Oct 28 06:05:17 2004 +0000 @@ -1857,9 +1857,8 @@ If `enable-local-variables' is nil, this function does not check for a -*- mode tag. -If the optional argument KEEP-MODE-IF-SAME is non-nil, -then we do not set anything but the major mode, -and we don't even do that unless it would come from the file name." +If the optional argument KEEP-MODE-IF-SAME is non-nil, then we +only set the major mode, if that would change it." ;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*- (let (end done mode modes xml) ;; Find a -*- mode tag @@ -1891,12 +1890,13 @@ modes)))) ;; If we found modes to use, invoke them now, outside the save-excursion. (if modes - (dolist (mode (nreverse modes)) - (if (not (functionp mode)) - (message "Ignoring unknown mode `%s'" mode) - (setq done t) - (unless (if keep-mode-if-same (eq mode major-mode)) - (funcall mode)))) + (catch 'nop + (dolist (mode (nreverse modes)) + (if (not (functionp mode)) + (message "Ignoring unknown mode `%s'" mode) + (setq done t) + (or (set-auto-mode-0 mode) + (throw 'nop))))) ;; If we didn't, look for an interpreter specified in the first line. ;; As a special case, allow for things like "#!/bin/env perl", which ;; finds the interpreter anywhere in $PATH. @@ -1910,9 +1910,7 @@ done (assoc (file-name-nondirectory mode) interpreter-mode-alist)) ;; If we found an interpreter mode to use, invoke it now. - (and done - (not (if keep-mode-if-same (eq mode major-mode))) - (funcall (cdr done)))) + (if done (set-auto-mode-0 (cdr done)))) (if (and (not done) buffer-file-name) (let ((name buffer-file-name)) ;; Remove backup-suffixes from file name. @@ -1930,19 +1928,31 @@ (setq name))) (when mode (if xml (or (memq mode xml-based-modes) - (setq mode 'sgml-mode))) ; alias to xml-mode for `eq' - ;; When KEEP-MODE-IF-SAME is set, we are working on behalf of - ;; set-visited-file-name. In that case, if the major mode - ;; specified is the same one we already have, don't actually - ;; reset it. We don't want to lose minor modes such as Font - ;; Lock. - (unless (if keep-mode-if-same (eq mode major-mode)) - (funcall mode)) + (setq mode 'xml-mode))) + (set-auto-mode-0 mode) (setq done t))))) - (and (not done) - xml - (not (if keep-mode-if-same (eq 'sgml-mode major-mode))) - (xml-mode)))) + (and xml + (not done) + (set-auto-mode-0 'xml-mode)))) + + +;; When `keep-mode-if-same' is set, we are working on behalf of +;; set-visited-file-name. In that case, if the major mode specified is the +;; same one we already have, don't actually reset it. We don't want to lose +;; minor modes such as Font Lock. +(defun set-auto-mode-0 (mode) + "Apply MODE and return it. +If `keep-mode-if-same' is non-nil MODE is chased of any aliases and +compared to current major mode. If they are the same, do nothing +and return nil." + (when keep-mode-if-same + (while (symbolp (symbol-function mode)) + (setq mode (symbol-function mode))) + (if (eq mode major-mode) + (setq mode))) + (when mode + (funcall mode) + mode)) (defun set-auto-mode-1 ()