Mercurial > emacs
comparison lisp/files.el @ 90182:f042e7c0fe20
Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-53
Merge from emacs--cvs-trunk--0
Patches applied:
* emacs--cvs-trunk--0 (patch 302-319)
- Update from CVS
- Merge from gnus--rel--5.10
* gnus--rel--5.10 (patch 69)
- Update from CVS
author | Miles Bader <miles@gnu.org> |
---|---|
date | Fri, 20 May 2005 04:22:05 +0000 |
parents | 62afea0771d8 a7e02ef1e3d6 |
children | 5b029ff3b08d |
comparison
equal
deleted
inserted
replaced
90181:0c828e2b0b6f | 90182:f042e7c0fe20 |
---|---|
539 Fifth arg INITIAL specifies text to start with. | 539 Fifth arg INITIAL specifies text to start with. |
540 DIR should be an absolute directory name. It defaults to | 540 DIR should be an absolute directory name. It defaults to |
541 the value of `default-directory'." | 541 the value of `default-directory'." |
542 (unless dir | 542 (unless dir |
543 (setq dir default-directory)) | 543 (setq dir default-directory)) |
544 (read-file-name prompt dir (or default-dirname | 544 (read-file-name prompt dir (or default-dirname |
545 (if initial (expand-file-name initial dir) | 545 (if initial (expand-file-name initial dir) |
546 dir)) | 546 dir)) |
547 mustmatch initial | 547 mustmatch initial |
548 'file-directory-p)) | 548 'file-directory-p)) |
549 | 549 |
1726 `enable-local-variables' is ignored if you run `normal-mode' interactively, | 1726 `enable-local-variables' is ignored if you run `normal-mode' interactively, |
1727 or from Lisp without specifying the optional argument FIND-FILE; | 1727 or from Lisp without specifying the optional argument FIND-FILE; |
1728 in that case, this function acts as if `enable-local-variables' were t." | 1728 in that case, this function acts as if `enable-local-variables' were t." |
1729 (interactive) | 1729 (interactive) |
1730 (or find-file (funcall (or default-major-mode 'fundamental-mode))) | 1730 (or find-file (funcall (or default-major-mode 'fundamental-mode))) |
1731 (report-errors "File mode specification error: %s" | 1731 (let ((enable-local-variables (or (not find-file) enable-local-variables))) |
1732 (set-auto-mode)) | 1732 (report-errors "File mode specification error: %s" |
1733 (report-errors "File local-variables error: %s" | 1733 (set-auto-mode)) |
1734 (let ((enable-local-variables (or (not find-file) enable-local-variables))) | 1734 (report-errors "File local-variables error: %s" |
1735 (hack-local-variables))) | 1735 (hack-local-variables))) |
1736 (if (fboundp 'ucs-set-table-for-input) ; don't lose when building | 1736 (if (fboundp 'ucs-set-table-for-input) ; don't lose when building |
1737 (ucs-set-table-for-input))) | 1737 (ucs-set-table-for-input))) |
1738 | 1738 |
1739 (defvar auto-mode-alist | 1739 (defvar auto-mode-alist |
1760 ("\\.p\\'" . pascal-mode) | 1760 ("\\.p\\'" . pascal-mode) |
1761 ("\\.pas\\'" . pascal-mode) | 1761 ("\\.pas\\'" . pascal-mode) |
1762 ("\\.ad[abs]\\'" . ada-mode) | 1762 ("\\.ad[abs]\\'" . ada-mode) |
1763 ("\\.ad[bs].dg\\'" . ada-mode) | 1763 ("\\.ad[bs].dg\\'" . ada-mode) |
1764 ("\\.\\([pP]\\([Llm]\\|erl\\|od\\)\\|al\\)\\'" . perl-mode) | 1764 ("\\.\\([pP]\\([Llm]\\|erl\\|od\\)\\|al\\)\\'" . perl-mode) |
1765 ("\\.mk\\'" . makefile-mode) | 1765 ("\\.mk\\'" . makefile-gmake-mode) ; Might be any make, give Gnu the host advantage |
1766 ("\\([Mm]\\|GNUm\\)akep*file\\'" . makefile-mode) | 1766 ("[Mm]akefile\\'" . makefile-mode) |
1767 ("\\.am\\'" . makefile-mode) ;For Automake. | 1767 ("GNUmakefile\\'" . makefile-gmake-mode) |
1768 ("Makeppfile\\'" . makefile-makepp-mode) | |
1769 ("\\.am\\'" . makefile-automake-mode) | |
1768 ;; Less common extensions come here | 1770 ;; Less common extensions come here |
1769 ;; so more common ones above are found faster. | 1771 ;; so more common ones above are found faster. |
1770 ("\\.texinfo\\'" . texinfo-mode) | 1772 ("\\.texinfo\\'" . texinfo-mode) |
1771 ("\\.te?xi\\'" . texinfo-mode) | 1773 ("\\.te?xi\\'" . texinfo-mode) |
1772 ("\\.[sS]\\'" . asm-mode) | 1774 ("\\.[sS]\\'" . asm-mode) |
1934 ("zsh" . sh-mode) | 1936 ("zsh" . sh-mode) |
1935 ("tail" . text-mode) | 1937 ("tail" . text-mode) |
1936 ("more" . text-mode) | 1938 ("more" . text-mode) |
1937 ("less" . text-mode) | 1939 ("less" . text-mode) |
1938 ("pg" . text-mode) | 1940 ("pg" . text-mode) |
1939 ("make" . makefile-mode) ; Debian uses this | 1941 ("make" . makefile-gmake-mode) ; Debian uses this |
1940 ("guile" . scheme-mode) | 1942 ("guile" . scheme-mode) |
1941 ("clisp" . lisp-mode))) | 1943 ("clisp" . lisp-mode))) |
1942 "Alist mapping interpreter names to major modes. | 1944 "Alist mapping interpreter names to major modes. |
1943 This is used for files whose first lines match `auto-mode-interpreter-regexp'. | 1945 This is used for files whose first lines match `auto-mode-interpreter-regexp'. |
1944 Each element looks like (INTERPRETER . MODE). | 1946 Each element looks like (INTERPRETER . MODE). |
1945 The car of each element is compared with | 1947 The car of each element, a regular expression, is compared with |
1946 the name of the interpreter specified in the first line. | 1948 the name of the interpreter specified in the first line. |
1947 If it matches, mode MODE is selected. | 1949 If it matches, mode MODE is selected. |
1948 | 1950 |
1949 See also `auto-mode-alist'.") | 1951 See also `auto-mode-alist'.") |
1950 | 1952 |
1957 from the end of the file name anything that matches one of these regexps.") | 1959 from the end of the file name anything that matches one of these regexps.") |
1958 | 1960 |
1959 (defvar auto-mode-interpreter-regexp | 1961 (defvar auto-mode-interpreter-regexp |
1960 "#![ \t]?\\([^ \t\n]*\ | 1962 "#![ \t]?\\([^ \t\n]*\ |
1961 /bin/env[ \t]\\)?\\([^ \t\n]+\\)" | 1963 /bin/env[ \t]\\)?\\([^ \t\n]+\\)" |
1962 "Regular expression matching interpreters, for file mode determination. | 1964 "Regexp matching interpreters, for file mode determination. |
1963 This regular expression is matched against the first line of a file | 1965 This regular expression is matched against the first line of a file |
1964 to determine the file's mode in `set-auto-mode' when Emacs can't deduce | 1966 to determine the file's mode in `set-auto-mode'. If it matches, the file |
1965 a mode from the file's name. If it matches, the file is assumed to | 1967 is assumed to be interpreted by the interpreter matched by the second group |
1966 be interpreted by the interpreter matched by the second group of the | 1968 of the regular expression. The mode is then determined as the mode |
1967 regular expression. The mode is then determined as the mode associated | 1969 associated with that interpreter in `interpreter-mode-alist'.") |
1968 with that interpreter in `interpreter-mode-alist'.") | |
1969 | 1970 |
1970 (defvar magic-mode-alist | 1971 (defvar magic-mode-alist |
1971 `(;; The < comes before the groups (but the first) to reduce backtracking. | 1972 `(;; The < comes before the groups (but the first) to reduce backtracking. |
1972 ;; TODO: UTF-16 <?xml may be preceded by a BOM 0xff 0xfe or 0xfe 0xff. | 1973 ;; TODO: UTF-16 <?xml may be preceded by a BOM 0xff 0xfe or 0xfe 0xff. |
1973 (,(let* ((incomment-re "\\(?:[^-]\\|-[^-]\\)") | 1974 (,(let* ((incomment-re "\\(?:[^-]\\|-[^-]\\)") |
1990 if REGEXP matches the text at the beginning of the buffer, | 1991 if REGEXP matches the text at the beginning of the buffer, |
1991 `normal-mode' will call FUNCTION rather than allowing `auto-mode-alist' | 1992 `normal-mode' will call FUNCTION rather than allowing `auto-mode-alist' |
1992 to decide the buffer's major mode. | 1993 to decide the buffer's major mode. |
1993 | 1994 |
1994 If FUNCTION is nil, then it is not called. (That is a way of saying | 1995 If FUNCTION is nil, then it is not called. (That is a way of saying |
1995 \"allow `auto-mode-alist' to decide for these files.") | 1996 \"allow `auto-mode-alist' to decide for these files.)") |
1996 | 1997 |
1997 (defun set-auto-mode (&optional keep-mode-if-same) | 1998 (defun set-auto-mode (&optional keep-mode-if-same) |
1998 "Select major mode appropriate for current buffer. | 1999 "Select major mode appropriate for current buffer. |
1999 | 2000 |
2000 This checks for a -*- mode tag in the buffer's text, checks the | 2001 This checks for a -*- mode tag in the buffer's text, checks the |
2149 (skip-chars-backward " \t") | 2150 (skip-chars-backward " \t") |
2150 (setq end (point)) | 2151 (setq end (point)) |
2151 (goto-char beg) | 2152 (goto-char beg) |
2152 end)))) | 2153 end)))) |
2153 | 2154 |
2154 (defun hack-local-variables-confirm () | 2155 (defun hack-local-variables-confirm (string) |
2155 (or (eq enable-local-variables t) | 2156 (or (eq enable-local-variables t) |
2156 (and enable-local-variables | 2157 (and enable-local-variables |
2157 (save-window-excursion | 2158 (save-window-excursion |
2158 (condition-case nil | 2159 (condition-case nil |
2159 (switch-to-buffer (current-buffer)) | 2160 (switch-to-buffer (current-buffer)) |
2166 ;; be undone by save-window-excursion. | 2167 ;; be undone by save-window-excursion. |
2167 (pop-to-buffer (current-buffer))))) | 2168 (pop-to-buffer (current-buffer))))) |
2168 (save-excursion | 2169 (save-excursion |
2169 (beginning-of-line) | 2170 (beginning-of-line) |
2170 (set-window-start (selected-window) (point))) | 2171 (set-window-start (selected-window) (point))) |
2171 (y-or-n-p (format "Set local variables as specified in -*- line of %s? " | 2172 (y-or-n-p (format string |
2172 (file-name-nondirectory buffer-file-name))))))) | 2173 (if buffer-file-name |
2174 (file-name-nondirectory buffer-file-name) | |
2175 (concat "buffer " (buffer-name))))))))) | |
2173 | 2176 |
2174 (defun hack-local-variables-prop-line (&optional mode-only) | 2177 (defun hack-local-variables-prop-line (&optional mode-only) |
2175 "Set local variables specified in the -*- line. | 2178 "Set local variables specified in the -*- line. |
2176 Ignore any specification for `mode:' and `coding:'; | 2179 Ignore any specification for `mode:' and `coding:'; |
2177 `set-auto-mode' should already have handled `mode:', | 2180 `set-auto-mode' should already have handled `mode:', |
2223 (setq result (nreverse result)))) | 2226 (setq result (nreverse result)))) |
2224 | 2227 |
2225 (if mode-only mode-specified | 2228 (if mode-only mode-specified |
2226 (if (and result | 2229 (if (and result |
2227 (or mode-only | 2230 (or mode-only |
2228 (hack-local-variables-confirm))) | 2231 (hack-local-variables-confirm |
2232 "Set local variables as specified in -*- line of %s? "))) | |
2229 (let ((enable-local-eval enable-local-eval)) | 2233 (let ((enable-local-eval enable-local-eval)) |
2230 (while result | 2234 (while result |
2231 (hack-one-local-variable (car (car result)) (cdr (car result))) | 2235 (hack-one-local-variable (car (car result)) (cdr (car result))) |
2232 (setq result (cdr result))))) | 2236 (setq result (cdr result))))) |
2233 nil)))) | 2237 nil)))) |
2253 (goto-char (point-max)) | 2257 (goto-char (point-max)) |
2254 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move) | 2258 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move) |
2255 (when (let ((case-fold-search t)) | 2259 (when (let ((case-fold-search t)) |
2256 (and (search-forward "Local Variables:" nil t) | 2260 (and (search-forward "Local Variables:" nil t) |
2257 (or mode-only | 2261 (or mode-only |
2258 (hack-local-variables-confirm)))) | 2262 (hack-local-variables-confirm |
2263 "Set local variables as specified at end of %s? ")))) | |
2259 (skip-chars-forward " \t") | 2264 (skip-chars-forward " \t") |
2260 (let ((enable-local-eval enable-local-eval) | 2265 (let ((enable-local-eval enable-local-eval) |
2261 ;; suffix is what comes after "local variables:" in its line. | 2266 ;; suffix is what comes after "local variables:" in its line. |
2262 (suffix | 2267 (suffix |
2263 (concat | 2268 (concat |
2474 ;; if the args do nothing tricky. | 2479 ;; if the args do nothing tricky. |
2475 (if (or (and (eq var 'eval) | 2480 (if (or (and (eq var 'eval) |
2476 (hack-one-local-variable-eval-safep val)) | 2481 (hack-one-local-variable-eval-safep val)) |
2477 ;; Permit eval if not root and user says ok. | 2482 ;; Permit eval if not root and user says ok. |
2478 (and (not (zerop (user-uid))) | 2483 (and (not (zerop (user-uid))) |
2479 (hack-local-variables-confirm))) | 2484 (hack-local-variables-confirm |
2485 "Process `eval' or hook local variables in %s? "))) | |
2480 (if (eq var 'eval) | 2486 (if (eq var 'eval) |
2481 (save-excursion (eval val)) | 2487 (save-excursion (eval val)) |
2482 (make-local-variable var) | 2488 (make-local-variable var) |
2483 (set var val)) | 2489 (set var val)) |
2484 (message "Ignoring risky spec in the local variables list"))) | 2490 (message "Ignoring risky spec in the local variables list"))) |
2980 "Given the name of a numeric backup file, FN, return the backup number. | 2986 "Given the name of a numeric backup file, FN, return the backup number. |
2981 Uses the free variable `backup-extract-version-start', whose value should be | 2987 Uses the free variable `backup-extract-version-start', whose value should be |
2982 the index in the name where the version number begins." | 2988 the index in the name where the version number begins." |
2983 (if (and (string-match "[0-9]+~$" fn backup-extract-version-start) | 2989 (if (and (string-match "[0-9]+~$" fn backup-extract-version-start) |
2984 (= (match-beginning 0) backup-extract-version-start)) | 2990 (= (match-beginning 0) backup-extract-version-start)) |
2985 (string-to-int (substring fn backup-extract-version-start -1)) | 2991 (string-to-number (substring fn backup-extract-version-start -1)) |
2986 0)) | 2992 0)) |
2987 | 2993 |
2988 ;; I believe there is no need to alter this behavior for VMS; | 2994 ;; I believe there is no need to alter this behavior for VMS; |
2989 ;; since backup files are not made on VMS, it should not get called. | 2995 ;; since backup files are not made on VMS, it should not get called. |
2990 (defun find-backup-file-name (fn) | 2996 (defun find-backup-file-name (fn) |
4544 (call-process "ls" nil t nil "--version") | 4550 (call-process "ls" nil t nil "--version") |
4545 (buffer-string)))) | 4551 (buffer-string)))) |
4546 (if (string-match "ls (.*utils) \\([0-9.]*\\)$" version-out) | 4552 (if (string-match "ls (.*utils) \\([0-9.]*\\)$" version-out) |
4547 (let* ((version (match-string 1 version-out)) | 4553 (let* ((version (match-string 1 version-out)) |
4548 (split (split-string version "[.]")) | 4554 (split (split-string version "[.]")) |
4549 (numbers (mapcar 'string-to-int split)) | 4555 (numbers (mapcar 'string-to-number split)) |
4550 (min '(5 2 1)) | 4556 (min '(5 2 1)) |
4551 comparison) | 4557 comparison) |
4552 (while (and (not comparison) (or numbers min)) | 4558 (while (and (not comparison) (or numbers min)) |
4553 (cond ((null min) | 4559 (cond ((null min) |
4554 (setq comparison '>)) | 4560 (setq comparison '>)) |