diff options
| author | Daniel Pfeiffer | 2004-10-27 21:44:35 +0000 |
|---|---|---|
| committer | Daniel Pfeiffer | 2004-10-27 21:44:35 +0000 |
| commit | 9e6f54198a18f3ac8838d7ada4fe6eef55e880bc (patch) | |
| tree | 9c3114a84e72fbf9ee7cb45cf244e7480aa371f4 | |
| parent | 068f384827a414b5c2f49d50cf2e5c307d888413 (diff) | |
| download | emacs-9e6f54198a18f3ac8838d7ada4fe6eef55e880bc.tar.gz emacs-9e6f54198a18f3ac8838d7ada4fe6eef55e880bc.zip | |
Tack language suffix onto html, and make C-x C-w find the mode in the same way as C-x C-f.
| -rw-r--r-- | lisp/files.el | 135 |
1 files changed, 70 insertions, 65 deletions
diff --git a/lisp/files.el b/lisp/files.el index dd36f449208..09e7c76107a 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -1645,7 +1645,9 @@ in that case, this function acts as if `enable-local-variables' were t." | |||
| 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 | '(;; do this first, so that .html.pl is Polish html, not Perl |
| 1649 | ("\\.s?html?\\(\\.[a-zA-Z_]+\\)?\\'" . html-mode) | ||
| 1650 | ("\\.te?xt\\'" . text-mode) | ||
| 1649 | ("\\.[tT]e[xX]\\'" . tex-mode) | 1651 | ("\\.[tT]e[xX]\\'" . tex-mode) |
| 1650 | ("\\.ins\\'" . tex-mode) ;Installation files for TeX packages. | 1652 | ("\\.ins\\'" . tex-mode) ;Installation files for TeX packages. |
| 1651 | ("\\.ltx\\'" . latex-mode) | 1653 | ("\\.ltx\\'" . latex-mode) |
| @@ -1661,7 +1663,6 @@ in that case, this function acts as if `enable-local-variables' were t." | |||
| 1661 | ("\\.ad[abs]\\'" . ada-mode) | 1663 | ("\\.ad[abs]\\'" . ada-mode) |
| 1662 | ("\\.ad[bs].dg\\'" . ada-mode) | 1664 | ("\\.ad[bs].dg\\'" . ada-mode) |
| 1663 | ("\\.\\([pP]\\([Llm]\\|erl\\|od\\)\\|al\\)\\'" . perl-mode) | 1665 | ("\\.\\([pP]\\([Llm]\\|erl\\|od\\)\\|al\\)\\'" . perl-mode) |
| 1664 | ("\\.s?html?\\'" . html-mode) | ||
| 1665 | ("\\.mk\\'" . makefile-mode) | 1666 | ("\\.mk\\'" . makefile-mode) |
| 1666 | ("\\([Mm]\\|GNUm\\)akep*file\\'" . makefile-mode) | 1667 | ("\\([Mm]\\|GNUm\\)akep*file\\'" . makefile-mode) |
| 1667 | ("\\.am\\'" . makefile-mode) ;For Automake. | 1668 | ("\\.am\\'" . makefile-mode) ;For Automake. |
| @@ -1689,7 +1690,8 @@ in that case, this function acts as if `enable-local-variables' were t." | |||
| 1689 | ("\\.bib\\'" . bibtex-mode) | 1690 | ("\\.bib\\'" . bibtex-mode) |
| 1690 | ("\\.sql\\'" . sql-mode) | 1691 | ("\\.sql\\'" . sql-mode) |
| 1691 | ("\\.m[4c]\\'" . m4-mode) | 1692 | ("\\.m[4c]\\'" . m4-mode) |
| 1692 | ("\\.m[fp]\\'" . metapost-mode) | 1693 | ("\\.mf\\'" . metafont-mode) |
| 1694 | ("\\.mp\\'" . metapost-mode) | ||
| 1693 | ("\\.vhdl?\\'" . vhdl-mode) | 1695 | ("\\.vhdl?\\'" . vhdl-mode) |
| 1694 | ("\\.article\\'" . text-mode) | 1696 | ("\\.article\\'" . text-mode) |
| 1695 | ("\\.letter\\'" . text-mode) | 1697 | ("\\.letter\\'" . text-mode) |
| @@ -1841,7 +1843,7 @@ 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 | 1843 | the file with one of the modes in this list, that mode will be |
| 1842 | used. Else `xml-mode' or `sgml-mode' is used.") | 1844 | used. Else `xml-mode' or `sgml-mode' is used.") |
| 1843 | 1845 | ||
| 1844 | (defun set-auto-mode (&optional just-from-file-name) | 1846 | (defun set-auto-mode (&optional keep-mode-if-same) |
| 1845 | "Select major mode appropriate for current buffer. | 1847 | "Select major mode appropriate for current buffer. |
| 1846 | This checks for a -*- mode tag in the buffer's text, checks the | 1848 | This checks for a -*- mode tag in the buffer's text, checks the |
| 1847 | interpreter that runs this file against `interpreter-mode-alist', | 1849 | interpreter that runs this file against `interpreter-mode-alist', |
| @@ -1855,60 +1857,62 @@ Local Variables section of the file; for that, use `hack-local-variables'. | |||
| 1855 | If `enable-local-variables' is nil, this function does not check for a | 1857 | If `enable-local-variables' is nil, this function does not check for a |
| 1856 | -*- mode tag. | 1858 | -*- mode tag. |
| 1857 | 1859 | ||
| 1858 | If the optional argument JUST-FROM-FILE-NAME is non-nil, | 1860 | If the optional argument KEEP-MODE-IF-SAME is non-nil, |
| 1859 | then we do not set anything but the major mode, | 1861 | then we do not set anything but the major mode, |
| 1860 | and we don't even do that unless it would come from the file name." | 1862 | and we don't even do that unless it would come from the file name." |
| 1861 | ;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*- | 1863 | ;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*- |
| 1862 | (let (end done mode modes xml) | 1864 | (let (end done mode modes xml) |
| 1863 | (unless just-from-file-name | 1865 | ;; Find a -*- mode tag |
| 1864 | ;; Find a -*- mode tag | 1866 | (save-excursion |
| 1865 | (save-excursion | 1867 | (goto-char (point-min)) |
| 1866 | (goto-char (point-min)) | 1868 | (skip-chars-forward " \t\n") |
| 1867 | (skip-chars-forward " \t\n") | 1869 | ;; While we're at this point, check xml for later. |
| 1868 | ;; While we're at this point, check xml for later. | 1870 | (setq xml (looking-at "<\\?xml \\|<!DOCTYPE")) |
| 1869 | (setq xml (looking-at "<\\?xml \\|<!DOCTYPE")) | 1871 | (and enable-local-variables |
| 1870 | (and enable-local-variables | 1872 | (setq end (set-auto-mode-1)) |
| 1871 | (setq end (set-auto-mode-1)) | 1873 | (if (save-excursion (search-forward ":" end t)) |
| 1872 | (if (save-excursion (search-forward ":" end t)) | 1874 | ;; Find all specifications for the `mode:' variable |
| 1873 | ;; Find all specifications for the `mode:' variable | 1875 | ;; and execute them left to right. |
| 1874 | ;; and execute them left to right. | 1876 | (while (let ((case-fold-search t)) |
| 1875 | (while (let ((case-fold-search t)) | 1877 | (or (and (looking-at "mode:") |
| 1876 | (or (and (looking-at "mode:") | 1878 | (goto-char (match-end 0))) |
| 1877 | (goto-char (match-end 0))) | 1879 | (re-search-forward "[ \t;]mode:" end t))) |
| 1878 | (re-search-forward "[ \t;]mode:" end t))) | 1880 | (skip-chars-forward " \t") |
| 1879 | (skip-chars-forward " \t") | 1881 | (let ((beg (point))) |
| 1880 | (let ((beg (point))) | 1882 | (if (search-forward ";" end t) |
| 1881 | (if (search-forward ";" end t) | 1883 | (forward-char -1) |
| 1882 | (forward-char -1) | 1884 | (goto-char end)) |
| 1883 | (goto-char end)) | 1885 | (skip-chars-backward " \t") |
| 1884 | (skip-chars-backward " \t") | 1886 | (push (intern (concat (downcase (buffer-substring beg (point))) "-mode")) |
| 1885 | (push (intern (concat (downcase (buffer-substring beg (point))) "-mode")) | 1887 | modes))) |
| 1886 | modes))) | 1888 | ;; Simple -*-MODE-*- case. |
| 1887 | ;; Simple -*-MODE-*- case. | 1889 | (push (intern (concat (downcase (buffer-substring (point) end)) |
| 1888 | (push (intern (concat (downcase (buffer-substring (point) end)) | 1890 | "-mode")) |
| 1889 | "-mode")) | 1891 | modes)))) |
| 1890 | modes)))) | 1892 | ;; If we found modes to use, invoke them now, outside the save-excursion. |
| 1891 | ;; If we found modes to use, invoke them now, outside the save-excursion. | 1893 | (if modes |
| 1892 | (if modes | 1894 | (dolist (mode (nreverse modes)) |
| 1893 | (dolist (mode (nreverse modes)) | 1895 | (if (not (functionp mode)) |
| 1894 | (if (not (functionp mode)) | 1896 | (message "Ignoring unknown mode `%s'" mode) |
| 1895 | (message "Ignoring unknown mode `%s'" mode) | 1897 | (setq done t) |
| 1896 | (setq done t) | 1898 | (unless (if keep-mode-if-same (eq mode major-mode)) |
| 1897 | (funcall mode))) | 1899 | (funcall mode)))) |
| 1898 | ;; If we didn't, look for an interpreter specified in the first line. | 1900 | ;; 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 | 1901 | ;; As a special case, allow for things like "#!/bin/env perl", which |
| 1900 | ;; finds the interpreter anywhere in $PATH. | 1902 | ;; finds the interpreter anywhere in $PATH. |
| 1901 | (setq mode (save-excursion | 1903 | (setq mode (save-excursion |
| 1902 | (goto-char (point-min)) | 1904 | (goto-char (point-min)) |
| 1903 | (if (looking-at auto-mode-interpreter-regexp) | 1905 | (if (looking-at auto-mode-interpreter-regexp) |
| 1904 | (match-string 2) | 1906 | (match-string 2) |
| 1905 | "")) | 1907 | "")) |
| 1906 | ;; Map interpreter name to a mode, signalling we're done at the | 1908 | ;; Map interpreter name to a mode, signalling we're done at the |
| 1907 | ;; same time. | 1909 | ;; same time. |
| 1908 | done (assoc (file-name-nondirectory mode) | 1910 | done (assoc (file-name-nondirectory mode) |
| 1909 | interpreter-mode-alist)) | 1911 | interpreter-mode-alist)) |
| 1910 | ;; If we found an interpreter mode to use, invoke it now. | 1912 | ;; If we found an interpreter mode to use, invoke it now. |
| 1911 | (if done (funcall (cdr done))))) | 1913 | (and done |
| 1914 | (not (if keep-mode-if-same (eq mode major-mode))) | ||
| 1915 | (funcall (cdr done)))) | ||
| 1912 | (if (and (not done) buffer-file-name) | 1916 | (if (and (not done) buffer-file-name) |
| 1913 | (let ((name buffer-file-name)) | 1917 | (let ((name buffer-file-name)) |
| 1914 | ;; Remove backup-suffixes from file name. | 1918 | ;; Remove backup-suffixes from file name. |
| @@ -1919,24 +1923,25 @@ and we don't even do that unless it would come from the file name." | |||
| 1919 | (memq system-type '(vax-vms windows-nt cygwin)))) | 1923 | (memq system-type '(vax-vms windows-nt cygwin)))) |
| 1920 | (if (and (setq mode (assoc-default name auto-mode-alist | 1924 | (if (and (setq mode (assoc-default name auto-mode-alist |
| 1921 | 'string-match)) | 1925 | 'string-match)) |
| 1922 | (setq done t) | ||
| 1923 | (consp mode) | 1926 | (consp mode) |
| 1924 | (cadr mode)) | 1927 | (cadr mode)) |
| 1925 | (setq mode (car mode) | 1928 | (setq mode (car mode) |
| 1926 | name (substring name 0 (match-beginning 0))) | 1929 | name (substring name 0 (match-beginning 0))) |
| 1927 | (setq name))) | 1930 | (setq name))) |
| 1928 | (if mode | 1931 | (when mode |
| 1929 | ;; When JUST-FROM-FILE-NAME is set, we are working on behalf | 1932 | (if xml (or (memq mode xml-based-modes) |
| 1930 | ;; of set-visited-file-name. In that case, if the major mode | 1933 | (setq mode 'sgml-mode))) ; alias to xml-mode for `eq' |
| 1931 | ;; specified is the same one we already have, don't actually | 1934 | ;; When KEEP-MODE-IF-SAME is set, we are working on behalf of |
| 1932 | ;; reset it. We don't want to lose minor modes such as Font | 1935 | ;; set-visited-file-name. In that case, if the major mode |
| 1933 | ;; Lock. | 1936 | ;; specified is the same one we already have, don't actually |
| 1934 | (unless (and just-from-file-name (eq mode major-mode)) | 1937 | ;; reset it. We don't want to lose minor modes such as Font |
| 1935 | (if (if xml (memq mode xml-based-modes) t) | 1938 | ;; Lock. |
| 1936 | (funcall mode) | 1939 | (unless (if keep-mode-if-same (eq mode major-mode)) |
| 1937 | (xml-mode))))))) | 1940 | (funcall mode)) |
| 1941 | (setq done t))))) | ||
| 1938 | (and (not done) | 1942 | (and (not done) |
| 1939 | xml | 1943 | xml |
| 1944 | (not (if keep-mode-if-same (eq 'sgml-mode major-mode))) | ||
| 1940 | (xml-mode)))) | 1945 | (xml-mode)))) |
| 1941 | 1946 | ||
| 1942 | 1947 | ||