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