Mercurial > hg > xemacs-beta
comparison lisp/code-files.el @ 748:ca2d04c5710a
[xemacs-hg @ 2002-02-12 14:24:39 by stephent]
fix write-region-pre-hook <87wuxi944z.fsf@tleeps18.sk.tsukuba.ac.jp>
author | stephent |
---|---|
date | Tue, 12 Feb 2002 14:24:40 +0000 |
parents | 685b588e92d8 |
children | 943eaba38521 |
comparison
equal
deleted
inserted
replaced
747:9f953fdc1394 | 748:ca2d04c5710a |
---|---|
196 ) | 196 ) |
197 (cond ((consp codesys) (find-coding-system (cdr codesys))) | 197 (cond ((consp codesys) (find-coding-system (cdr codesys))) |
198 ((find-coding-system codesys)) | 198 ((find-coding-system codesys)) |
199 )))) | 199 )))) |
200 | 200 |
201 ;; This is completely broken, not only in implementation (does not | 201 ;; This was completely broken, not only in implementation (does not |
202 ;; understand MIME), but in concept -- such high-level decoding should | 202 ;; understand MIME), but in concept -- such high-level decoding should |
203 ;; be done by mail readers, not by IO code! | 203 ;; be done by mail readers, not by IO code! Removed 2000-04-18. |
204 | 204 |
205 ;(defun convert-mbox-coding-system (filename visit start end) | 205 ;(defun convert-mbox-coding-system (filename visit start end) ...) |
206 ;... | |
207 | 206 |
208 (defun load (file &optional noerror nomessage nosuffix) | 207 (defun load (file &optional noerror nomessage nosuffix) |
209 "Execute a file of Lisp code named FILE. | 208 "Execute a file of Lisp code named FILE. |
210 First tries FILE with .elc appended, then tries with .el, | 209 First tries FILE with .elc appended, then tries with .el, |
211 then tries FILE unmodified. Searches directories in load-path. | 210 then tries FILE unmodified. Searches directories in load-path. |
411 return-val)) | 410 return-val)) |
412 | 411 |
413 (defvar write-region-pre-hook nil | 412 (defvar write-region-pre-hook nil |
414 "A special hook to decide the coding system used for writing out a file. | 413 "A special hook to decide the coding system used for writing out a file. |
415 | 414 |
416 Before writing a file, `write-region' calls the functions on this hook | 415 Before writing a file, `write-region' calls the functions on this hook with |
417 with arguments START, END, FILENAME, APPEND, VISIT, and CODING-SYSTEM, | 416 arguments START, END, FILENAME, APPEND, VISIT, LOCKNAME, and CODING-SYSTEM, |
418 the same as the corresponding arguments in the call to | 417 the same as the corresponding arguments in the call to `write-region'. |
419 `write-region'. | 418 |
420 | 419 The return value of each function should be one of |
421 The return value of the functions should be either | |
422 | 420 |
423 -- nil | 421 -- nil |
424 -- A coding system or a symbol denoting it, indicating the coding system | 422 -- A coding system or a symbol denoting it, indicating the coding system |
425 to be used for reading the file | 423 to be used for reading the file |
426 -- A list of two elements (absolute pathname and length of data written), | 424 -- A list of two elements (absolute pathname and length of data written), |
427 which is used as the return value to `write-region'. In this | 425 which is used as the return value to `write-region'. In this |
428 case, `write-region' assumes that the function has written | 426 case, `write-region' assumes that the function has written |
429 the file for itself and suppresses further writing. | 427 the file, and returns. |
430 | 428 |
431 If any function returns non-nil, the remaining functions are not called.") | 429 If any function returns non-nil, the remaining functions are not called.") |
432 | 430 |
433 (defvar write-region-post-hook nil | 431 (defvar write-region-post-hook nil |
434 "A hook called by `write-region' after a file has been written out. | 432 "A hook called by `write-region' after a file has been written out. |
435 | 433 |
436 The functions on this hook are called with arguments START, END, | 434 The functions on this hook are called with arguments START, END, |
437 FILENAME, APPEND, VISIT, and CODING-SYSTEM, the same as the | 435 FILENAME, APPEND, VISIT, LOCKNAME, and CODING-SYSTEM, the same as the |
438 corresponding arguments in the call to `write-region'.") | 436 corresponding arguments in the call to `write-region'.") |
439 | 437 |
440 (defun write-region (start end filename &optional append visit lockname coding-system) | 438 (defun write-region (start end filename &optional append visit lockname coding-system) |
441 "Write current region into specified file. | 439 "Write current region into specified file. |
442 By default the file's existing contents are replaced by the specified region. | 440 By default the file's existing contents are replaced by the specified region. |
443 When called from a program, takes three arguments: | 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: | |
444 START, END and FILENAME. START and END are buffer positions. | 445 START, END and FILENAME. START and END are buffer positions. |
445 Optional fourth argument APPEND if non-nil means | 446 Optional fourth argument APPEND if non-nil means |
446 append to existing file contents (if any). | 447 append to existing file contents (if any). |
447 Optional fifth argument VISIT if t means | 448 Optional fifth argument VISIT if t means |
448 set last-save-file-modtime of buffer to this file's modtime | 449 set last-save-file-modtime of buffer to this file's modtime |
457 Kludgy feature: if START is a string, then that string is written | 458 Kludgy feature: if START is a string, then that string is written |
458 to the file, instead of any buffer contents, and END is ignored. | 459 to the file, instead of any buffer contents, and END is ignored. |
459 Optional seventh argument CODING-SYSTEM specifies the coding system | 460 Optional seventh argument CODING-SYSTEM specifies the coding system |
460 used to encode the text when it is written out, and defaults to | 461 used to encode the text when it is written out, and defaults to |
461 the value of `buffer-file-coding-system' in the current buffer. | 462 the value of `buffer-file-coding-system' in the current buffer. |
462 Interactively, with a prefix arg, you will be prompted for the | |
463 coding system. | |
464 See also `write-region-pre-hook' and `write-region-post-hook'." | 463 See also `write-region-pre-hook' and `write-region-post-hook'." |
465 (interactive "r\nFWrite region to file: \ni\ni\ni\nZCoding-system: ") | 464 (interactive "r\nFWrite region to file: \ni\ni\ni\nZCoding-system: ") |
466 (setq coding-system | 465 (setq coding-system |
467 (or coding-system-for-write | 466 (or coding-system-for-write |
468 (run-hook-with-args-until-success | 467 (run-hook-with-args-until-success |
469 'write-region-pre-hook start end filename append visit lockname) | 468 'write-region-pre-hook |
469 start end filename append visit lockname coding-system) | |
470 coding-system | 470 coding-system |
471 buffer-file-coding-system | 471 buffer-file-coding-system |
472 (find-file-coding-system-for-write-from-filename filename) | 472 (find-file-coding-system-for-write-from-filename filename) |
473 )) | 473 )) |
474 (if (consp coding-system) | 474 (if (consp coding-system) |
475 ;; One of the `write-region-pre-hook' functions wrote the file | |
475 coding-system | 476 coding-system |
476 (let ((func | 477 (let ((func |
477 (coding-system-property coding-system 'pre-write-conversion))) | 478 (coding-system-property coding-system 'pre-write-conversion))) |
478 (if func | 479 (if func |
479 (let ((curbuf (current-buffer)) | 480 (let ((curbuf (current-buffer)) |