1896 |
(if (not (functionp mode)) |
(if (not (functionp mode)) |
1897 |
(message "Ignoring unknown mode `%s'" mode) |
(message "Ignoring unknown mode `%s'" mode) |
1898 |
(setq done t) |
(setq done t) |
1899 |
(or (set-auto-mode-0 mode) |
(or (set-auto-mode-0 mode keep-mode-if-same) |
1900 |
(throw 'nop nil))))) |
(throw 'nop nil))))) |
1901 |
;; If we didn't, look for an interpreter specified in the first line. |
;; If we didn't, look for an interpreter specified in the first line. |
1902 |
;; As a special case, allow for things like "#!/bin/env perl", which |
;; As a special case, allow for things like "#!/bin/env perl", which |
1911 |
done (assoc (file-name-nondirectory mode) |
done (assoc (file-name-nondirectory mode) |
1912 |
interpreter-mode-alist)) |
interpreter-mode-alist)) |
1913 |
;; If we found an interpreter mode to use, invoke it now. |
;; If we found an interpreter mode to use, invoke it now. |
1914 |
(if done (set-auto-mode-0 (cdr done)))) |
(if done (set-auto-mode-0 (cdr done) keep-mode-if-same))) |
1915 |
(if (and (not done) buffer-file-name) |
(if (and (not done) buffer-file-name) |
1916 |
(let ((name buffer-file-name)) |
(let ((name buffer-file-name)) |
1917 |
;; Remove backup-suffixes from file name. |
;; Remove backup-suffixes from file name. |
1930 |
(when mode |
(when mode |
1931 |
(if xml (or (memq mode xml-based-modes) |
(if xml (or (memq mode xml-based-modes) |
1932 |
(setq mode 'xml-mode))) |
(setq mode 'xml-mode))) |
1933 |
(set-auto-mode-0 mode) |
(set-auto-mode-0 mode keep-mode-if-same) |
1934 |
(setq done t))))) |
(setq done t))))) |
1935 |
(and xml |
(and xml |
1936 |
(not done) |
(not done) |
1937 |
(set-auto-mode-0 'xml-mode)))) |
(set-auto-mode-0 'xml-mode keep-mode-if-same)))) |
1938 |
|
|
1939 |
|
|
1940 |
;; When `keep-mode-if-same' is set, we are working on behalf of |
;; When `keep-mode-if-same' is set, we are working on behalf of |
1941 |
;; set-visited-file-name. In that case, if the major mode specified is the |
;; set-visited-file-name. In that case, if the major mode specified is the |
1942 |
;; same one we already have, don't actually reset it. We don't want to lose |
;; same one we already have, don't actually reset it. We don't want to lose |
1943 |
;; minor modes such as Font Lock. |
;; minor modes such as Font Lock. |
1944 |
(defun set-auto-mode-0 (mode) |
(defun set-auto-mode-0 (mode &optional keep-mode-if-same) |
1945 |
"Apply MODE and return it. |
"Apply MODE and return it. |
1946 |
If `keep-mode-if-same' is non-nil MODE is chased of any aliases and |
If optional arg KEEP-MODE-IF-SAME is non-nil, MODE is chased of |
1947 |
compared to current major mode. If they are the same, do nothing |
any aliases and compared to current major mode. If they are the |
1948 |
and return nil." |
same, do nothing and return nil." |
1949 |
(when keep-mode-if-same |
(when keep-mode-if-same |
1950 |
(while (symbolp (symbol-function mode)) |
(while (symbolp (symbol-function mode)) |
1951 |
(setq mode (symbol-function mode))) |
(setq mode (symbol-function mode))) |
1952 |
(if (eq mode major-mode) |
(if (eq mode major-mode) |
1953 |
(setq mode))) |
(setq mode nil))) |
1954 |
(when mode |
(when mode |
1955 |
(funcall mode) |
(funcall mode) |
1956 |
mode)) |
mode)) |