comparison lisp/international/mule-cmds.el @ 45631:b01cd9b1ae08

(select-safe-coding-system): New arg FILE; use that for set-auto-coding. When computing auto-cs, narrow to FROM...TO. Put save-excursion outside save-restriction.
author Richard M. Stallman <rms@gnu.org>
date Mon, 03 Jun 2002 22:55:26 +0000
parents 837ac5e7592f
children b634913b5b45
comparison
equal deleted inserted replaced
45630:c6e4c52881d7 45631:b01cd9b1ae08
541 The meaning is the same as the argument ACCEPT-DEFAULT-P of the 541 The meaning is the same as the argument ACCEPT-DEFAULT-P of the
542 function `select-safe-coding-system' (which see). This variable 542 function `select-safe-coding-system' (which see). This variable
543 overrides that argument.") 543 overrides that argument.")
544 544
545 (defun select-safe-coding-system (from to &optional default-coding-system 545 (defun select-safe-coding-system (from to &optional default-coding-system
546 accept-default-p) 546 accept-default-p file)
547 "Ask a user to select a safe coding system from candidates. 547 "Ask a user to select a safe coding system from candidates.
548 The candidates of coding systems which can safely encode a text 548 The candidates of coding systems which can safely encode a text
549 between FROM and TO are shown in a popup window. Among them, the most 549 between FROM and TO are shown in a popup window. Among them, the most
550 proper one is suggested as the default. 550 proper one is suggested as the default.
551 551
561 561
562 Optional 4th arg ACCEPT-DEFAULT-P, if non-nil, is a function to 562 Optional 4th arg ACCEPT-DEFAULT-P, if non-nil, is a function to
563 determine the acceptability of the silently selected coding system. 563 determine the acceptability of the silently selected coding system.
564 It is called with that coding system, and should return nil if it 564 It is called with that coding system, and should return nil if it
565 should not be silently selected and thus user interaction is required. 565 should not be silently selected and thus user interaction is required.
566
567 Optional 5th arg FILE is the file name to use for this purpose.
568 That is different from `buffer-file-name' when handling `write-region'
569 \(for example).
566 570
567 The variable `select-safe-coding-system-accept-default-p', if 571 The variable `select-safe-coding-system-accept-default-p', if
568 non-nil, overrides ACCEPT-DEFAULT-P. 572 non-nil, overrides ACCEPT-DEFAULT-P.
569 573
570 Kludgy feature: if FROM is a string, the string is the target text, 574 Kludgy feature: if FROM is a string, the string is the target text,
716 (if (eq coding-system t) 720 (if (eq coding-system t)
717 (setq coding-system buffer-file-coding-system)) 721 (setq coding-system buffer-file-coding-system))
718 ;; Check we're not inconsistent with what `coding:' spec &c would 722 ;; Check we're not inconsistent with what `coding:' spec &c would
719 ;; give when file is re-read. 723 ;; give when file is re-read.
720 (unless (stringp from) 724 (unless (stringp from)
721 (let ((auto-cs (save-restriction 725 (let ((auto-cs (save-excursion
722 (widen) 726 (save-restriction
723 (save-excursion 727 (widen)
728 (narrow-to-region from to)
724 (goto-char (point-min)) 729 (goto-char (point-min))
725 (set-auto-coding (or buffer-file-name "") 730 (set-auto-coding (or file buffer-file-name "")
726 (buffer-size)))))) 731 (buffer-size))))))
727 (if (and auto-cs 732 (if (and auto-cs
728 (not (coding-system-equal (coding-system-base coding-system) 733 (not (coding-system-equal (coding-system-base coding-system)
729 (coding-system-base auto-cs)))) 734 (coding-system-base auto-cs))))
730 (unless (yes-or-no-p 735 (unless (yes-or-no-p