1876 |
"[Hh][Tt][Mm][Ll]")) . html-mode) |
"[Hh][Tt][Mm][Ll]")) . html-mode) |
1877 |
;; These two must come after html, because they are more general: |
;; These two must come after html, because they are more general: |
1878 |
("<\\?xml " . xml-mode) |
("<\\?xml " . xml-mode) |
1879 |
("\\s *<\\(?:!--\\(?:.\\|\n\\)*?-->\\s *<\\)*!DOCTYPE " . sgml-mode) |
(,(let* ((incomment-re "\\(?:[^-]\\|-[^-]\\)") |
1880 |
|
(comment-re (concat "\\(?:!--" incomment-re "*-->\\s *<\\)"))) |
1881 |
|
(concat "\\s *<" comment-re "*!DOCTYPE ")) . sgml-mode) |
1882 |
("%![^V]" . ps-mode) |
("%![^V]" . ps-mode) |
1883 |
("# xmcd " . conf-unix-mode)) |
("# xmcd " . conf-unix-mode)) |
1884 |
"Alist of buffer beginnings vs. corresponding major mode functions. |
"Alist of buffer beginnings vs. corresponding major mode functions. |
1890 |
|
|
1891 |
This checks for a -*- mode tag in the buffer's text, checks the |
This checks for a -*- mode tag in the buffer's text, checks the |
1892 |
interpreter that runs this file against `interpreter-mode-alist', |
interpreter that runs this file against `interpreter-mode-alist', |
1893 |
compares the buffer beginning against `magic-mode-alist', |
compares the buffer beginning against `magic-mode-alist', or |
1894 |
or compares the filename against the entries in |
compares the filename against the entries in `auto-mode-alist'. |
|
`auto-mode-alist'. |
|
1895 |
|
|
1896 |
It does not check for the `mode:' local variable in the |
It does not check for the `mode:' local variable in the |
1897 |
Local Variables section of the file; for that, use `hack-local-variables'. |
Local Variables section of the file; for that, use `hack-local-variables'. |
1902 |
If the optional argument KEEP-MODE-IF-SAME is non-nil, then we |
If the optional argument KEEP-MODE-IF-SAME is non-nil, then we |
1903 |
only set the major mode, if that would change it." |
only set the major mode, if that would change it." |
1904 |
;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*- |
;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*- |
1905 |
(let (end done mode modes xml) |
(let (end done mode modes) |
1906 |
;; Find a -*- mode tag |
;; Find a -*- mode tag |
1907 |
(save-excursion |
(save-excursion |
1908 |
(goto-char (point-min)) |
(goto-char (point-min)) |
1909 |
(skip-chars-forward " \t\n") |
(skip-chars-forward " \t\n") |
|
;; While we're at this point, check xml for later. |
|
|
(setq xml (looking-at "<\\?xml \\|<!DOCTYPE")) |
|
1910 |
(and enable-local-variables |
(and enable-local-variables |
1911 |
(setq end (set-auto-mode-1)) |
(setq end (set-auto-mode-1)) |
1912 |
(if (save-excursion (search-forward ":" end t)) |
(if (save-excursion (search-forward ":" end t)) |
1950 |
;; same time. |
;; same time. |
1951 |
done (assoc (file-name-nondirectory mode) |
done (assoc (file-name-nondirectory mode) |
1952 |
interpreter-mode-alist)) |
interpreter-mode-alist)) |
1953 |
|
;; If we found an interpreter mode to use, invoke it now. |
1954 |
(if done |
(if done |
1955 |
(set-auto-mode-0 (cdr done) keep-mode-if-same))) |
(set-auto-mode-0 (cdr done) keep-mode-if-same))) |
1956 |
;; If we found an interpreter mode to use, invoke it now. |
;; If we didn't, match the buffer beginning against magic-mode-alist. |
1957 |
(unless done |
(unless done |
1958 |
(if (setq done (save-excursion |
(if (setq done (save-excursion |
1959 |
(goto-char (point-min)) |
(goto-char (point-min)) |
1961 |
(lambda (re dummy) |
(lambda (re dummy) |
1962 |
(looking-at re))))) |
(looking-at re))))) |
1963 |
(set-auto-mode-0 done keep-mode-if-same) |
(set-auto-mode-0 done keep-mode-if-same) |
1964 |
|
;; Compare the filename against the entries in auto-mode-alist. |
1965 |
(if buffer-file-name |
(if buffer-file-name |
1966 |
(let ((name buffer-file-name)) |
(let ((name buffer-file-name)) |
1967 |
;; Remove backup-suffixes from file name. |
;; Remove backup-suffixes from file name. |
1971 |
(let ((case-fold-search |
(let ((case-fold-search |
1972 |
(memq system-type '(vax-vms windows-nt cygwin)))) |
(memq system-type '(vax-vms windows-nt cygwin)))) |
1973 |
(if (and (setq mode (assoc-default name auto-mode-alist |
(if (and (setq mode (assoc-default name auto-mode-alist |
1974 |
'string-match)) |
'string-match)) |
1975 |
(consp mode) |
(consp mode) |
1976 |
(cadr mode)) |
(cadr mode)) |
1977 |
(setq mode (car mode) |
(setq mode (car mode) |
1980 |
(when mode |
(when mode |
1981 |
(set-auto-mode-0 mode keep-mode-if-same))))))))) |
(set-auto-mode-0 mode keep-mode-if-same))))))))) |
1982 |
|
|
|
|
|
1983 |
;; 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 |
1984 |
;; 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 |
1985 |
;; 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 |
1998 |
(funcall mode) |
(funcall mode) |
1999 |
mode)) |
mode)) |
2000 |
|
|
|
|
|
2001 |
(defun set-auto-mode-1 () |
(defun set-auto-mode-1 () |
2002 |
"Find the -*- spec in the buffer. |
"Find the -*- spec in the buffer. |
2003 |
Call with point at the place to start searching from. |
Call with point at the place to start searching from. |