/[emacs]/emacs/lisp/files.el
ViewVC logotype

Diff of /emacs/lisp/files.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.583.2.22 by miles, Wed Oct 6 05:23:54 2004 UTC revision 1.583.2.23 by miles, Fri Oct 29 02:05:09 2004 UTC
# Line 1645  in that case, this function acts as if ` Line 1645  in that case, this function acts as if `
1645    (mapc    (mapc
1646     (lambda (elt)     (lambda (elt)
1647       (cons (purecopy (car elt)) (cdr elt)))       (cons (purecopy (car elt)) (cdr elt)))
1648     '(("\\.te?xt\\'" . text-mode)     '(;; do this first, so that .html.pl is Polish html, not Perl
1649       ("\\.tex\\'" . tex-mode)       ("\\.s?html?\\(\\.[a-zA-Z_]+\\)?\\'" . html-mode)
1650         ("\\.te?xt\\'" . text-mode)
1651         ("\\.[tT]e[xX]\\'" . tex-mode)
1652       ("\\.ins\\'" . tex-mode)           ;Installation files for TeX packages.       ("\\.ins\\'" . tex-mode)           ;Installation files for TeX packages.
1653       ("\\.ltx\\'" . latex-mode)       ("\\.ltx\\'" . latex-mode)
1654       ("\\.dtx\\'" . doctex-mode)       ("\\.dtx\\'" . doctex-mode)
1655       ("\\.el\\'" . emacs-lisp-mode)       ("\\.el\\'" . emacs-lisp-mode)
1656       ("\\.\\(scm\\|stk\\|ss\\|sch\\)\\'" . scheme-mode)       ("\\.\\(scm\\|stk\\|ss\\|sch\\)\\'" . scheme-mode)
1657       ("\\.l\\'" . lisp-mode)       ("\\.l\\'" . lisp-mode)
1658       ("\\.lisp\\'" . lisp-mode)       ("\\.li?sp\\'" . lisp-mode)
1659       ("\\.f\\'" . fortran-mode)       ("\\.[fF]\\'" . fortran-mode)
      ("\\.F\\'" . fortran-mode)  
1660       ("\\.for\\'" . fortran-mode)       ("\\.for\\'" . fortran-mode)
1661       ("\\.p\\'" . pascal-mode)       ("\\.p\\'" . pascal-mode)
1662       ("\\.pas\\'" . pascal-mode)       ("\\.pas\\'" . pascal-mode)
1663       ("\\.ad[abs]\\'" . ada-mode)       ("\\.ad[abs]\\'" . ada-mode)
1664       ("\\.ad[bs].dg\\'" . ada-mode)       ("\\.ad[bs].dg\\'" . ada-mode)
1665       ("\\.\\([pP]\\([Llm]\\|erl\\)\\|al\\)\\'" . perl-mode)       ("\\.\\([pP]\\([Llm]\\|erl\\|od\\)\\|al\\)\\'" . perl-mode)
      ("\\.s?html?\\'" . html-mode)  
1666       ("\\.mk\\'" . makefile-mode)       ("\\.mk\\'" . makefile-mode)
1667       ("\\(M\\|m\\|GNUm\\)akefile\\'" . makefile-mode)       ("\\([Mm]\\|GNUm\\)akep*file\\'" . makefile-mode)
1668       ("\\.am\\'" . makefile-mode)       ;For Automake.       ("\\.am\\'" . makefile-mode)       ;For Automake.
1669       ;; Less common extensions come here       ;; Less common extensions come here
1670       ;; so more common ones above are found faster.       ;; so more common ones above are found faster.
1671       ("\\.texinfo\\'" . texinfo-mode)       ("\\.texinfo\\'" . texinfo-mode)
1672       ("\\.te?xi\\'" . texinfo-mode)       ("\\.te?xi\\'" . texinfo-mode)
1673       ("\\.s\\'" . asm-mode)       ("\\.[sS]\\'" . asm-mode)
      ("\\.S\\'" . asm-mode)  
1674       ("\\.asm\\'" . asm-mode)       ("\\.asm\\'" . asm-mode)
1675       ("ChangeLog\\'" . change-log-mode)       ("[cC]hange\\.?[lL]og?\\'" . change-log-mode)
1676       ("change\\.log\\'" . change-log-mode)       ("[cC]hange[lL]og\\.[0-9]+\\'" . change-log-mode)
      ("changelo\\'" . change-log-mode)  
      ("ChangeLog\\.[0-9]+\\'" . change-log-mode)  
      ;; for MSDOS and MS-Windows (which are case-insensitive)  
      ("changelog\\'" . change-log-mode)  
      ("changelog\\.[0-9]+\\'" . change-log-mode)  
1677       ("\\$CHANGE_LOG\\$\\.TXT" . change-log-mode)       ("\\$CHANGE_LOG\\$\\.TXT" . change-log-mode)
1678       ("\\.scm\\.[0-9]*\\'" . scheme-mode)       ("\\.scm\\.[0-9]*\\'" . scheme-mode)
1679       ("\\.[ck]?sh\\'\\|\\.shar\\'\\|/\\.z?profile\\'" . sh-mode)       ("\\.[ck]?sh\\'\\|\\.shar\\'\\|/\\.z?profile\\'" . sh-mode)
# Line 1688  in that case, this function acts as if ` Line 1682  in that case, this function acts as if `
1682       ("\\(/\\|\\`\\)\\.\\(bash_logout\\|shrc\\|[kz]shrc\\|bashrc\\|t?cshrc\\|esrc\\)\\'" . sh-mode)       ("\\(/\\|\\`\\)\\.\\(bash_logout\\|shrc\\|[kz]shrc\\|bashrc\\|t?cshrc\\|esrc\\)\\'" . sh-mode)
1683       ("\\(/\\|\\`\\)\\.\\([kz]shenv\\|xinitrc\\|startxrc\\|xsession\\)\\'" . sh-mode)       ("\\(/\\|\\`\\)\\.\\([kz]shenv\\|xinitrc\\|startxrc\\|xsession\\)\\'" . sh-mode)
1684       ("\\.m?spec\\'" . sh-mode)       ("\\.m?spec\\'" . sh-mode)
1685       ("\\.mm\\'" . nroff-mode)       ("\\.m[mes]\\'" . nroff-mode)
      ("\\.me\\'" . nroff-mode)  
      ("\\.ms\\'" . nroff-mode)  
1686       ("\\.man\\'" . nroff-mode)       ("\\.man\\'" . nroff-mode)
      ("\\.TeX\\'" . tex-mode)  
1687       ("\\.sty\\'" . latex-mode)       ("\\.sty\\'" . latex-mode)
1688       ("\\.cls\\'" . latex-mode)         ;LaTeX 2e class       ("\\.cl[so]\\'" . latex-mode)              ;LaTeX 2e class option
      ("\\.clo\\'" . latex-mode)         ;LaTeX 2e class option  
1689       ("\\.bbl\\'" . latex-mode)       ("\\.bbl\\'" . latex-mode)
1690       ("\\.bib\\'" . bibtex-mode)       ("\\.bib\\'" . bibtex-mode)
1691       ("\\.sql\\'" . sql-mode)       ("\\.sql\\'" . sql-mode)
1692       ("\\.m4\\'" . m4-mode)       ("\\.m[4c]\\'" . m4-mode)
      ("\\.mc\\'" . m4-mode)  
1693       ("\\.mf\\'" . metafont-mode)       ("\\.mf\\'" . metafont-mode)
1694       ("\\.mp\\'" . metapost-mode)       ("\\.mp\\'" . metapost-mode)
1695       ("\\.vhdl?\\'" . vhdl-mode)       ("\\.vhdl?\\'" . vhdl-mode)
1696       ("\\.article\\'" . text-mode)       ("\\.article\\'" . text-mode)
1697       ("\\.letter\\'" . text-mode)       ("\\.letter\\'" . text-mode)
1698       ("\\.tcl\\'" . tcl-mode)       ("\\.i?tcl\\'" . tcl-mode)
1699       ("\\.exp\\'" . tcl-mode)       ("\\.exp\\'" . tcl-mode)
      ("\\.itcl\\'" . tcl-mode)  
1700       ("\\.itk\\'" . tcl-mode)       ("\\.itk\\'" . tcl-mode)
1701       ("\\.icn\\'" . icon-mode)       ("\\.icn\\'" . icon-mode)
1702       ("\\.sim\\'" . simula-mode)       ("\\.sim\\'" . simula-mode)
1703       ("\\.mss\\'" . scribe-mode)       ("\\.mss\\'" . scribe-mode)
1704       ("\\.f90\\'" . f90-mode)       ("\\.f9[05]\\'" . f90-mode)
      ("\\.f95\\'" . f90-mode)  
1705       ("\\.indent\\.pro\\'" . fundamental-mode) ; to avoid idlwave-mode       ("\\.indent\\.pro\\'" . fundamental-mode) ; to avoid idlwave-mode
1706       ("\\.pro\\'" . idlwave-mode)       ("\\.pro\\'" . idlwave-mode)
      ("\\.lsp\\'" . lisp-mode)  
1707       ("\\.prolog\\'" . prolog-mode)       ("\\.prolog\\'" . prolog-mode)
1708       ("\\.tar\\'" . tar-mode)       ("\\.tar\\'" . tar-mode)
1709       ("\\.\\(arc\\|zip\\|lzh\\|zoo\\|ear\\|jar\\|war\\)\\'" . archive-mode)       ("\\.\\(arc\\|zip\\|lzh\\|zoo\\|ear\\|jar\\|war\\)\\'" . archive-mode)
# Line 1733  in that case, this function acts as if ` Line 1719  in that case, this function acts as if `
1719       ("\\`/tmp/fol/" . text-mode)       ("\\`/tmp/fol/" . text-mode)
1720       ("\\.oak\\'" . scheme-mode)       ("\\.oak\\'" . scheme-mode)
1721       ("\\.sgml?\\'" . sgml-mode)       ("\\.sgml?\\'" . sgml-mode)
1722       ("\\.xml\\'" . sgml-mode)       ("\\.x[ms]l\\'" . xml-mode)
      ("\\.xsl\\'" . sgml-mode)  
1723       ("\\.dtd\\'" . sgml-mode)       ("\\.dtd\\'" . sgml-mode)
1724       ("\\.ds\\(ss\\)?l\\'" . dsssl-mode)       ("\\.ds\\(ss\\)?l\\'" . dsssl-mode)
1725         ("\\.js\\'" . java-mode)           ; javascript-mode would be better
1726         ("\\.x[bp]m\\'" . c-mode)
1727       ;; .emacs or .gnus or .viper following a directory delimiter in       ;; .emacs or .gnus or .viper following a directory delimiter in
1728       ;; Unix, MSDOG or VMS syntax.       ;; Unix, MSDOG or VMS syntax.
1729       ("[]>:/\\]\\..*\\(emacs\\|gnus\\|viper\\)\\'" . emacs-lisp-mode)       ("[]>:/\\]\\..*\\(emacs\\|gnus\\|viper\\)\\'" . emacs-lisp-mode)
# Line 1760  in that case, this function acts as if ` Line 1747  in that case, this function acts as if `
1747       ;; or .#<file>.<rev>-<rev> or VC's <file>.~<rev>~.       ;; or .#<file>.<rev>-<rev> or VC's <file>.~<rev>~.
1748       ;; Using mode nil rather than `ignore' would let the search continue       ;; Using mode nil rather than `ignore' would let the search continue
1749       ;; through this list (with the shortened name) rather than start over.       ;; through this list (with the shortened name) rather than start over.
1750       ("\\.~?[0-9]+\\.[0-9][-.0-9]*~?\\'" ignore t)       ("\\.~?[0-9]+\\.[0-9][-.0-9]*~?\\'" nil t)
1751       ;; The following should come after the ChangeLog pattern       ;; The following should come after the ChangeLog pattern
1752       ;; for the sake of ChangeLog.1, etc.       ;; for the sake of ChangeLog.1, etc.
1753       ;; and after the .scm.[0-9] and CVS' <file>.<rev> patterns too.       ;; and after the .scm.[0-9] and CVS' <file>.<rev> patterns too.
# Line 1849  be interpreted by the interpreter matche Line 1836  be interpreted by the interpreter matche
1836  regular expression.  The mode is then determined as the mode associated  regular expression.  The mode is then determined as the mode associated
1837  with that interpreter in `interpreter-mode-alist'.")  with that interpreter in `interpreter-mode-alist'.")
1838    
1839  (defun set-auto-mode (&optional just-from-file-name)  (defvar xml-based-modes '(html-mode)
1840      "Modes that override an XML declaration.
1841    When `set-auto-mode' sees an <?xml or <!DOCTYPE declaration, that
1842    buffer will be in some XML mode.  If `auto-mode-alist' associates
1843    the file with one of the modes in this list, that mode will be
1844    used.  Else `xml-mode' or `sgml-mode' is used.")
1845    
1846    (defun set-auto-mode (&optional keep-mode-if-same)
1847    "Select major mode appropriate for current buffer.    "Select major mode appropriate for current buffer.
1848  This checks for a -*- mode tag in the buffer's text,  This checks for a -*- mode tag in the buffer's text, checks the
1849  compares the filename against the entries in `auto-mode-alist',  interpreter that runs this file against `interpreter-mode-alist',
1850  or checks the interpreter that runs this file against  looks for an <?xml or <!DOCTYPE declaration (see
1851  `interpreter-mode-alist'.  `xml-based-modes'), or compares the filename against the entries
1852    in `auto-mode-alist'.
1853    
1854  It does not check for the `mode:' local variable in the  It does not check for the `mode:' local variable in the
1855  Local Variables section of the file; for that, use `hack-local-variables'.  Local Variables section of the file; for that, use `hack-local-variables'.
# Line 1862  Local Variables section of the file; for Line 1857  Local Variables section of the file; for
1857  If `enable-local-variables' is nil, this function does not check for a  If `enable-local-variables' is nil, this function does not check for a
1858  -*- mode tag.  -*- mode tag.
1859    
1860  If the optional argument JUST-FROM-FILE-NAME is non-nil,  If the optional argument KEEP-MODE-IF-SAME is non-nil, then we
1861  then we do not set anything but the major mode,  only set the major mode, if that would change it."
 and we don't even do that unless it would come from the file name."  
1862    ;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*-    ;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*-
1863    (let (end done modes)    (let (end done mode modes xml)
1864        ;; Find a -*- mode tag
1865      (save-excursion      (save-excursion
1866        (goto-char (point-min))        (goto-char (point-min))
1867        (skip-chars-forward " \t\n")        (skip-chars-forward " \t\n")
1868          ;; While we're at this point, check xml for later.
1869          (setq xml (looking-at "<\\?xml \\|<!DOCTYPE"))
1870        (and enable-local-variables        (and enable-local-variables
1871             (setq end (set-auto-mode-1))             (setq end (set-auto-mode-1))
1872             (if (save-excursion (search-forward ":" end t))             (if (save-excursion (search-forward ":" end t))
# Line 1891  and we don't even do that unless it woul Line 1888  and we don't even do that unless it woul
1888               (push (intern (concat (downcase (buffer-substring (point) end))               (push (intern (concat (downcase (buffer-substring (point) end))
1889                                     "-mode"))                                     "-mode"))
1890                     modes))))                     modes))))
1891      ;; If we found modes to use, invoke them now,      ;; If we found modes to use, invoke them now, outside the save-excursion.
1892      ;; outside the save-excursion.      (if modes
1893      (unless just-from-file-name          (catch 'nop
1894        (dolist (mode (nreverse modes))            (dolist (mode (nreverse modes))
1895          (if (not (functionp mode))              (if (not (functionp mode))
1896              (message "Ignoring unknown mode `%s'" mode)                  (message "Ignoring unknown mode `%s'" mode)
1897            (setq done t)                (setq done t)
1898            (funcall mode))))                (or (set-auto-mode-0 mode)
1899      ;; If we didn't find a mode from a -*- line, try using the file name.                    (throw 'nop nil)))))
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
1902          ;; finds the interpreter anywhere in $PATH.
1903          (setq mode (save-excursion
1904                       (goto-char (point-min))
1905                       (if (looking-at auto-mode-interpreter-regexp)
1906                           (match-string 2)
1907                         ""))
1908                ;; Map interpreter name to a mode, signalling we're done at the
1909                ;; same time.
1910                done (assoc (file-name-nondirectory mode)
1911                            interpreter-mode-alist))
1912          ;; If we found an interpreter mode to use, invoke it now.
1913          (if done (set-auto-mode-0 (cdr done))))
1914      (if (and (not done) buffer-file-name)      (if (and (not done) buffer-file-name)
1915          (let ((name buffer-file-name)          (let ((name buffer-file-name))
               (keep-going t))  
1916            ;; Remove backup-suffixes from file name.            ;; Remove backup-suffixes from file name.
1917            (setq name (file-name-sans-versions name))            (setq name (file-name-sans-versions name))
1918            (while keep-going            (while name
1919              (setq keep-going nil)              ;; Find first matching alist entry.
1920              (let ((alist auto-mode-alist)              (let ((case-fold-search
1921                    (mode nil))                     (memq system-type '(vax-vms windows-nt cygwin))))
1922                ;; Find first matching alist entry.                (if (and (setq mode (assoc-default name auto-mode-alist
1923                (let ((case-fold-search                                                   'string-match))
1924                       (memq system-type '(vax-vms windows-nt cygwin))))                         (consp mode)
1925                  (while (and (not mode) alist)                         (cadr mode))
1926                    (if (string-match (car (car alist)) name)                    (setq mode (car mode)
1927                        (if (and (consp (cdr (car alist)))                          name (substring name 0 (match-beginning 0)))
1928                                 (nth 2 (car alist)))                  (setq name)))
1929                            (setq mode (car (cdr (car alist)))              (when mode
1930                                  name (substring name 0 (match-beginning 0))                (if xml (or (memq mode xml-based-modes)
1931                                  keep-going t)                            (setq mode 'xml-mode)))
1932                          (setq mode (cdr (car alist))                (set-auto-mode-0 mode)
1933                                keep-going nil)))                (setq done t)))))
1934                    (setq alist (cdr alist))))      (and xml
1935                (if mode           (not done)
1936                    ;; When JUST-FROM-FILE-NAME is set,           (set-auto-mode-0 'xml-mode))))
1937                    ;; we are working on behalf of set-visited-file-name.  
1938                    ;; In that case, if the major mode specified is the  
1939                    ;; same one we already have, don't actually reset it.  ;; When `keep-mode-if-same' is set, we are working on behalf of
1940                    ;; We don't want to lose minor modes such as Font Lock.  ;; set-visited-file-name.  In that case, if the major mode specified is the
1941                    (unless (and just-from-file-name (eq mode major-mode))  ;; same one we already have, don't actually reset it.  We don't want to lose
1942                      (funcall mode))  ;; minor modes such as Font Lock.
1943                  ;; If we can't deduce a mode from the file name,  (defun set-auto-mode-0 (mode)
1944                  ;; look for an interpreter specified in the first line.    "Apply MODE and return it.
1945                  ;; As a special case, allow for things like "#!/bin/env perl",  If `keep-mode-if-same' is non-nil MODE is chased of any aliases and
1946                  ;; which finds the interpreter anywhere in $PATH.  compared to current major mode.  If they are the same, do nothing
1947                  (let ((interpreter  and return nil."
1948                         (save-excursion    (when keep-mode-if-same
1949                           (goto-char (point-min))      (while (symbolp (symbol-function mode))
1950                           (if (looking-at auto-mode-interpreter-regexp)        (setq mode (symbol-function mode)))
1951                               (match-string 2)      (if (eq mode major-mode)
1952                             "")))          (setq mode)))
1953                        elt)    (when mode
1954                    ;; Map interpreter name to a mode.      (funcall mode)
1955                    (setq elt (assoc (file-name-nondirectory interpreter)      mode))
                                    interpreter-mode-alist))  
                   (unless just-from-file-name  
                     (if elt  
                         (funcall (cdr elt))))))))))))  
1956    
1957    
1958  (defun set-auto-mode-1 ()  (defun set-auto-mode-1 ()
# Line 2157  is specified, returning t if it is speci Line 2163  is specified, returning t if it is speci
2163                          (error "Local variables entry is missing the suffix")))                          (error "Local variables entry is missing the suffix")))
2164                    (forward-line 1))                    (forward-line 1))
2165                  (goto-char (point-min))                  (goto-char (point-min))
2166                      
2167                  (while (not (eobp))                  (while (not (eobp))
2168                    ;; Find the variable name; strip whitespace.                    ;; Find the variable name; strip whitespace.
2169                    (skip-chars-forward " \t")                    (skip-chars-forward " \t")

Legend:
Removed from v.1.583.2.22  
changed lines
  Added in v.1.583.2.23

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26