Mercurial > emacs
comparison lisp/files.el @ 90037:0fe073a08cef
Revision: miles@gnu.org--gnu-2004/emacs--unicode--0--patch-65
Merge from emacs--cvs-trunk--0
Patches applied:
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-634
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-639
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-640
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-641
Update from CVS
* miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-59
- miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-60
Update from CVS
author | Miles Bader <miles@gnu.org> |
---|---|
date | Wed, 27 Oct 2004 05:42:04 +0000 |
parents | e23928ac5a97 557213a7ca17 |
children | e24e2e78deda |
comparison
equal
deleted
inserted
replaced
90036:af754c88f187 | 90037:0fe073a08cef |
---|---|
1644 ;; spreads out the definition of the initial value. | 1644 ;; spreads out the definition of the initial value. |
1645 (mapc | 1645 (mapc |
1646 (lambda (elt) | 1646 (lambda (elt) |
1647 (cons (purecopy (car elt)) (cdr elt))) | 1647 (cons (purecopy (car elt)) (cdr elt))) |
1648 '(("\\.te?xt\\'" . text-mode) | 1648 '(("\\.te?xt\\'" . text-mode) |
1649 ("\\.tex\\'" . tex-mode) | 1649 ("\\.[tT]e[xX]\\'" . tex-mode) |
1650 ("\\.ins\\'" . tex-mode) ;Installation files for TeX packages. | 1650 ("\\.ins\\'" . tex-mode) ;Installation files for TeX packages. |
1651 ("\\.ltx\\'" . latex-mode) | 1651 ("\\.ltx\\'" . latex-mode) |
1652 ("\\.dtx\\'" . doctex-mode) | 1652 ("\\.dtx\\'" . doctex-mode) |
1653 ("\\.el\\'" . emacs-lisp-mode) | 1653 ("\\.el\\'" . emacs-lisp-mode) |
1654 ("\\.\\(scm\\|stk\\|ss\\|sch\\)\\'" . scheme-mode) | 1654 ("\\.\\(scm\\|stk\\|ss\\|sch\\)\\'" . scheme-mode) |
1655 ("\\.l\\'" . lisp-mode) | 1655 ("\\.l\\'" . lisp-mode) |
1656 ("\\.lisp\\'" . lisp-mode) | 1656 ("\\.li?sp\\'" . lisp-mode) |
1657 ("\\.f\\'" . fortran-mode) | 1657 ("\\.[fF]\\'" . fortran-mode) |
1658 ("\\.F\\'" . fortran-mode) | |
1659 ("\\.for\\'" . fortran-mode) | 1658 ("\\.for\\'" . fortran-mode) |
1660 ("\\.p\\'" . pascal-mode) | 1659 ("\\.p\\'" . pascal-mode) |
1661 ("\\.pas\\'" . pascal-mode) | 1660 ("\\.pas\\'" . pascal-mode) |
1662 ("\\.ad[abs]\\'" . ada-mode) | 1661 ("\\.ad[abs]\\'" . ada-mode) |
1663 ("\\.ad[bs].dg\\'" . ada-mode) | 1662 ("\\.ad[bs].dg\\'" . ada-mode) |
1664 ("\\.\\([pP]\\([Llm]\\|erl\\)\\|al\\)\\'" . perl-mode) | 1663 ("\\.\\([pP]\\([Llm]\\|erl\\|od\\)\\|al\\)\\'" . perl-mode) |
1665 ("\\.s?html?\\'" . html-mode) | 1664 ("\\.s?html?\\'" . html-mode) |
1666 ("\\.mk\\'" . makefile-mode) | 1665 ("\\.mk\\'" . makefile-mode) |
1667 ("\\(M\\|m\\|GNUm\\)akefile\\'" . makefile-mode) | 1666 ("\\([Mm]\\|GNUm\\)akep*file\\'" . makefile-mode) |
1668 ("\\.am\\'" . makefile-mode) ;For Automake. | 1667 ("\\.am\\'" . makefile-mode) ;For Automake. |
1669 ;; Less common extensions come here | 1668 ;; Less common extensions come here |
1670 ;; so more common ones above are found faster. | 1669 ;; so more common ones above are found faster. |
1671 ("\\.texinfo\\'" . texinfo-mode) | 1670 ("\\.texinfo\\'" . texinfo-mode) |
1672 ("\\.te?xi\\'" . texinfo-mode) | 1671 ("\\.te?xi\\'" . texinfo-mode) |
1673 ("\\.s\\'" . asm-mode) | 1672 ("\\.[sS]\\'" . asm-mode) |
1674 ("\\.S\\'" . asm-mode) | |
1675 ("\\.asm\\'" . asm-mode) | 1673 ("\\.asm\\'" . asm-mode) |
1676 ("ChangeLog\\'" . change-log-mode) | 1674 ("[cC]hange\\.?[lL]og?\\'" . change-log-mode) |
1677 ("change\\.log\\'" . change-log-mode) | 1675 ("[cC]hange[lL]og\\.[0-9]+\\'" . change-log-mode) |
1678 ("changelo\\'" . change-log-mode) | |
1679 ("ChangeLog\\.[0-9]+\\'" . change-log-mode) | |
1680 ;; for MSDOS and MS-Windows (which are case-insensitive) | |
1681 ("changelog\\'" . change-log-mode) | |
1682 ("changelog\\.[0-9]+\\'" . change-log-mode) | |
1683 ("\\$CHANGE_LOG\\$\\.TXT" . change-log-mode) | 1676 ("\\$CHANGE_LOG\\$\\.TXT" . change-log-mode) |
1684 ("\\.scm\\.[0-9]*\\'" . scheme-mode) | 1677 ("\\.scm\\.[0-9]*\\'" . scheme-mode) |
1685 ("\\.[ck]?sh\\'\\|\\.shar\\'\\|/\\.z?profile\\'" . sh-mode) | 1678 ("\\.[ck]?sh\\'\\|\\.shar\\'\\|/\\.z?profile\\'" . sh-mode) |
1686 ("\\.bash\\'" . sh-mode) | 1679 ("\\.bash\\'" . sh-mode) |
1687 ("\\(/\\|\\`\\)\\.\\(bash_profile\\|z?login\\|bash_login\\|z?logout\\)\\'" . sh-mode) | 1680 ("\\(/\\|\\`\\)\\.\\(bash_profile\\|z?login\\|bash_login\\|z?logout\\)\\'" . sh-mode) |
1688 ("\\(/\\|\\`\\)\\.\\(bash_logout\\|shrc\\|[kz]shrc\\|bashrc\\|t?cshrc\\|esrc\\)\\'" . sh-mode) | 1681 ("\\(/\\|\\`\\)\\.\\(bash_logout\\|shrc\\|[kz]shrc\\|bashrc\\|t?cshrc\\|esrc\\)\\'" . sh-mode) |
1689 ("\\(/\\|\\`\\)\\.\\([kz]shenv\\|xinitrc\\|startxrc\\|xsession\\)\\'" . sh-mode) | 1682 ("\\(/\\|\\`\\)\\.\\([kz]shenv\\|xinitrc\\|startxrc\\|xsession\\)\\'" . sh-mode) |
1690 ("\\.m?spec\\'" . sh-mode) | 1683 ("\\.m?spec\\'" . sh-mode) |
1691 ("\\.mm\\'" . nroff-mode) | 1684 ("\\.m[mes]\\'" . nroff-mode) |
1692 ("\\.me\\'" . nroff-mode) | |
1693 ("\\.ms\\'" . nroff-mode) | |
1694 ("\\.man\\'" . nroff-mode) | 1685 ("\\.man\\'" . nroff-mode) |
1695 ("\\.TeX\\'" . tex-mode) | |
1696 ("\\.sty\\'" . latex-mode) | 1686 ("\\.sty\\'" . latex-mode) |
1697 ("\\.cls\\'" . latex-mode) ;LaTeX 2e class | 1687 ("\\.cl[so]\\'" . latex-mode) ;LaTeX 2e class option |
1698 ("\\.clo\\'" . latex-mode) ;LaTeX 2e class option | |
1699 ("\\.bbl\\'" . latex-mode) | 1688 ("\\.bbl\\'" . latex-mode) |
1700 ("\\.bib\\'" . bibtex-mode) | 1689 ("\\.bib\\'" . bibtex-mode) |
1701 ("\\.sql\\'" . sql-mode) | 1690 ("\\.sql\\'" . sql-mode) |
1702 ("\\.m4\\'" . m4-mode) | 1691 ("\\.m[4c]\\'" . m4-mode) |
1703 ("\\.mc\\'" . m4-mode) | 1692 ("\\.m[fp]\\'" . metapost-mode) |
1704 ("\\.mf\\'" . metafont-mode) | |
1705 ("\\.mp\\'" . metapost-mode) | |
1706 ("\\.vhdl?\\'" . vhdl-mode) | 1693 ("\\.vhdl?\\'" . vhdl-mode) |
1707 ("\\.article\\'" . text-mode) | 1694 ("\\.article\\'" . text-mode) |
1708 ("\\.letter\\'" . text-mode) | 1695 ("\\.letter\\'" . text-mode) |
1709 ("\\.tcl\\'" . tcl-mode) | 1696 ("\\.i?tcl\\'" . tcl-mode) |
1710 ("\\.exp\\'" . tcl-mode) | 1697 ("\\.exp\\'" . tcl-mode) |
1711 ("\\.itcl\\'" . tcl-mode) | |
1712 ("\\.itk\\'" . tcl-mode) | 1698 ("\\.itk\\'" . tcl-mode) |
1713 ("\\.icn\\'" . icon-mode) | 1699 ("\\.icn\\'" . icon-mode) |
1714 ("\\.sim\\'" . simula-mode) | 1700 ("\\.sim\\'" . simula-mode) |
1715 ("\\.mss\\'" . scribe-mode) | 1701 ("\\.mss\\'" . scribe-mode) |
1716 ("\\.f90\\'" . f90-mode) | 1702 ("\\.f9[05]\\'" . f90-mode) |
1717 ("\\.f95\\'" . f90-mode) | |
1718 ("\\.indent\\.pro\\'" . fundamental-mode) ; to avoid idlwave-mode | 1703 ("\\.indent\\.pro\\'" . fundamental-mode) ; to avoid idlwave-mode |
1719 ("\\.pro\\'" . idlwave-mode) | 1704 ("\\.pro\\'" . idlwave-mode) |
1720 ("\\.lsp\\'" . lisp-mode) | |
1721 ("\\.prolog\\'" . prolog-mode) | 1705 ("\\.prolog\\'" . prolog-mode) |
1722 ("\\.tar\\'" . tar-mode) | 1706 ("\\.tar\\'" . tar-mode) |
1723 ("\\.\\(arc\\|zip\\|lzh\\|zoo\\|ear\\|jar\\|war\\)\\'" . archive-mode) | 1707 ("\\.\\(arc\\|zip\\|lzh\\|zoo\\|ear\\|jar\\|war\\)\\'" . archive-mode) |
1724 ("\\.\\(ARC\\|ZIP\\|LZH\\|ZOO\\|EAR\\|JAR\\|WAR\\)\\'" . archive-mode) | 1708 ("\\.\\(ARC\\|ZIP\\|LZH\\|ZOO\\|EAR\\|JAR\\|WAR\\)\\'" . archive-mode) |
1725 ("\\.sx[dmicw]\\'" . archive-mode) ; OpenOffice.org | 1709 ("\\.sx[dmicw]\\'" . archive-mode) ; OpenOffice.org |
1731 ("\\.zone\\'" . zone-mode) | 1715 ("\\.zone\\'" . zone-mode) |
1732 ;; some news reader is reported to use this | 1716 ;; some news reader is reported to use this |
1733 ("\\`/tmp/fol/" . text-mode) | 1717 ("\\`/tmp/fol/" . text-mode) |
1734 ("\\.oak\\'" . scheme-mode) | 1718 ("\\.oak\\'" . scheme-mode) |
1735 ("\\.sgml?\\'" . sgml-mode) | 1719 ("\\.sgml?\\'" . sgml-mode) |
1736 ("\\.xml\\'" . sgml-mode) | 1720 ("\\.x[ms]l\\'" . xml-mode) |
1737 ("\\.xsl\\'" . sgml-mode) | |
1738 ("\\.dtd\\'" . sgml-mode) | 1721 ("\\.dtd\\'" . sgml-mode) |
1739 ("\\.ds\\(ss\\)?l\\'" . dsssl-mode) | 1722 ("\\.ds\\(ss\\)?l\\'" . dsssl-mode) |
1723 ("\\.js\\'" . java-mode) ; javascript-mode would be better | |
1724 ("\\.x[bp]m\\'" . c-mode) | |
1740 ;; .emacs or .gnus or .viper following a directory delimiter in | 1725 ;; .emacs or .gnus or .viper following a directory delimiter in |
1741 ;; Unix, MSDOG or VMS syntax. | 1726 ;; Unix, MSDOG or VMS syntax. |
1742 ("[]>:/\\]\\..*\\(emacs\\|gnus\\|viper\\)\\'" . emacs-lisp-mode) | 1727 ("[]>:/\\]\\..*\\(emacs\\|gnus\\|viper\\)\\'" . emacs-lisp-mode) |
1743 ("\\`\\..*emacs\\'" . emacs-lisp-mode) | 1728 ("\\`\\..*emacs\\'" . emacs-lisp-mode) |
1744 ;; _emacs following a directory delimiter | 1729 ;; _emacs following a directory delimiter |
1758 ;; Get rid of any trailing .n.m and try again. | 1743 ;; Get rid of any trailing .n.m and try again. |
1759 ;; This is for files saved by cvs-merge that look like .#<file>.<rev> | 1744 ;; This is for files saved by cvs-merge that look like .#<file>.<rev> |
1760 ;; or .#<file>.<rev>-<rev> or VC's <file>.~<rev>~. | 1745 ;; or .#<file>.<rev>-<rev> or VC's <file>.~<rev>~. |
1761 ;; Using mode nil rather than `ignore' would let the search continue | 1746 ;; Using mode nil rather than `ignore' would let the search continue |
1762 ;; through this list (with the shortened name) rather than start over. | 1747 ;; through this list (with the shortened name) rather than start over. |
1763 ("\\.~?[0-9]+\\.[0-9][-.0-9]*~?\\'" ignore t) | 1748 ("\\.~?[0-9]+\\.[0-9][-.0-9]*~?\\'" nil t) |
1764 ;; The following should come after the ChangeLog pattern | 1749 ;; The following should come after the ChangeLog pattern |
1765 ;; for the sake of ChangeLog.1, etc. | 1750 ;; for the sake of ChangeLog.1, etc. |
1766 ;; and after the .scm.[0-9] and CVS' <file>.<rev> patterns too. | 1751 ;; and after the .scm.[0-9] and CVS' <file>.<rev> patterns too. |
1767 ("\\.[1-9]\\'" . nroff-mode) | 1752 ("\\.[1-9]\\'" . nroff-mode) |
1768 ("\\.g\\'" . antlr-mode) | 1753 ("\\.g\\'" . antlr-mode) |
1847 a mode from the file's name. If it matches, the file is assumed to | 1832 a mode from the file's name. If it matches, the file is assumed to |
1848 be interpreted by the interpreter matched by the second group of the | 1833 be interpreted by the interpreter matched by the second group of the |
1849 regular expression. The mode is then determined as the mode associated | 1834 regular expression. The mode is then determined as the mode associated |
1850 with that interpreter in `interpreter-mode-alist'.") | 1835 with that interpreter in `interpreter-mode-alist'.") |
1851 | 1836 |
1837 (defvar xml-based-modes '(html-mode) | |
1838 "Modes that override an XML declaration. | |
1839 When `set-auto-mode' sees an <?xml or <!DOCTYPE declaration, that | |
1840 buffer will be in some XML mode. If `auto-mode-alist' associates | |
1841 the file with one of the modes in this list, that mode will be | |
1842 used. Else `xml-mode' or `sgml-mode' is used.") | |
1843 | |
1852 (defun set-auto-mode (&optional just-from-file-name) | 1844 (defun set-auto-mode (&optional just-from-file-name) |
1853 "Select major mode appropriate for current buffer. | 1845 "Select major mode appropriate for current buffer. |
1854 This checks for a -*- mode tag in the buffer's text, | 1846 This checks for a -*- mode tag in the buffer's text, checks the |
1855 compares the filename against the entries in `auto-mode-alist', | 1847 interpreter that runs this file against `interpreter-mode-alist', |
1856 or checks the interpreter that runs this file against | 1848 looks for an <?xml or <!DOCTYPE declaration (see |
1857 `interpreter-mode-alist'. | 1849 `xml-based-modes'), or compares the filename against the entries |
1850 in `auto-mode-alist'. | |
1858 | 1851 |
1859 It does not check for the `mode:' local variable in the | 1852 It does not check for the `mode:' local variable in the |
1860 Local Variables section of the file; for that, use `hack-local-variables'. | 1853 Local Variables section of the file; for that, use `hack-local-variables'. |
1861 | 1854 |
1862 If `enable-local-variables' is nil, this function does not check for a | 1855 If `enable-local-variables' is nil, this function does not check for a |
1864 | 1857 |
1865 If the optional argument JUST-FROM-FILE-NAME is non-nil, | 1858 If the optional argument JUST-FROM-FILE-NAME is non-nil, |
1866 then we do not set anything but the major mode, | 1859 then we do not set anything but the major mode, |
1867 and we don't even do that unless it would come from the file name." | 1860 and we don't even do that unless it would come from the file name." |
1868 ;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*- | 1861 ;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*- |
1869 (let (end done modes) | 1862 (let (end done mode modes xml) |
1870 (save-excursion | |
1871 (goto-char (point-min)) | |
1872 (skip-chars-forward " \t\n") | |
1873 (and enable-local-variables | |
1874 (setq end (set-auto-mode-1)) | |
1875 (if (save-excursion (search-forward ":" end t)) | |
1876 ;; Find all specifications for the `mode:' variable | |
1877 ;; and execute them left to right. | |
1878 (while (let ((case-fold-search t)) | |
1879 (or (and (looking-at "mode:") | |
1880 (goto-char (match-end 0))) | |
1881 (re-search-forward "[ \t;]mode:" end t))) | |
1882 (skip-chars-forward " \t") | |
1883 (let ((beg (point))) | |
1884 (if (search-forward ";" end t) | |
1885 (forward-char -1) | |
1886 (goto-char end)) | |
1887 (skip-chars-backward " \t") | |
1888 (push (intern (concat (downcase (buffer-substring beg (point))) "-mode")) | |
1889 modes))) | |
1890 ;; Simple -*-MODE-*- case. | |
1891 (push (intern (concat (downcase (buffer-substring (point) end)) | |
1892 "-mode")) | |
1893 modes)))) | |
1894 ;; If we found modes to use, invoke them now, | |
1895 ;; outside the save-excursion. | |
1896 (unless just-from-file-name | 1863 (unless just-from-file-name |
1897 (dolist (mode (nreverse modes)) | 1864 ;; Find a -*- mode tag |
1898 (if (not (functionp mode)) | 1865 (save-excursion |
1899 (message "Ignoring unknown mode `%s'" mode) | 1866 (goto-char (point-min)) |
1900 (setq done t) | 1867 (skip-chars-forward " \t\n") |
1901 (funcall mode)))) | 1868 ;; While we're at this point, check xml for later. |
1902 ;; If we didn't find a mode from a -*- line, try using the file name. | 1869 (setq xml (looking-at "<\\?xml \\|<!DOCTYPE")) |
1870 (and enable-local-variables | |
1871 (setq end (set-auto-mode-1)) | |
1872 (if (save-excursion (search-forward ":" end t)) | |
1873 ;; Find all specifications for the `mode:' variable | |
1874 ;; and execute them left to right. | |
1875 (while (let ((case-fold-search t)) | |
1876 (or (and (looking-at "mode:") | |
1877 (goto-char (match-end 0))) | |
1878 (re-search-forward "[ \t;]mode:" end t))) | |
1879 (skip-chars-forward " \t") | |
1880 (let ((beg (point))) | |
1881 (if (search-forward ";" end t) | |
1882 (forward-char -1) | |
1883 (goto-char end)) | |
1884 (skip-chars-backward " \t") | |
1885 (push (intern (concat (downcase (buffer-substring beg (point))) "-mode")) | |
1886 modes))) | |
1887 ;; Simple -*-MODE-*- case. | |
1888 (push (intern (concat (downcase (buffer-substring (point) end)) | |
1889 "-mode")) | |
1890 modes)))) | |
1891 ;; If we found modes to use, invoke them now, outside the save-excursion. | |
1892 (if modes | |
1893 (dolist (mode (nreverse modes)) | |
1894 (if (not (functionp mode)) | |
1895 (message "Ignoring unknown mode `%s'" mode) | |
1896 (setq done t) | |
1897 (funcall mode))) | |
1898 ;; If we didn't, look for an interpreter specified in the first line. | |
1899 ;; As a special case, allow for things like "#!/bin/env perl", which | |
1900 ;; finds the interpreter anywhere in $PATH. | |
1901 (setq mode (save-excursion | |
1902 (goto-char (point-min)) | |
1903 (if (looking-at auto-mode-interpreter-regexp) | |
1904 (match-string 2) | |
1905 "")) | |
1906 ;; Map interpreter name to a mode, signalling we're done at the | |
1907 ;; same time. | |
1908 done (assoc (file-name-nondirectory mode) | |
1909 interpreter-mode-alist)) | |
1910 ;; If we found an interpreter mode to use, invoke it now. | |
1911 (if done (funcall (cdr done))))) | |
1903 (if (and (not done) buffer-file-name) | 1912 (if (and (not done) buffer-file-name) |
1904 (let ((name buffer-file-name) | 1913 (let ((name buffer-file-name)) |
1905 (keep-going t)) | |
1906 ;; Remove backup-suffixes from file name. | 1914 ;; Remove backup-suffixes from file name. |
1907 (setq name (file-name-sans-versions name)) | 1915 (setq name (file-name-sans-versions name)) |
1908 (while keep-going | 1916 (while (not done) |
1909 (setq keep-going nil) | 1917 ;; Find first matching alist entry. |
1910 (let ((alist auto-mode-alist) | 1918 (let ((case-fold-search |
1911 (mode nil)) | 1919 (memq system-type '(vax-vms windows-nt cygwin)))) |
1912 ;; Find first matching alist entry. | 1920 (if (and (setq mode (assoc-default name auto-mode-alist |
1913 (let ((case-fold-search | 1921 'string-match)) |
1914 (memq system-type '(vax-vms windows-nt cygwin)))) | 1922 (consp mode) |
1915 (while (and (not mode) alist) | 1923 (cadr mode)) |
1916 (if (string-match (car (car alist)) name) | 1924 (setq mode (car mode) |
1917 (if (and (consp (cdr (car alist))) | 1925 name (substring name 0 (match-beginning 0))) |
1918 (nth 2 (car alist))) | 1926 (setq done t))) |
1919 (setq mode (car (cdr (car alist))) | 1927 (if mode |
1920 name (substring name 0 (match-beginning 0)) | 1928 ;; When JUST-FROM-FILE-NAME is set, we are working on behalf |
1921 keep-going t) | 1929 ;; of set-visited-file-name. In that case, if the major mode |
1922 (setq mode (cdr (car alist)) | 1930 ;; specified is the same one we already have, don't actually |
1923 keep-going nil))) | 1931 ;; reset it. We don't want to lose minor modes such as Font |
1924 (setq alist (cdr alist)))) | 1932 ;; Lock. |
1925 (if mode | 1933 (unless (and just-from-file-name (eq mode major-mode)) |
1926 ;; When JUST-FROM-FILE-NAME is set, | 1934 (if (if xml (memq mode xml-based-modes) t) |
1927 ;; we are working on behalf of set-visited-file-name. | 1935 (funcall mode) |
1928 ;; In that case, if the major mode specified is the | 1936 (xml-mode))))))) |
1929 ;; same one we already have, don't actually reset it. | 1937 (and (not done) |
1930 ;; We don't want to lose minor modes such as Font Lock. | 1938 xml |
1931 (unless (and just-from-file-name (eq mode major-mode)) | 1939 (xml-mode)))) |
1932 (funcall mode)) | |
1933 ;; If we can't deduce a mode from the file name, | |
1934 ;; look for an interpreter specified in the first line. | |
1935 ;; As a special case, allow for things like "#!/bin/env perl", | |
1936 ;; which finds the interpreter anywhere in $PATH. | |
1937 (let ((interpreter | |
1938 (save-excursion | |
1939 (goto-char (point-min)) | |
1940 (if (looking-at auto-mode-interpreter-regexp) | |
1941 (match-string 2) | |
1942 ""))) | |
1943 elt) | |
1944 ;; Map interpreter name to a mode. | |
1945 (setq elt (assoc (file-name-nondirectory interpreter) | |
1946 interpreter-mode-alist)) | |
1947 (unless just-from-file-name | |
1948 (if elt | |
1949 (funcall (cdr elt)))))))))))) | |
1950 | 1940 |
1951 | 1941 |
1952 (defun set-auto-mode-1 () | 1942 (defun set-auto-mode-1 () |
1953 "Find the -*- spec in the buffer. | 1943 "Find the -*- spec in the buffer. |
1954 Call with point at the place to start searching from. | 1944 Call with point at the place to start searching from. |
2155 (if (looking-back suffix) | 2145 (if (looking-back suffix) |
2156 (delete-region (match-beginning 0) (point)) | 2146 (delete-region (match-beginning 0) (point)) |
2157 (error "Local variables entry is missing the suffix"))) | 2147 (error "Local variables entry is missing the suffix"))) |
2158 (forward-line 1)) | 2148 (forward-line 1)) |
2159 (goto-char (point-min)) | 2149 (goto-char (point-min)) |
2160 | 2150 |
2161 (while (not (eobp)) | 2151 (while (not (eobp)) |
2162 ;; Find the variable name; strip whitespace. | 2152 ;; Find the variable name; strip whitespace. |
2163 (skip-chars-forward " \t") | 2153 (skip-chars-forward " \t") |
2164 (setq beg (point)) | 2154 (setq beg (point)) |
2165 (skip-chars-forward "^:\n") | 2155 (skip-chars-forward "^:\n") |