1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-12-02 08:22:22 +00:00

(set-auto-mode-0): Don't rely on dynamic binding of

keep-mode-if-same variable.  Add it as optional arg instead.
(set-auto-mode): Call set-auto-mode-0 with keep-mode-if-same.
This commit is contained in:
Kim F. Storm 2004-11-01 23:16:42 +00:00
parent ad8d994cbe
commit 3467488ee7

View File

@ -1896,7 +1896,7 @@ only set the major mode, if that would change it."
(if (not (functionp mode))
(message "Ignoring unknown mode `%s'" mode)
(setq done t)
(or (set-auto-mode-0 mode)
(or (set-auto-mode-0 mode keep-mode-if-same)
(throw 'nop nil)))))
;; 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
@ -1911,7 +1911,7 @@ only set the major mode, if that would change it."
done (assoc (file-name-nondirectory mode)
interpreter-mode-alist))
;; If we found an interpreter mode to use, invoke it now.
(if done (set-auto-mode-0 (cdr done))))
(if done (set-auto-mode-0 (cdr done) keep-mode-if-same)))
(if (and (not done) buffer-file-name)
(let ((name buffer-file-name))
;; Remove backup-suffixes from file name.
@ -1930,27 +1930,27 @@ only set the major mode, if that would change it."
(when mode
(if xml (or (memq mode xml-based-modes)
(setq mode 'xml-mode)))
(set-auto-mode-0 mode)
(set-auto-mode-0 mode keep-mode-if-same)
(setq done t)))))
(and xml
(not done)
(set-auto-mode-0 'xml-mode))))
(set-auto-mode-0 'xml-mode keep-mode-if-same))))
;; 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)
(defun set-auto-mode-0 (mode &optional keep-mode-if-same)
"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."
If optional arg 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)))
(setq mode nil)))
(when mode
(funcall mode)
mode))