aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/files.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/files.el')
-rw-r--r--lisp/files.el68
1 files changed, 46 insertions, 22 deletions
diff --git a/lisp/files.el b/lisp/files.el
index 75d9965133c..d0f3b47f2b5 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -1751,6 +1751,30 @@ in that case, this function acts as if `enable-local-variables' were t."
1751 ("BROWSE\\'" . ebrowse-tree-mode) 1751 ("BROWSE\\'" . ebrowse-tree-mode)
1752 ("\\.ebrowse\\'" . ebrowse-tree-mode) 1752 ("\\.ebrowse\\'" . ebrowse-tree-mode)
1753 ("#\\*mail\\*" . mail-mode) 1753 ("#\\*mail\\*" . mail-mode)
1754 ("\\.g\\'" . antlr-mode)
1755 ("\\.ses\\'" . ses-mode)
1756 ("\\.\\(soa\\|zone\\)\\'" . dns-mode)
1757 ("\\.docbook\\'" . sgml-mode)
1758 ("/config\\.\\(?:bat\\|log\\)\\'" . fundamental-mode)
1759 ;; Windows candidates may be opened case sensitively on Unix
1760 ("\\.\\(?:[iI][nN][iI]\\|[lL][sS][tT]\\|[rR][eE][gG]\\|[sS][yY][sS]\\)\\'" . conf-mode)
1761 ("\\.\\(?:desktop\\|la\\)\\'" . conf-unix-mode)
1762 ("java.+\\.conf\\'" . conf-javaprop-mode)
1763 ("\\.properties\\(?:\\.[a-zA-Z0-9._-]+\\)?\\'" . conf-javaprop-mode)
1764 ;; *.cf, *.cfg, *.conf, *.config[.local|.de_DE.UTF8|...], */config
1765 ("[/.]c\\(?:on\\)?f\\(?:i?g\\)?\\(?:\\.[a-zA-Z0-9._-]+\\)?\\'" . conf-mode)
1766 ("\\`/etc/\\(?:DIR_COLORS\\|ethers\\|.?fstab\\|.*hosts\\|lesskey\\|login\\.?de\\(?:fs\\|vperm\\)\\|magic\\|mtab\\|permissions\\|protocols\\|rpc\\|services\\)\\'" . conf-space-mode)
1767 ("\\`/etc/\\(?:aliases\\|hosts\\..+\\|ksysguarddrc\\|opera6rc\\)\\'" . conf-mode)
1768 ;; either user's dot-files or under /etc or some such
1769 ("/\\.?\\(?:gnokiirc\\|kde.*rc\\|mime\\.types\\|wgetrc\\)\\'" . conf-mode)
1770 ;; alas not all ~/.*rc files are like this
1771 ("/\\.\\(?:enigma\\|gltron\\|hxplayer\\|net\\|neverball\\|qt/.+\\|realplayer\\|scummvm\\|sversion\\|sylpheed/.+\\|xmp\\)rc\\'" . conf-mode)
1772 ("/\\.\\(?:gdbtkinit\\|grip\\|orbital/.+txt\\|rhosts\\|tuxracer/options\\)\\'" . conf-mode)
1773 ("/\\.?X\\(?:default\\|resource\\|re\\)s\\>" . conf-xdefaults-mode)
1774 ("/X11.+app-defaults/" . conf-xdefaults-mode)
1775 ("/X11.+locale/.+/Compose\\'" . conf-colon-mode)
1776 ;; this contains everything twice, with space and with colon :-(
1777 ("/X11.+locale/compose\\.dir\\'" . conf-javaprop-mode)
1754 ;; Get rid of any trailing .n.m and try again. 1778 ;; Get rid of any trailing .n.m and try again.
1755 ;; This is for files saved by cvs-merge that look like .#<file>.<rev> 1779 ;; This is for files saved by cvs-merge that look like .#<file>.<rev>
1756 ;; or .#<file>.<rev>-<rev> or VC's <file>.~<rev>~. 1780 ;; or .#<file>.<rev>-<rev> or VC's <file>.~<rev>~.
@@ -1761,11 +1785,7 @@ in that case, this function acts as if `enable-local-variables' were t."
1761 ;; for the sake of ChangeLog.1, etc. 1785 ;; for the sake of ChangeLog.1, etc.
1762 ;; and after the .scm.[0-9] and CVS' <file>.<rev> patterns too. 1786 ;; and after the .scm.[0-9] and CVS' <file>.<rev> patterns too.
1763 ("\\.[1-9]\\'" . nroff-mode) 1787 ("\\.[1-9]\\'" . nroff-mode)
1764 ("\\.g\\'" . antlr-mode) 1788 ("\\.\\(?:orig\\|in\\|[bB][aA][kK]\\)\\'" nil t)))
1765 ("\\.ses\\'" . ses-mode)
1766 ("\\.orig\\'" nil t) ; from patch
1767 ("\\.\\(soa\\|zone\\)\\'" . dns-mode)
1768 ("\\.in\\'" nil t)))
1769 "Alist of filename patterns vs corresponding major mode functions. 1789 "Alist of filename patterns vs corresponding major mode functions.
1770Each element looks like (REGEXP . FUNCTION) or (REGEXP FUNCTION NON-NIL). 1790Each element looks like (REGEXP . FUNCTION) or (REGEXP FUNCTION NON-NIL).
1771\(NON-NIL stands for anything that is not nil; the value does not matter.) 1791\(NON-NIL stands for anything that is not nil; the value does not matter.)
@@ -1846,26 +1866,32 @@ regular expression. The mode is then determined as the mode associated
1846with that interpreter in `interpreter-mode-alist'.") 1866with that interpreter in `interpreter-mode-alist'.")
1847 1867
1848(defvar magic-mode-alist 1868(defvar magic-mode-alist
1849 '(;; The < comes before the groups (but the first) to reduce backtracking. 1869 `(;; The < comes before the groups (but the first) to reduce backtracking.
1850 ;; Is there a nicer way of getting . including \n?
1851 ;; TODO: UTF-16 <?xml may be preceded by a BOM 0xff 0xfe or 0xfe 0xff. 1870 ;; TODO: UTF-16 <?xml may be preceded by a BOM 0xff 0xfe or 0xfe 0xff.
1852 ("\\(?:<\\?xml\\s +[^>]*>\\)?\\s *<\\(?:!--\\(?:.\\|\n\\)*?-->\\s *<\\)*\\(?:!DOCTYPE\\s +[^>]*>\\s *<\\)?\\s *\\(?:!--\\(?:.\\|\n\\)*?-->\\s *<\\)*[Hh][Tt][Mm][Ll]" . html-mode) 1871 (,(let* ((incomment-re "\\(?:[^-]\\|-[^-]\\)")
1872 (comment-re (concat "\\(?:!--" incomment-re "*-->\\s *<\\)")))
1873 (concat "\\(?:<\\?xml\\s +[^>]*>\\)?\\s *<"
1874 comment-re "*"
1875 "\\(?:!DOCTYPE\\s +[^>]*>\\s *<\\s *" comment-re "*\\)?"
1876 "[Hh][Tt][Mm][Ll]")) . html-mode)
1853 ;; These two must come after html, because they are more general: 1877 ;; These two must come after html, because they are more general:
1854 ("<\\?xml " . xml-mode) 1878 ("<\\?xml " . xml-mode)
1855 ("\\s *<\\(?:!--\\(?:.\\|\n\\)*?-->\\s *<\\)*!DOCTYPE " . sgml-mode) 1879 (,(let* ((incomment-re "\\(?:[^-]\\|-[^-]\\)")
1856 ("%![^V]" . ps-mode)) 1880 (comment-re (concat "\\(?:!--" incomment-re "*-->\\s *<\\)")))
1857 "Alist of buffer beginnings vs corresponding major mode functions. 1881 (concat "\\s *<" comment-re "*!DOCTYPE ")) . sgml-mode)
1882 ("%![^V]" . ps-mode)
1883 ("# xmcd " . conf-unix-mode))
1884 "Alist of buffer beginnings vs. corresponding major mode functions.
1858Each element looks like (REGEXP . FUNCTION). FUNCTION will be 1885Each element looks like (REGEXP . FUNCTION). FUNCTION will be
1859called, unless it is nil.") 1886called, unless it is nil (to allow `auto-mode-alist' to override).")
1860 1887
1861(defun set-auto-mode (&optional keep-mode-if-same) 1888(defun set-auto-mode (&optional keep-mode-if-same)
1862 "Select major mode appropriate for current buffer. 1889 "Select major mode appropriate for current buffer.
1863 1890
1864This checks for a -*- mode tag in the buffer's text, checks the 1891This checks for a -*- mode tag in the buffer's text, checks the
1865interpreter that runs this file against `interpreter-mode-alist', 1892interpreter that runs this file against `interpreter-mode-alist',
1866compares the buffer beginning against `magic-mode-alist', 1893compares the buffer beginning against `magic-mode-alist', or
1867or compares the filename against the entries in 1894compares the filename against the entries in `auto-mode-alist'.
1868`auto-mode-alist'.
1869 1895
1870It does not check for the `mode:' local variable in the 1896It does not check for the `mode:' local variable in the
1871Local Variables section of the file; for that, use `hack-local-variables'. 1897Local Variables section of the file; for that, use `hack-local-variables'.
@@ -1876,13 +1902,11 @@ If `enable-local-variables' is nil, this function does not check for a
1876If the optional argument KEEP-MODE-IF-SAME is non-nil, then we 1902If the optional argument KEEP-MODE-IF-SAME is non-nil, then we
1877only set the major mode, if that would change it." 1903only set the major mode, if that would change it."
1878 ;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*- 1904 ;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*-
1879 (let (end done mode modes xml) 1905 (let (end done mode modes)
1880 ;; Find a -*- mode tag 1906 ;; Find a -*- mode tag
1881 (save-excursion 1907 (save-excursion
1882 (goto-char (point-min)) 1908 (goto-char (point-min))
1883 (skip-chars-forward " \t\n") 1909 (skip-chars-forward " \t\n")
1884 ;; While we're at this point, check xml for later.
1885 (setq xml (looking-at "<\\?xml \\|<!DOCTYPE"))
1886 (and enable-local-variables 1910 (and enable-local-variables
1887 (setq end (set-auto-mode-1)) 1911 (setq end (set-auto-mode-1))
1888 (if (save-excursion (search-forward ":" end t)) 1912 (if (save-excursion (search-forward ":" end t))
@@ -1926,9 +1950,10 @@ only set the major mode, if that would change it."
1926 ;; same time. 1950 ;; same time.
1927 done (assoc (file-name-nondirectory mode) 1951 done (assoc (file-name-nondirectory mode)
1928 interpreter-mode-alist)) 1952 interpreter-mode-alist))
1953 ;; If we found an interpreter mode to use, invoke it now.
1929 (if done 1954 (if done
1930 (set-auto-mode-0 (cdr done) keep-mode-if-same))) 1955 (set-auto-mode-0 (cdr done) keep-mode-if-same)))
1931 ;; If we found an interpreter mode to use, invoke it now. 1956 ;; If we didn't, match the buffer beginning against magic-mode-alist.
1932 (unless done 1957 (unless done
1933 (if (setq done (save-excursion 1958 (if (setq done (save-excursion
1934 (goto-char (point-min)) 1959 (goto-char (point-min))
@@ -1936,6 +1961,7 @@ only set the major mode, if that would change it."
1936 (lambda (re dummy) 1961 (lambda (re dummy)
1937 (looking-at re))))) 1962 (looking-at re)))))
1938 (set-auto-mode-0 done keep-mode-if-same) 1963 (set-auto-mode-0 done keep-mode-if-same)
1964 ;; Compare the filename against the entries in auto-mode-alist.
1939 (if buffer-file-name 1965 (if buffer-file-name
1940 (let ((name buffer-file-name)) 1966 (let ((name buffer-file-name))
1941 ;; Remove backup-suffixes from file name. 1967 ;; Remove backup-suffixes from file name.
@@ -1945,7 +1971,7 @@ only set the major mode, if that would change it."
1945 (let ((case-fold-search 1971 (let ((case-fold-search
1946 (memq system-type '(vax-vms windows-nt cygwin)))) 1972 (memq system-type '(vax-vms windows-nt cygwin))))
1947 (if (and (setq mode (assoc-default name auto-mode-alist 1973 (if (and (setq mode (assoc-default name auto-mode-alist
1948 'string-match)) 1974 'string-match))
1949 (consp mode) 1975 (consp mode)
1950 (cadr mode)) 1976 (cadr mode))
1951 (setq mode (car mode) 1977 (setq mode (car mode)
@@ -1954,7 +1980,6 @@ only set the major mode, if that would change it."
1954 (when mode 1980 (when mode
1955 (set-auto-mode-0 mode keep-mode-if-same))))))))) 1981 (set-auto-mode-0 mode keep-mode-if-same)))))))))
1956 1982
1957
1958;; When `keep-mode-if-same' is set, we are working on behalf of 1983;; When `keep-mode-if-same' is set, we are working on behalf of
1959;; set-visited-file-name. In that case, if the major mode specified is the 1984;; set-visited-file-name. In that case, if the major mode specified is the
1960;; same one we already have, don't actually reset it. We don't want to lose 1985;; same one we already have, don't actually reset it. We don't want to lose
@@ -1973,7 +1998,6 @@ same, do nothing and return nil."
1973 (funcall mode) 1998 (funcall mode)
1974 mode)) 1999 mode))
1975 2000
1976
1977(defun set-auto-mode-1 () 2001(defun set-auto-mode-1 ()
1978 "Find the -*- spec in the buffer. 2002 "Find the -*- spec in the buffer.
1979Call with point at the place to start searching from. 2003Call with point at the place to start searching from.