diff options
| author | Daniel Pfeiffer | 2004-11-03 21:44:49 +0000 |
|---|---|---|
| committer | Daniel Pfeiffer | 2004-11-03 21:44:49 +0000 |
| commit | 4ac1d37a80316cc0a013326f1ebbdfe166d4928a (patch) | |
| tree | d84f033a5bf54650e3be18d3f3f3cd92b4083ccd | |
| parent | b44a1825e5b5de262b51dde301a145ec3f59cf98 (diff) | |
| download | emacs-4ac1d37a80316cc0a013326f1ebbdfe166d4928a.tar.gz emacs-4ac1d37a80316cc0a013326f1ebbdfe166d4928a.zip | |
(xml-based-modes): Delete var.
(magic-mode-alist): New var.
(set-auto-mode): Use it.
| -rw-r--r-- | lisp/files.el | 76 |
1 files changed, 42 insertions, 34 deletions
diff --git a/lisp/files.el b/lisp/files.el index 888f9dc81e9..901e0a65f6b 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -1845,20 +1845,27 @@ be interpreted by the interpreter matched by the second group of the | |||
| 1845 | regular expression. The mode is then determined as the mode associated | 1845 | regular expression. The mode is then determined as the mode associated |
| 1846 | with that interpreter in `interpreter-mode-alist'.") | 1846 | with that interpreter in `interpreter-mode-alist'.") |
| 1847 | 1847 | ||
| 1848 | (defvar xml-based-modes '(html-mode) | 1848 | (defvar magic-mode-alist |
| 1849 | "Modes that override an XML declaration. | 1849 | '(;; The < comes before the groups (but the first) to reduce backtracking. |
| 1850 | When `set-auto-mode' sees an <?xml or <!DOCTYPE declaration, that | 1850 | ;; Is there a nicer way of getting . including \n? |
| 1851 | buffer will be in some XML mode. If `auto-mode-alist' associates | 1851 | ;; TODO: UTF-16 <?xml may be preceded by a BOM 0xff 0xfe or 0xfe 0xff. |
| 1852 | the file with one of the modes in this list, that mode will be | 1852 | ("\\(?:<\\?xml\\s +[^>]*>\\)?\\s *<\\(?:!--\\(?:.\\|\n\\)*?-->\\s *<\\)*\\(?:!DOCTYPE\\s +[^>]*>\\s *<\\)?\\s *\\(?:!--\\(?:.\\|\n\\)*?-->\\s *<\\)*[Hh][Tt][Mm][Ll]" . html-mode) |
| 1853 | used. Else `xml-mode' or `sgml-mode' is used.") | 1853 | ;; These two must come after html, because they are more general: |
| 1854 | ("<\\?xml " . xml-mode) | ||
| 1855 | ("\\s *<\\(?:!--\\(?:.\\|\n\\)*?-->\\s *<\\)*!DOCTYPE " . sgml-mode) | ||
| 1856 | ("%![^V]" . ps-mode)) | ||
| 1857 | "Alist of buffer beginnings vs corresponding major mode functions. | ||
| 1858 | Each element looks like (REGEXP . FUNCTION). FUNCTION will be | ||
| 1859 | called, unless it is nil.") | ||
| 1854 | 1860 | ||
| 1855 | (defun set-auto-mode (&optional keep-mode-if-same) | 1861 | (defun set-auto-mode (&optional keep-mode-if-same) |
| 1856 | "Select major mode appropriate for current buffer. | 1862 | "Select major mode appropriate for current buffer. |
| 1863 | |||
| 1857 | This checks for a -*- mode tag in the buffer's text, checks the | 1864 | This checks for a -*- mode tag in the buffer's text, checks the |
| 1858 | interpreter that runs this file against `interpreter-mode-alist', | 1865 | interpreter that runs this file against `interpreter-mode-alist', |
| 1859 | looks for an <?xml or <!DOCTYPE declaration (see | 1866 | compares the buffer beginning against `magic-mode-alist', |
| 1860 | `xml-based-modes'), or compares the filename against the entries | 1867 | or compares the filename against the entries in |
| 1861 | in `auto-mode-alist'. | 1868 | `auto-mode-alist'. |
| 1862 | 1869 | ||
| 1863 | It does not check for the `mode:' local variable in the | 1870 | It does not check for the `mode:' local variable in the |
| 1864 | Local Variables section of the file; for that, use `hack-local-variables'. | 1871 | Local Variables section of the file; for that, use `hack-local-variables'. |
| @@ -1917,32 +1924,33 @@ only set the major mode, if that would change it." | |||
| 1917 | ;; Map interpreter name to a mode, signalling we're done at the | 1924 | ;; Map interpreter name to a mode, signalling we're done at the |
| 1918 | ;; same time. | 1925 | ;; same time. |
| 1919 | done (assoc (file-name-nondirectory mode) | 1926 | done (assoc (file-name-nondirectory mode) |
| 1920 | interpreter-mode-alist)) | 1927 | interpreter-mode-alist))) |
| 1921 | ;; If we found an interpreter mode to use, invoke it now. | 1928 | ;; If we found an interpreter mode to use, invoke it now. |
| 1922 | (if done (set-auto-mode-0 (cdr done) keep-mode-if-same))) | 1929 | (if done |
| 1923 | (if (and (not done) buffer-file-name) | 1930 | (set-auto-mode-0 (cdr done) keep-mode-if-same) |
| 1924 | (let ((name buffer-file-name)) | 1931 | (if (setq done (save-excursion |
| 1925 | ;; Remove backup-suffixes from file name. | 1932 | (goto-char (point-min)) |
| 1926 | (setq name (file-name-sans-versions name)) | 1933 | (assoc-default nil magic-mode-alist |
| 1927 | (while name | 1934 | (lambda (re dummy) |
| 1928 | ;; Find first matching alist entry. | 1935 | (looking-at re))))) |
| 1929 | (let ((case-fold-search | 1936 | (set-auto-mode-0 done keep-mode-if-same) |
| 1930 | (memq system-type '(vax-vms windows-nt cygwin)))) | 1937 | (if buffer-file-name |
| 1931 | (if (and (setq mode (assoc-default name auto-mode-alist | 1938 | (let ((name buffer-file-name)) |
| 1939 | ;; Remove backup-suffixes from file name. | ||
| 1940 | (setq name (file-name-sans-versions name)) | ||
| 1941 | (while name | ||
| 1942 | ;; Find first matching alist entry. | ||
| 1943 | (let ((case-fold-search | ||
| 1944 | (memq system-type '(vax-vms windows-nt cygwin)))) | ||
| 1945 | (if (and (setq mode (assoc-default name auto-mode-alist | ||
| 1932 | 'string-match)) | 1946 | 'string-match)) |
| 1933 | (consp mode) | 1947 | (consp mode) |
| 1934 | (cadr mode)) | 1948 | (cadr mode)) |
| 1935 | (setq mode (car mode) | 1949 | (setq mode (car mode) |
| 1936 | name (substring name 0 (match-beginning 0))) | 1950 | name (substring name 0 (match-beginning 0))) |
| 1937 | (setq name))) | 1951 | (setq name))) |
| 1938 | (when mode | 1952 | (when mode |
| 1939 | (if xml (or (memq mode xml-based-modes) | 1953 | (set-auto-mode-0 mode keep-mode-if-same))))))))) |
| 1940 | (setq mode 'xml-mode))) | ||
| 1941 | (set-auto-mode-0 mode keep-mode-if-same) | ||
| 1942 | (setq done t))))) | ||
| 1943 | (and xml | ||
| 1944 | (not done) | ||
| 1945 | (set-auto-mode-0 'xml-mode keep-mode-if-same)))) | ||
| 1946 | 1954 | ||
| 1947 | 1955 | ||
| 1948 | ;; When `keep-mode-if-same' is set, we are working on behalf of | 1956 | ;; When `keep-mode-if-same' is set, we are working on behalf of |