annotate lisp/code-files.el @ 428:3ecd8885ac67 r21-2-22

Import from CVS: tag r21-2-22
author cvs
date Mon, 13 Aug 2007 11:28:15 +0200
parents
children abe6d1db359e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 ;;; code-files.el --- File I/O functions for XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 ;; Copyright (C) 1992,93,94,95 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 ;; Copyright (C) 1995 Amdahl Corporation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 ;; Copyright (C) 1995 Sun Microsystems.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 ;; This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 ;; XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 ;; under the terms of the GNU General Public License as published by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 ;; any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 ;; XEmacs is distributed in the hope that it will be useful, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 ;; General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 ;; along with XEmacs; see the file COPYING. If not, write to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 ;; Boston, MA 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 ;;; Synched up with: Not synched.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 ;;; Commentary:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 ;; Derived from mule.el in the original Mule but heavily modified
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 ;; by Ben Wing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 ;; 1997/3/11 modified by MORIOKA Tomohiko to sync with Emacs 20 API.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 ;; This file was derived from the former mule-files.el which has been removed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 ;; as of XEmacs 21.2.15.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 ;;; Code:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 (setq-default buffer-file-coding-system 'raw-text)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 (put 'buffer-file-coding-system 'permanent-local t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 (define-obsolete-variable-alias
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 'file-coding-system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 'buffer-file-coding-system)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 (define-obsolete-variable-alias
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 'overriding-file-coding-system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 'coding-system-for-read)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 (defvar buffer-file-coding-system-for-read 'undecided
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 "Coding system used when reading a file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 This provides coarse-grained control; for finer-grained control, use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 `file-coding-system-alist'. From a Lisp program, if you wish to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 unilaterally specify the coding system used for one particular
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 operation, you should bind the variable `coding-system-for-read'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 rather than setting this variable, which is intended to be used for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 global environment specification.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 (define-obsolete-variable-alias
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 'file-coding-system-for-read
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 'buffer-file-coding-system-for-read)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 (defvar file-coding-system-alist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 `(
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 ;; This must not be necessary, slb suggests -kkm
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 ;; ("loaddefs.el$" . (binary . binary))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 ,@(mapcar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 #'(lambda (regexp) (cons regexp 'binary)) binary-file-regexps)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 ("TUTORIAL\\.\\(?:hr\\|pl\\|ro\\)\\'" . iso-8859-2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 ;; ("\\.\\(el\\|emacs\\|info\\(-[0-9]+\\)?\\|texi\\)$" . iso-2022-8)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 ;; ("\\(ChangeLog\\|CHANGES-beta\\)$" . iso-2022-8)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 ("/spool/mail/.*$" . convert-mbox-coding-system))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 "Alist to decide a coding system to use for a file I/O operation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 The format is ((PATTERN . VAL) ...),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 where PATTERN is a regular expression matching a file name,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 VAL is a coding system, a cons of coding systems, or a function symbol.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 If VAL is a coding system, it is used for both decoding and encoding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 the file contents.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 If VAL is a cons of coding systems, the car part is used for decoding,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 and the cdr part is used for encoding.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 If VAL is a function symbol, the function must return a coding system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 or a cons of coding systems which are used as above.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 This overrides the more general specification in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 `buffer-file-coding-system-for-read', but is overridden by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 `coding-system-for-read'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 (defun set-buffer-file-coding-system (coding-system &optional force)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 "Set buffer-file-coding-system of the current buffer to CODING-SYSTEM.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 If optional argument FORCE (interactively, the prefix argument) is not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 given, attempt to match the EOL type of the new coding system to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 the current value of `buffer-file-coding-system'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 (interactive "zFile coding system: \nP")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 (get-coding-system coding-system) ;; correctness check
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 (if (not force)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 (setq coding-system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 (subsidiary-coding-system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 coding-system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 (coding-system-eol-type buffer-file-coding-system))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 (setq buffer-file-coding-system coding-system)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 (redraw-modeline t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 (defun toggle-buffer-file-coding-system ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 "Set EOL type of buffer-file-coding-system of the current buffer to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 something other than what it is at the moment."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 (let ((eol-type
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 (coding-system-eol-type buffer-file-coding-system)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 (setq buffer-file-coding-system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 (subsidiary-coding-system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 (coding-system-base buffer-file-coding-system)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 (cond ((eq eol-type 'lf) 'crlf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 ((eq eol-type 'crlf) 'lf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 ((eq eol-type 'cr) 'lf))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 (define-obsolete-function-alias
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 'set-file-coding-system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 'set-buffer-file-coding-system)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 (defun set-buffer-file-coding-system-for-read (coding-system)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 "Set the coding system used when reading in a file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 This is equivalent to setting the variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 `buffer-file-coding-system-for-read'. You can also use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 `file-coding-system-alist' to specify the coding system for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 particular files."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 (interactive "zFile coding system for read: ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 (get-coding-system coding-system) ;; correctness check
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 (setq buffer-file-coding-system-for-read coding-system))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 (define-obsolete-function-alias
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 'set-file-coding-system-for-read
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 'set-buffer-file-coding-system-for-read)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 (defun set-default-buffer-file-coding-system (coding-system)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 "Set the default value of `buffer-file-coding-system' to CODING-SYSTEM.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 The default value is used both for buffers without associated files
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 and for files with no apparent coding system (i.e. primarily ASCII).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 See `buffer-file-coding-system' for more information."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 (interactive "zDefault file coding system: ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 (setq-default buffer-file-coding-system coding-system)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 (redraw-modeline t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 (define-obsolete-function-alias
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 'set-default-file-coding-system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 'set-default-buffer-file-coding-system)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 (defun find-file-coding-system-for-read-from-filename (filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 "Look up coding system to read a file in `file-coding-system-alist'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 The return value will be nil (no applicable entry) or a coding system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 object (the entry specified a coding system)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 (let ((alist file-coding-system-alist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 (found nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 (codesys nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 (let ((case-fold-search nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 (setq filename (file-name-sans-versions filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 (while (and (not found) alist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 (if (string-match (car (car alist)) filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 (setq codesys (cdr (car alist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 found t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 (setq alist (cdr alist))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 (when codesys
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 (if (functionp codesys)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 (setq codesys (funcall codesys 'insert-file-contents filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 (cond ((consp codesys) (find-coding-system (car codesys)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 ((find-coding-system codesys))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 ))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 (define-obsolete-function-alias
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 'find-file-coding-system-from-filename
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 'find-file-coding-system-for-read-from-filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 (defun find-file-coding-system-for-write-from-filename (filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 "Look up coding system to write a file in `file-coding-system-alist'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 The return value will be nil (no applicable entry) or a coding system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 object (the entry specified a coding system)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 (let ((alist file-coding-system-alist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 (found nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 (codesys nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 (let ((case-fold-search nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 (setq filename (file-name-sans-versions filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 (while (and (not found) alist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 (if (string-match (car (car alist)) filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 (setq codesys (cdr (car alist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 found t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 (setq alist (cdr alist))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 (when codesys
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 (if (functionp codesys)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 (setq codesys (funcall codesys 'write-region filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 (cond ((consp codesys) (find-coding-system (cdr codesys)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 ((find-coding-system codesys))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 ))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 (defun convert-mbox-coding-system (filename visit start end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 "Decoding function for Unix mailboxes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 Does separate detection and decoding on each message, since each
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 message might be in a different encoding."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 (let ((buffer-read-only nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 (narrow-to-region start end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 (while (not (eobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 (let ((start (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 (forward-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 (if (re-search-forward "^From" nil 'move)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 (beginning-of-line))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 (setq end (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 (decode-coding-region start end 'undecided))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 (defun find-coding-system-magic-cookie ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 "Look for the coding-system magic cookie in the current buffer.\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 "The coding-system magic cookie is the exact string\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 "\";;;###coding system: \" followed by a valid coding system symbol,\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 "somewhere within the first 3000 characters of the file. If found,\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 "the coding system symbol is returned; otherwise nil is returned.\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 "Note that it is extremely unlikely that such a string would occur\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 "coincidentally as the result of encoding some characters in a non-ASCII\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 "charset, and that the spaces make it even less likely since the space\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 "character is not a valid octet in any ISO 2022 encoding of most non-ASCII\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 "charsets."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 (or (and (looking-at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 "^[^\n]*-\\*-[^\n]*coding: \\([^ \t\n;]+\\)[^\n]*-\\*-")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 (let ((codesys (intern (buffer-substring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 (match-beginning 1)(match-end 1)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 (if (find-coding-system codesys) codesys)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 ;; (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 ;; (let (start end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 ;; (and (re-search-forward "^;+[ \t]*Local Variables:" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 ;; (setq start (match-end 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 ;; (re-search-forward "\n;+[ \t]*End:")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 ;; (setq end (match-beginning 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 ;; (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 ;; (narrow-to-region start end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 ;; (goto-char start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 ;; (re-search-forward "^;;; coding: \\([^\n]+\\)$" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 ;; )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 ;; (let ((codesys
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 ;; (intern (buffer-substring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 ;; (match-beginning 1)(match-end 1)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 ;; (if (find-coding-system codesys) codesys))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 ;; )))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 (let ((case-fold-search nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 (if (search-forward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 ";;;###coding system: " (+ (point-min) 3000) t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 (let ((start (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 (end (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 (skip-chars-forward "^ \t\n\r")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 (if (> end start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 (let ((codesys (intern (buffer-substring start end))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 (if (find-coding-system codesys) codesys)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 )))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 )))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 (defun load (file &optional noerror nomessage nosuffix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 "Execute a file of Lisp code named FILE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 First tries FILE with .elc appended, then tries with .el,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 then tries FILE unmodified. Searches directories in load-path.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 If optional second arg NOERROR is non-nil,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 report no error if FILE doesn't exist.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 Print messages at start and end of loading unless
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 optional third arg NOMESSAGE is non-nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 If optional fourth arg NOSUFFIX is non-nil, don't try adding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 suffixes .elc or .el to the specified name FILE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 Return t if file exists."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 (let* ((filename (substitute-in-file-name file))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 (handler (find-file-name-handler filename 'load))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 (path nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 (if handler
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 (funcall handler 'load filename noerror nomessage nosuffix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 (if (or (<= (length filename) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 (null (setq path
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 (locate-file filename load-path
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 (and (not nosuffix) '(".elc" ".el" ""))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 (and (null noerror)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 (signal 'file-error (list "Cannot open load file" filename)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 ;; now use the internal load to actually load the file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 (load-internal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 file noerror nomessage nosuffix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 (let ((elc ; use string= instead of string-match to keep match-data.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 (string= ".elc" (downcase (substring path -4)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 (or (and (not elc) coding-system-for-read) ; prefer for source file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 ;; find magic-cookie
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 (set-buffer (get-buffer-create " *load*"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 (let ((coding-system-for-read 'raw-text))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 (insert-file-contents path nil 1 3001))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 (find-coding-system-magic-cookie))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 (if elc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 ;; if reading a byte-compiled file and we didn't find
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 ;; a coding-system magic cookie, then use `binary'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 ;; We need to guarantee that we never do autodetection
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 ;; on byte-compiled files because confusion here would
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 ;; be a very bad thing. Pre-existing byte-compiled
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 ;; files are always in the `binary' coding system.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 ;; Also, byte-compiled files always use `lf' to terminate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 ;; a line; don't risk confusion here either.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 'binary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 (or (find-file-coding-system-for-read-from-filename path)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 ;; looking up in `file-coding-system-alist'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 ;; otherwise use `buffer-file-coding-system-for-read',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 ;; as normal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 buffer-file-coding-system-for-read)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 )))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 )))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 (defvar insert-file-contents-access-hook nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 "A hook to make a file accessible before reading it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 `insert-file-contents' calls this hook before doing anything else.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 Called with two arguments: FILENAME and VISIT, the same as the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 corresponding arguments in the call to `insert-file-contents'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 (defvar insert-file-contents-pre-hook nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 "A special hook to decide the coding system used for reading in a file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 Before reading a file, `insert-file-contents' calls the functions on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 this hook with arguments FILENAME and VISIT, the same as the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 corresponding arguments in the call to `insert-file-contents'. In
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 these functions, you may refer to the global variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 `buffer-file-coding-system-for-read'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 The return value of the functions should be either
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 -- nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 -- A coding system or a symbol denoting it, indicating the coding system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 to be used for reading the file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 -- A list of two elements (absolute pathname and length of data inserted),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 which is used as the return value to `insert-file-contents'. In this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 case, `insert-file-contents' assumes that the function has inserted
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 the file for itself and suppresses further reading.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 If any function returns non-nil, the remaining functions are not called.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 (defvar insert-file-contents-error-hook nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 "A hook to set `buffer-file-coding-system' when a read error has occurred.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 When a file error (e.g. nonexistent file) occurs while read a file,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 `insert-file-contents' calls the functions on this hook with three
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 arguments: FILENAME and VISIT (the same as the corresponding arguments
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 in the call to `insert-file-contents') and a cons (SIGNALED-CONDITIONS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 . SIGNAL-DATA).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 After calling this hook, the error is signalled for real and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 propagates to the caller of `insert-file-contents'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 (defvar insert-file-contents-post-hook nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 "A hook to set `buffer-file-coding-system' for the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 After successful reading, `insert-file-contents' calls the functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 on this hook with four arguments: FILENAME and VISIT (the same as the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 corresponding arguments in the call to `insert-file-contents'),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 CODING-SYSTEM (the actual coding system used to decode the file), and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 a cons of absolute pathname and length of data inserted (the same
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 thing as will be returned from `insert-file-contents').")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 (defun insert-file-contents (filename &optional visit beg end replace)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 "Insert contents of file FILENAME after point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 Returns list of absolute file name and length of data inserted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 If second argument VISIT is non-nil, the buffer's visited filename
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 and last save file modtime are set, and it is marked unmodified.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 If visiting and the file does not exist, visiting is completed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 before the error is signaled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 The optional third and fourth arguments BEG and END
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 specify what portion of the file to insert.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 If VISIT is non-nil, BEG and END must be nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 If optional fifth argument REPLACE is non-nil,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 it means replace the current buffer contents (in the accessible portion)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 with the file contents. This is better than simply deleting and inserting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 the whole thing because (1) it preserves some marker positions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 and (2) it puts less data in the undo list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 The coding system used for decoding the file is determined as follows:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 1. `coding-system-for-read', if non-nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 2. The result of `insert-file-contents-pre-hook', if non-nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 3. The matching value for this filename from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 `file-coding-system-alist', if any.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 4. `buffer-file-coding-system-for-read', if non-nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 5. The coding system 'raw-text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 If a local value for `buffer-file-coding-system' in the current buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 does not exist, it is set to the coding system which was actually used
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 for reading.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 See also `insert-file-contents-access-hook',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 `insert-file-contents-pre-hook', `insert-file-contents-error-hook',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 and `insert-file-contents-post-hook'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 (let (return-val coding-system used-codesys)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 ;; OK, first load the file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 (condition-case err
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 (run-hook-with-args 'insert-file-contents-access-hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 filename visit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 ;; determine the coding system to use, as described above.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 (setq coding-system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 (or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 ;; #1.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 coding-system-for-read
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 ;; #2.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 (run-hook-with-args-until-success
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 'insert-file-contents-pre-hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 filename visit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 ;; #3.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 (find-file-coding-system-for-read-from-filename filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 ;; #4.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 buffer-file-coding-system-for-read
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 ;; #5.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 'raw-text))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 (if (consp coding-system)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 (setq return-val coding-system)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 (if (null (find-coding-system coding-system))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 (message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 "Invalid coding-system (%s), using 'undecided"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 coding-system)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 (setq coding-system 'undecided)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 (setq return-val
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 (insert-file-contents-internal filename visit beg end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 replace coding-system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 ;; store here!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 'used-codesys))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 (file-error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 (run-hook-with-args 'insert-file-contents-error-hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 filename visit err)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 (signal (car err) (cdr err))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 (setq coding-system used-codesys)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 ;; call any `post-read-conversion' for the coding system that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 ;; was used ...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 (let ((func
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 (coding-system-property coding-system 'post-read-conversion))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 (endmark (make-marker)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 (set-marker endmark (+ (point) (nth 1 return-val)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 (if func
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 (unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 (let (buffer-read-only)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 (funcall func (point) (marker-position endmark))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 (if visit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 (set-buffer-auto-saved)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 (set-buffer-modified-p nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 (setcar (cdr return-val) (- (marker-position endmark) (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 ;; now finally set the buffer's `buffer-file-coding-system'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 (if (run-hook-with-args-until-success 'insert-file-contents-post-hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 filename visit return-val)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 (if (local-variable-p 'buffer-file-coding-system (current-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 ;; if buffer-file-coding-system is already local, just
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 ;; set its eol type to what was found, if it wasn't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 ;; set already.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 (set-buffer-file-coding-system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 (subsidiary-coding-system buffer-file-coding-system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 (coding-system-eol-type coding-system)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 ;; otherwise actually set buffer-file-coding-system.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 (set-buffer-file-coding-system coding-system)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 return-val))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 (defvar write-region-pre-hook nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 "A special hook to decide the coding system used for writing out a file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 Before writing a file, `write-region' calls the functions on this hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 with arguments START, END, FILENAME, APPEND, VISIT, and CODING-SYSTEM,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 the same as the corresponding arguments in the call to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 `write-region'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 The return value of the functions should be either
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 -- nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 -- A coding system or a symbol denoting it, indicating the coding system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 to be used for reading the file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 -- A list of two elements (absolute pathname and length of data written),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 which is used as the return value to `write-region'. In this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 case, `write-region' assumes that the function has written
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 the file for itself and suppresses further writing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 If any function returns non-nil, the remaining functions are not called.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 (defvar write-region-post-hook nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 "A hook called by `write-region' after a file has been written out.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 The functions on this hook are called with arguments START, END,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 FILENAME, APPEND, VISIT, and CODING-SYSTEM, the same as the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 corresponding arguments in the call to `write-region'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 (defun write-region (start end filename &optional append visit lockname coding-system)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 "Write current region into specified file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 By default the file's existing contents are replaced by the specified region.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 When called from a program, takes three arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 START, END and FILENAME. START and END are buffer positions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 Optional fourth argument APPEND if non-nil means
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 append to existing file contents (if any).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 Optional fifth argument VISIT if t means
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 set last-save-file-modtime of buffer to this file's modtime
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 and mark buffer not modified.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 If VISIT is a string, it is a second file name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 the output goes to FILENAME, but the buffer is marked as visiting VISIT.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 VISIT is also the file name to lock and unlock for clash detection.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 If VISIT is neither t nor nil nor a string,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 that means do not print the \"Wrote file\" message.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 The optional sixth arg LOCKNAME, if non-nil, specifies the name to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 use for locking and unlocking, overriding FILENAME and VISIT.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 Kludgy feature: if START is a string, then that string is written
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 to the file, instead of any buffer contents, and END is ignored.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 Optional seventh argument CODING-SYSTEM specifies the coding system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 used to encode the text when it is written out, and defaults to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 the value of `buffer-file-coding-system' in the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 Interactively, with a prefix arg, you will be prompted for the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 coding system.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 See also `write-region-pre-hook' and `write-region-post-hook'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 (interactive "r\nFWrite region to file: \ni\ni\ni\nZCoding-system: ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 (setq coding-system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 (or coding-system-for-write
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 (run-hook-with-args-until-success
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 'write-region-pre-hook start end filename append visit lockname)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 coding-system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 buffer-file-coding-system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 (find-file-coding-system-for-write-from-filename filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 (if (consp coding-system)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 coding-system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 (let ((func
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 (coding-system-property coding-system 'pre-write-conversion)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 (if func
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 (let ((curbuf (current-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 (tempbuf (generate-new-buffer " *temp-write-buffer*"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 (modif (buffer-modified-p)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 (unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 (set-buffer tempbuf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 (insert-buffer-substring curbuf start end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 (funcall func (point-min) (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 (write-region-internal (point-min) (point-max) filename
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 append
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 (if (eq visit t) nil visit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 lockname
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 coding-system))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 ;; leaving a buffer associated with file will cause problems
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 ;; when next visiting.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 (kill-buffer tempbuf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 (if (or visit (null modif))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 (set-buffer-auto-saved)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 (set-buffer-modified-p nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 (if (buffer-file-name) (set-visited-file-modtime))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 (write-region-internal start end filename append visit lockname
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 coding-system)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 (run-hook-with-args 'write-region-post-hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 start end filename append visit lockname
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 coding-system)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 ;;; The following was all that remained in mule-files.el, so I moved it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 ;;; here for neatness. -sb
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 (when (featurep 'mule)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 (setq-default buffer-file-coding-system 'iso-2022-8))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 ;;; code-files.el ends here