comparison lisp/files.el @ 90043:e24e2e78deda

Revision: miles@gnu.org--gnu-2004/emacs--unicode--0--patch-69 Merge from emacs--cvs-trunk--0 Patches applied: * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-643 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-649 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-650 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-651 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-655 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-656 Update from CVS: lisp/man.el (Man-xref-normal-file): Fix help-echo. * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-657 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-658 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-659 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-660 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-661 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-667 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-668 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-61 - miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-68 Update from CVS
author Miles Bader <miles@gnu.org>
date Thu, 04 Nov 2004 08:55:40 +0000
parents 0fe073a08cef fc267b57656c
children cb7f41387eb3
comparison
equal deleted inserted replaced
90042:003d95404d71 90043:e24e2e78deda
974 (progn 974 (progn
975 (setq value (nreverse value)) 975 (setq value (nreverse value))
976 (switch-to-buffer-other-frame (car value)) 976 (switch-to-buffer-other-frame (car value))
977 (mapcar 'switch-to-buffer (cdr value))) 977 (mapcar 'switch-to-buffer (cdr value)))
978 (switch-to-buffer-other-frame value)))) 978 (switch-to-buffer-other-frame value))))
979
980 (defun find-file-existing (filename &optional wildcards)
981 "Edit the existing file FILENAME.
982 Like \\[find-file] but only allow files that exists."
983 (interactive (find-file-read-args "Find existing file: " t))
984 (unless (file-exists-p filename) (error "%s does not exist" filename))
985 (find-file filename wildcards)
986 (current-buffer))
979 987
980 (defun find-file-read-only (filename &optional wildcards) 988 (defun find-file-read-only (filename &optional wildcards)
981 "Edit file FILENAME but don't allow changes. 989 "Edit file FILENAME but don't allow changes.
982 Like \\[find-file] but marks buffer as read-only. 990 Like \\[find-file] but marks buffer as read-only.
983 Use \\[toggle-read-only] to permit editing." 991 Use \\[toggle-read-only] to permit editing."
1223 (defcustom large-file-warning-threshold 10000000 1231 (defcustom large-file-warning-threshold 10000000
1224 "Maximum size of file above which a confirmation is requested. 1232 "Maximum size of file above which a confirmation is requested.
1225 When nil, never request confirmation." 1233 When nil, never request confirmation."
1226 :group 'files 1234 :group 'files
1227 :group 'find-file 1235 :group 'find-file
1236 :version "21.4"
1228 :type '(choice integer (const :tag "Never request confirmation" nil))) 1237 :type '(choice integer (const :tag "Never request confirmation" nil)))
1229 1238
1230 (defun find-file-noselect (filename &optional nowarn rawfile wildcards) 1239 (defun find-file-noselect (filename &optional nowarn rawfile wildcards)
1231 "Read file FILENAME into a buffer and return the buffer. 1240 "Read file FILENAME into a buffer and return the buffer.
1232 If a buffer exists visiting FILENAME, return that one, but 1241 If a buffer exists visiting FILENAME, return that one, but
1643 ;; directives in that file. That way is discouraged since it 1652 ;; directives in that file. That way is discouraged since it
1644 ;; spreads out the definition of the initial value. 1653 ;; spreads out the definition of the initial value.
1645 (mapc 1654 (mapc
1646 (lambda (elt) 1655 (lambda (elt)
1647 (cons (purecopy (car elt)) (cdr elt))) 1656 (cons (purecopy (car elt)) (cdr elt)))
1648 '(("\\.te?xt\\'" . text-mode) 1657 '(;; do this first, so that .html.pl is Polish html, not Perl
1658 ("\\.s?html?\\(\\.[a-zA-Z_]+\\)?\\'" . html-mode)
1659 ("\\.te?xt\\'" . text-mode)
1649 ("\\.[tT]e[xX]\\'" . tex-mode) 1660 ("\\.[tT]e[xX]\\'" . tex-mode)
1650 ("\\.ins\\'" . tex-mode) ;Installation files for TeX packages. 1661 ("\\.ins\\'" . tex-mode) ;Installation files for TeX packages.
1651 ("\\.ltx\\'" . latex-mode) 1662 ("\\.ltx\\'" . latex-mode)
1652 ("\\.dtx\\'" . doctex-mode) 1663 ("\\.dtx\\'" . doctex-mode)
1653 ("\\.el\\'" . emacs-lisp-mode) 1664 ("\\.el\\'" . emacs-lisp-mode)
1659 ("\\.p\\'" . pascal-mode) 1670 ("\\.p\\'" . pascal-mode)
1660 ("\\.pas\\'" . pascal-mode) 1671 ("\\.pas\\'" . pascal-mode)
1661 ("\\.ad[abs]\\'" . ada-mode) 1672 ("\\.ad[abs]\\'" . ada-mode)
1662 ("\\.ad[bs].dg\\'" . ada-mode) 1673 ("\\.ad[bs].dg\\'" . ada-mode)
1663 ("\\.\\([pP]\\([Llm]\\|erl\\|od\\)\\|al\\)\\'" . perl-mode) 1674 ("\\.\\([pP]\\([Llm]\\|erl\\|od\\)\\|al\\)\\'" . perl-mode)
1664 ("\\.s?html?\\'" . html-mode)
1665 ("\\.mk\\'" . makefile-mode) 1675 ("\\.mk\\'" . makefile-mode)
1666 ("\\([Mm]\\|GNUm\\)akep*file\\'" . makefile-mode) 1676 ("\\([Mm]\\|GNUm\\)akep*file\\'" . makefile-mode)
1667 ("\\.am\\'" . makefile-mode) ;For Automake. 1677 ("\\.am\\'" . makefile-mode) ;For Automake.
1668 ;; Less common extensions come here 1678 ;; Less common extensions come here
1669 ;; so more common ones above are found faster. 1679 ;; so more common ones above are found faster.
1687 ("\\.cl[so]\\'" . latex-mode) ;LaTeX 2e class option 1697 ("\\.cl[so]\\'" . latex-mode) ;LaTeX 2e class option
1688 ("\\.bbl\\'" . latex-mode) 1698 ("\\.bbl\\'" . latex-mode)
1689 ("\\.bib\\'" . bibtex-mode) 1699 ("\\.bib\\'" . bibtex-mode)
1690 ("\\.sql\\'" . sql-mode) 1700 ("\\.sql\\'" . sql-mode)
1691 ("\\.m[4c]\\'" . m4-mode) 1701 ("\\.m[4c]\\'" . m4-mode)
1692 ("\\.m[fp]\\'" . metapost-mode) 1702 ("\\.mf\\'" . metafont-mode)
1703 ("\\.mp\\'" . metapost-mode)
1693 ("\\.vhdl?\\'" . vhdl-mode) 1704 ("\\.vhdl?\\'" . vhdl-mode)
1694 ("\\.article\\'" . text-mode) 1705 ("\\.article\\'" . text-mode)
1695 ("\\.letter\\'" . text-mode) 1706 ("\\.letter\\'" . text-mode)
1696 ("\\.i?tcl\\'" . tcl-mode) 1707 ("\\.i?tcl\\'" . tcl-mode)
1697 ("\\.exp\\'" . tcl-mode) 1708 ("\\.exp\\'" . tcl-mode)
1832 a mode from the file's name. If it matches, the file is assumed to 1843 a mode from the file's name. If it matches, the file is assumed to
1833 be interpreted by the interpreter matched by the second group of the 1844 be interpreted by the interpreter matched by the second group of the
1834 regular expression. The mode is then determined as the mode associated 1845 regular expression. The mode is then determined as the mode associated
1835 with that interpreter in `interpreter-mode-alist'.") 1846 with that interpreter in `interpreter-mode-alist'.")
1836 1847
1837 (defvar xml-based-modes '(html-mode) 1848 (defvar magic-mode-alist
1838 "Modes that override an XML declaration. 1849 '(;; The < comes before the groups (but the first) to reduce backtracking.
1839 When `set-auto-mode' sees an <?xml or <!DOCTYPE declaration, that 1850 ;; Is there a nicer way of getting . including \n?
1840 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.
1841 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)
1842 used. Else `xml-mode' or `sgml-mode' is used.") 1853 ;; These two must come after html, because they are more general:
1843 1854 ("<\\?xml " . xml-mode)
1844 (defun set-auto-mode (&optional just-from-file-name) 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.")
1860
1861 (defun set-auto-mode (&optional keep-mode-if-same)
1845 "Select major mode appropriate for current buffer. 1862 "Select major mode appropriate for current buffer.
1863
1846 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
1847 interpreter that runs this file against `interpreter-mode-alist', 1865 interpreter that runs this file against `interpreter-mode-alist',
1848 looks for an <?xml or <!DOCTYPE declaration (see 1866 compares the buffer beginning against `magic-mode-alist',
1849 `xml-based-modes'), or compares the filename against the entries 1867 or compares the filename against the entries in
1850 in `auto-mode-alist'. 1868 `auto-mode-alist'.
1851 1869
1852 It does not check for the `mode:' local variable in the 1870 It does not check for the `mode:' local variable in the
1853 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'.
1854 1872
1855 If `enable-local-variables' is nil, this function does not check for a 1873 If `enable-local-variables' is nil, this function does not check for a
1856 -*- mode tag. 1874 -*- mode tag.
1857 1875
1858 If the optional argument JUST-FROM-FILE-NAME is non-nil, 1876 If the optional argument KEEP-MODE-IF-SAME is non-nil, then we
1859 then we do not set anything but the major mode, 1877 only set the major mode, if that would change it."
1860 and we don't even do that unless it would come from the file name."
1861 ;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*- 1878 ;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*-
1862 (let (end done mode modes xml) 1879 (let (end done mode modes xml)
1863 (unless just-from-file-name 1880 ;; Find a -*- mode tag
1864 ;; Find a -*- mode tag 1881 (save-excursion
1865 (save-excursion 1882 (goto-char (point-min))
1866 (goto-char (point-min)) 1883 (skip-chars-forward " \t\n")
1867 (skip-chars-forward " \t\n") 1884 ;; While we're at this point, check xml for later.
1868 ;; While we're at this point, check xml for later. 1885 (setq xml (looking-at "<\\?xml \\|<!DOCTYPE"))
1869 (setq xml (looking-at "<\\?xml \\|<!DOCTYPE")) 1886 (and enable-local-variables
1870 (and enable-local-variables 1887 (setq end (set-auto-mode-1))
1871 (setq end (set-auto-mode-1)) 1888 (if (save-excursion (search-forward ":" end t))
1872 (if (save-excursion (search-forward ":" end t)) 1889 ;; Find all specifications for the `mode:' variable
1873 ;; Find all specifications for the `mode:' variable 1890 ;; and execute them left to right.
1874 ;; and execute them left to right. 1891 (while (let ((case-fold-search t))
1875 (while (let ((case-fold-search t)) 1892 (or (and (looking-at "mode:")
1876 (or (and (looking-at "mode:") 1893 (goto-char (match-end 0)))
1877 (goto-char (match-end 0))) 1894 (re-search-forward "[ \t;]mode:" end t)))
1878 (re-search-forward "[ \t;]mode:" end t))) 1895 (skip-chars-forward " \t")
1879 (skip-chars-forward " \t") 1896 (let ((beg (point)))
1880 (let ((beg (point))) 1897 (if (search-forward ";" end t)
1881 (if (search-forward ";" end t) 1898 (forward-char -1)
1882 (forward-char -1) 1899 (goto-char end))
1883 (goto-char end)) 1900 (skip-chars-backward " \t")
1884 (skip-chars-backward " \t") 1901 (push (intern (concat (downcase (buffer-substring beg (point))) "-mode"))
1885 (push (intern (concat (downcase (buffer-substring beg (point))) "-mode")) 1902 modes)))
1886 modes))) 1903 ;; Simple -*-MODE-*- case.
1887 ;; Simple -*-MODE-*- case. 1904 (push (intern (concat (downcase (buffer-substring (point) end))
1888 (push (intern (concat (downcase (buffer-substring (point) end)) 1905 "-mode"))
1889 "-mode")) 1906 modes))))
1890 modes)))) 1907 ;; 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. 1908 (if modes
1892 (if modes 1909 (catch 'nop
1893 (dolist (mode (nreverse modes)) 1910 (dolist (mode (nreverse modes))
1894 (if (not (functionp mode)) 1911 (if (not (functionp mode))
1895 (message "Ignoring unknown mode `%s'" mode) 1912 (message "Ignoring unknown mode `%s'" mode)
1896 (setq done t) 1913 (setq done t)
1897 (funcall mode))) 1914 (or (set-auto-mode-0 mode keep-mode-if-same)
1898 ;; If we didn't, look for an interpreter specified in the first line. 1915 (throw 'nop nil)))))
1899 ;; As a special case, allow for things like "#!/bin/env perl", which 1916 ;; If we didn't, look for an interpreter specified in the first line.
1900 ;; finds the interpreter anywhere in $PATH. 1917 ;; As a special case, allow for things like "#!/bin/env perl", which
1901 (setq mode (save-excursion 1918 ;; finds the interpreter anywhere in $PATH.
1902 (goto-char (point-min)) 1919 (setq mode (save-excursion
1903 (if (looking-at auto-mode-interpreter-regexp) 1920 (goto-char (point-min))
1904 (match-string 2) 1921 (if (looking-at auto-mode-interpreter-regexp)
1905 "")) 1922 (match-string 2)
1906 ;; Map interpreter name to a mode, signalling we're done at the 1923 ""))
1907 ;; same time. 1924 ;; Map interpreter name to a mode, signalling we're done at the
1908 done (assoc (file-name-nondirectory mode) 1925 ;; same time.
1909 interpreter-mode-alist)) 1926 done (assoc (file-name-nondirectory mode)
1910 ;; If we found an interpreter mode to use, invoke it now. 1927 interpreter-mode-alist)))
1911 (if done (funcall (cdr done))))) 1928 ;; If we found an interpreter mode to use, invoke it now.
1912 (if (and (not done) buffer-file-name) 1929 (if done
1913 (let ((name buffer-file-name)) 1930 (set-auto-mode-0 (cdr done) keep-mode-if-same)
1914 ;; Remove backup-suffixes from file name. 1931 (if (setq done (save-excursion
1915 (setq name (file-name-sans-versions name)) 1932 (goto-char (point-min))
1916 (while (not done) 1933 (assoc-default nil magic-mode-alist
1917 ;; Find first matching alist entry. 1934 (lambda (re dummy)
1918 (let ((case-fold-search 1935 (looking-at re)))))
1919 (memq system-type '(vax-vms windows-nt cygwin)))) 1936 (set-auto-mode-0 done keep-mode-if-same)
1920 (if (and (setq mode (assoc-default name auto-mode-alist 1937 (if buffer-file-name
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
1921 'string-match)) 1946 'string-match))
1922 (consp mode) 1947 (consp mode)
1923 (cadr mode)) 1948 (cadr mode))
1924 (setq mode (car mode) 1949 (setq mode (car mode)
1925 name (substring name 0 (match-beginning 0))) 1950 name (substring name 0 (match-beginning 0)))
1926 (setq done t))) 1951 (setq name)))
1927 (if mode 1952 (when mode
1928 ;; When JUST-FROM-FILE-NAME is set, we are working on behalf 1953 (set-auto-mode-0 mode keep-mode-if-same)))))))))
1929 ;; of set-visited-file-name. In that case, if the major mode 1954
1930 ;; specified is the same one we already have, don't actually 1955
1931 ;; reset it. We don't want to lose minor modes such as Font 1956 ;; When `keep-mode-if-same' is set, we are working on behalf of
1932 ;; Lock. 1957 ;; set-visited-file-name. In that case, if the major mode specified is the
1933 (unless (and just-from-file-name (eq mode major-mode)) 1958 ;; same one we already have, don't actually reset it. We don't want to lose
1934 (if (if xml (memq mode xml-based-modes) t) 1959 ;; minor modes such as Font Lock.
1935 (funcall mode) 1960 (defun set-auto-mode-0 (mode &optional keep-mode-if-same)
1936 (xml-mode))))))) 1961 "Apply MODE and return it.
1937 (and (not done) 1962 If optional arg KEEP-MODE-IF-SAME is non-nil, MODE is chased of
1938 xml 1963 any aliases and compared to current major mode. If they are the
1939 (xml-mode)))) 1964 same, do nothing and return nil."
1965 (when keep-mode-if-same
1966 (while (symbolp (symbol-function mode))
1967 (setq mode (symbol-function mode)))
1968 (if (eq mode major-mode)
1969 (setq mode nil)))
1970 (when mode
1971 (funcall mode)
1972 mode))
1940 1973
1941 1974
1942 (defun set-auto-mode-1 () 1975 (defun set-auto-mode-1 ()
1943 "Find the -*- spec in the buffer. 1976 "Find the -*- spec in the buffer.
1944 Call with point at the place to start searching from. 1977 Call with point at the place to start searching from.
3795 (message "No files can be recovered from this session now"))) 3828 (message "No files can be recovered from this session now")))
3796 (kill-buffer buffer)))) 3829 (kill-buffer buffer))))
3797 3830
3798 (defun kill-some-buffers (&optional list) 3831 (defun kill-some-buffers (&optional list)
3799 "Kill some buffers. Asks the user whether to kill each one of them. 3832 "Kill some buffers. Asks the user whether to kill each one of them.
3800 Non-interactively, if optional argument LIST is non-`nil', it 3833 Non-interactively, if optional argument LIST is non-nil, it
3801 specifies the list of buffers to kill, asking for approval for each one." 3834 specifies the list of buffers to kill, asking for approval for each one."
3802 (interactive) 3835 (interactive)
3803 (if (null list) 3836 (if (null list)
3804 (setq list (buffer-list))) 3837 (setq list (buffer-list)))
3805 (while list 3838 (while list