aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Pfeiffer2004-10-28 06:09:55 +0000
committerDaniel Pfeiffer2004-10-28 06:09:55 +0000
commit521cf174c35d062a90b05358f23d9f8d60f64c36 (patch)
tree63810cbd4fe8ad0303c412cfae94caf65bde111b
parent7d9d5480e3ac2b7f5abfe3ab7b3e423ea50943ab (diff)
downloademacs-521cf174c35d062a90b05358f23d9f8d60f64c36.tar.gz
emacs-521cf174c35d062a90b05358f23d9f8d60f64c36.zip
(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.
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/files.el58
2 files changed, 40 insertions, 24 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 6467fe5408a..d731c8a9daa 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
12004-10-28 Daniel Pfeiffer <occitan@esperanto.org>
2
3 * files.el (set-auto-mode-0): New function.
4 (set-auto-mode): Use it to handle aliased modes and to
5 be consistent between C-x C-f and C-x C-w.
6
12004-10-28 Kenichi Handa <handa@m17n.org> 72004-10-28 Kenichi Handa <handa@m17n.org>
2 8
3 * international/utf-8.el (utf-translate-cjk-charsets): Add 9 * international/utf-8.el (utf-translate-cjk-charsets): Add
diff --git a/lisp/files.el b/lisp/files.el
index 09e7c76107a..83955d26fcc 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -1857,9 +1857,8 @@ Local Variables section of the file; for that, use `hack-local-variables'.
1857If `enable-local-variables' is nil, this function does not check for a 1857If `enable-local-variables' is nil, this function does not check for a
1858-*- mode tag. 1858-*- mode tag.
1859 1859
1860If the optional argument KEEP-MODE-IF-SAME is non-nil, 1860If the optional argument KEEP-MODE-IF-SAME is non-nil, then we
1861then we do not set anything but the major mode, 1861only set the major mode, if that would change it."
1862and we don't even do that unless it would come from the file name."
1863 ;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*- 1862 ;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*-
1864 (let (end done mode modes xml) 1863 (let (end done mode modes xml)
1865 ;; Find a -*- mode tag 1864 ;; Find a -*- mode tag
@@ -1891,12 +1890,13 @@ and we don't even do that unless it would come from the file name."
1891 modes)))) 1890 modes))))
1892 ;; If we found modes to use, invoke them now, outside the save-excursion. 1891 ;; If we found modes to use, invoke them now, outside the save-excursion.
1893 (if modes 1892 (if modes
1894 (dolist (mode (nreverse modes)) 1893 (catch 'nop
1895 (if (not (functionp mode)) 1894 (dolist (mode (nreverse modes))
1896 (message "Ignoring unknown mode `%s'" mode) 1895 (if (not (functionp mode))
1897 (setq done t) 1896 (message "Ignoring unknown mode `%s'" mode)
1898 (unless (if keep-mode-if-same (eq mode major-mode)) 1897 (setq done t)
1899 (funcall mode)))) 1898 (or (set-auto-mode-0 mode)
1899 (throw 'nop)))))
1900 ;; If we didn't, look for an interpreter specified in the first line. 1900 ;; If we didn't, look for an interpreter specified in the first line.
1901 ;; As a special case, allow for things like "#!/bin/env perl", which 1901 ;; As a special case, allow for things like "#!/bin/env perl", which
1902 ;; finds the interpreter anywhere in $PATH. 1902 ;; finds the interpreter anywhere in $PATH.
@@ -1910,9 +1910,7 @@ and we don't even do that unless it would come from the file name."
1910 done (assoc (file-name-nondirectory mode) 1910 done (assoc (file-name-nondirectory mode)
1911 interpreter-mode-alist)) 1911 interpreter-mode-alist))
1912 ;; If we found an interpreter mode to use, invoke it now. 1912 ;; If we found an interpreter mode to use, invoke it now.
1913 (and done 1913 (if done (set-auto-mode-0 (cdr done))))
1914 (not (if keep-mode-if-same (eq mode major-mode)))
1915 (funcall (cdr done))))
1916 (if (and (not done) buffer-file-name) 1914 (if (and (not done) buffer-file-name)
1917 (let ((name buffer-file-name)) 1915 (let ((name buffer-file-name))
1918 ;; Remove backup-suffixes from file name. 1916 ;; Remove backup-suffixes from file name.
@@ -1930,19 +1928,31 @@ and we don't even do that unless it would come from the file name."
1930 (setq name))) 1928 (setq name)))
1931 (when mode 1929 (when mode
1932 (if xml (or (memq mode xml-based-modes) 1930 (if xml (or (memq mode xml-based-modes)
1933 (setq mode 'sgml-mode))) ; alias to xml-mode for `eq' 1931 (setq mode 'xml-mode)))
1934 ;; When KEEP-MODE-IF-SAME is set, we are working on behalf of 1932 (set-auto-mode-0 mode)
1935 ;; set-visited-file-name. In that case, if the major mode
1936 ;; specified is the same one we already have, don't actually
1937 ;; reset it. We don't want to lose minor modes such as Font
1938 ;; Lock.
1939 (unless (if keep-mode-if-same (eq mode major-mode))
1940 (funcall mode))
1941 (setq done t))))) 1933 (setq done t)))))
1942 (and (not done) 1934 (and xml
1943 xml 1935 (not done)
1944 (not (if keep-mode-if-same (eq 'sgml-mode major-mode))) 1936 (set-auto-mode-0 'xml-mode))))
1945 (xml-mode)))) 1937
1938
1939;; When `keep-mode-if-same' is set, we are working on behalf of
1940;; set-visited-file-name. In that case, if the major mode specified is the
1941;; same one we already have, don't actually reset it. We don't want to lose
1942;; minor modes such as Font Lock.
1943(defun set-auto-mode-0 (mode)
1944 "Apply MODE and return it.
1945If `keep-mode-if-same' is non-nil MODE is chased of any aliases and
1946compared to current major mode. If they are the same, do nothing
1947and return nil."
1948 (when keep-mode-if-same
1949 (while (symbolp (symbol-function mode))
1950 (setq mode (symbol-function mode)))
1951 (if (eq mode major-mode)
1952 (setq mode)))
1953 (when mode
1954 (funcall mode)
1955 mode))
1946 1956
1947 1957
1948(defun set-auto-mode-1 () 1958(defun set-auto-mode-1 ()