aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenichi Handa2002-09-25 13:19:59 +0000
committerKenichi Handa2002-09-25 13:19:59 +0000
commitc0d3ed9724ae7b8a118565e9a175096b37185726 (patch)
tree818ec84822eb602210cb9f6495cbb20b883ba88c
parent76320e8edc89467467ff5a6a72ce09ea07e4dff6 (diff)
downloademacs-c0d3ed9724ae7b8a118565e9a175096b37185726.tar.gz
emacs-c0d3ed9724ae7b8a118565e9a175096b37185726.zip
(select-safe-coding-system): Handle
safe but rejected default coding systems and unsafe default coding systems differently.
-rw-r--r--lisp/international/mule-cmds.el167
1 files changed, 89 insertions, 78 deletions
diff --git a/lisp/international/mule-cmds.el b/lisp/international/mule-cmds.el
index 1f657700fc8..7ea2046bb0c 100644
--- a/lisp/international/mule-cmds.el
+++ b/lisp/international/mule-cmds.el
@@ -661,43 +661,48 @@ and TO is ignored."
661 (let ((codings (find-coding-systems-region from to)) 661 (let ((codings (find-coding-systems-region from to))
662 (coding-system nil) 662 (coding-system nil)
663 (bufname (buffer-name)) 663 (bufname (buffer-name))
664 (l default-coding-system)) 664 safe rejected unsafe)
665 (if (eq (car codings) 'undecided) 665 (if (eq (car codings) 'undecided)
666 ;; Any coding system is ok. 666 ;; Any coding system is ok.
667 (setq coding-system t) 667 (setq coding-system t)
668 ;; Try the defaults. 668 ;; Classify the defaults into safe, rejected, and unsafe.
669 (while (and l (not coding-system)) 669 (dolist (elt default-coding-system)
670 (if (memq (cdr (car l)) codings) 670 (if (memq (cdr elt) codings)
671 (setq coding-system (car (car l))) 671 (if (and (functionp accept-default-p)
672 (setq l (cdr l)))) 672 (not (funcall accept-default-p (cdr elt))))
673 (if (and coding-system accept-default-p) 673 (push (car elt) rejected)
674 (or (funcall accept-default-p coding-system) 674 (push (car elt) safe))
675 (setq coding-system (list coding-system))))) 675 (push (car elt) unsafe)))
676 676 (if safe
677 (setq coding-system (car (last safe)))))
678
679 (setq x (list default-coding-system safe rejected unsafe))
677 ;; If all the defaults failed, ask a user. 680 ;; If all the defaults failed, ask a user.
678 (when (or (not coding-system) (consp coding-system)) 681 (when (not coding-system)
679 ;; At first, record at most 11 problematic characters and their 682 ;; At first, if some defaults are unsafe, record at most 11
680 ;; positions for each default. 683 ;; problematic characters and their positions for them by turning
681 (if (stringp from) 684 ;; (CODING ...)
682 (mapc #'(lambda (coding) 685 ;; into
683 (setcdr coding 686 ;; ((CODING (POS . CHAR) (POS . CHAR) ...) ...)
684 (mapcar #'(lambda (pos) 687 (if unsafe
685 (cons pos (aref from pos))) 688 (if (stringp from)
686 (unencodable-char-position 689 (setq unsafe
687 0 (length from) (car coding) 11 from)))) 690 (mapcar #'(lambda (coding)
688 default-coding-system) 691 (cons coding
689 (mapc #'(lambda (coding) 692 (mapcar #'(lambda (pos)
690 (setcdr coding 693 (cons pos (aref from pos)))
691 (mapcar #'(lambda (pos) 694 (unencodable-char-position
692 (cons pos (char-after pos))) 695 0 (length from) coding
693 (unencodable-char-position 696 11 from))))
694 from to (car coding) 11)))) 697 unsafe))
695 default-coding-system)) 698 (setq unsafe
696 ;; If 11 unencodable characters were found, mark the last one as nil. 699 (mapcar #'(lambda (coding)
697 (mapc #'(lambda (coding) 700 (cons coding
698 (if (> (length coding) 11) 701 (mapcar #'(lambda (pos)
699 (setcdr (car (last coding)) nil))) 702 (cons pos (char-after pos)))
700 default-coding-system) 703 (unencodable-char-position
704 from to coding 11))))
705 unsafe))))
701 706
702 ;; Change each safe coding system to the corresponding 707 ;; Change each safe coding system to the corresponding
703 ;; mime-charset name if it is also a coding system. Such a name 708 ;; mime-charset name if it is also a coding system. Such a name
@@ -722,13 +727,14 @@ and TO is ignored."
722 727
723 (let ((window-configuration (current-window-configuration))) 728 (let ((window-configuration (current-window-configuration)))
724 (save-excursion 729 (save-excursion
725 ;; Make sure the offending buffer is displayed. 730 ;; If some defaults are unsafe, make sure the offending
726 (when (and (consp default-coding-system) (not (stringp from))) 731 ;; buffer is displayed.
732 (when (and unsafe (not (stringp from)))
727 (pop-to-buffer bufname) 733 (pop-to-buffer bufname)
728 ;; The `or' is because sometimes (car (cadr x)) is nil. 734 (goto-char (apply 'min (mapcar #'(lambda (x) (car (cadr x)))
729 (goto-char (apply 'min (mapcar #'(lambda (x) (or (car (cadr x)) (point-max))) 735 unsafe))))
730 default-coding-system)))) 736 ;; Then ask users to select one from CODINGS while showing
731 ;; Then ask users to select one from CODINGS. 737 ;; the reason why none of the defaults are not used.
732 (with-output-to-temp-buffer "*Warning*" 738 (with-output-to-temp-buffer "*Warning*"
733 (save-excursion 739 (save-excursion
734 (set-buffer standard-output) 740 (set-buffer standard-output)
@@ -747,44 +753,30 @@ and TO is ignored."
747 ":\n") 753 ":\n")
748 (let ((pos (point)) 754 (let ((pos (point))
749 (fill-prefix " ")) 755 (fill-prefix " "))
750 (mapcar (function (lambda (x) 756 (mapc #'(lambda (x) (princ " ") (princ (car x)))
751 (princ " ") (princ (car x)))) 757 default-coding-system)
752 default-coding-system)
753 (insert "\n") 758 (insert "\n")
754 (fill-region-as-paragraph pos (point))) 759 (fill-region-as-paragraph pos (point)))
755 (if (consp coding-system) 760 (when rejected
756 (insert (format "%s safely encodes the target text,\n" 761 (insert "These safely encodes the target text,
757 (car coding-system))
758 "\
759but it is not recommended for encoding text in this context, 762but it is not recommended for encoding text in this context,
760e.g., for sending an email message.\n") 763e.g., for sending an email message.\n ")
761 (insert "\ 764 (mapc #'(lambda (x) (princ " ") (princ x)) rejected)
762However, each of them encountered these problematic characters:\n") 765 (insert "\n"))
766 (when unsafe
767 (insert (if rejected "And the others"
768 "However, each of them")
769 " encountered these problematic characters:\n")
763 (mapc 770 (mapc
764 #'(lambda (coding) 771 #'(lambda (coding)
765 (insert (format " %s:" (car coding))) 772 (insert (format " %s:" (car coding)))
766 (dolist (elt (cdr coding)) 773 (let ((i 0)
767 (insert " ") 774 (func1
768 (if (stringp from) 775 #'(lambda (bufname pos)
769 (insert (or (cdr elt) "...")) 776 (when (buffer-live-p (get-buffer bufname))
770 (if (cdr elt) 777 (pop-to-buffer bufname)
771 (insert-text-button 778 (goto-char pos))))
772 (cdr elt) 779 (func2
773 :type 'help-xref
774 'help-echo
775 "mouse-2, RET: jump to this character"
776 'help-function
777 #'(lambda (bufname pos)
778 (when (buffer-live-p (get-buffer bufname))
779 (pop-to-buffer bufname)
780 (goto-char pos)))
781 'help-args (list bufname (car elt)))
782 (insert-text-button
783 "..."
784 :type 'help-xref
785 'help-echo
786 "mouse-2, RET: next unencodable character"
787 'help-function
788 #'(lambda (bufname pos coding) 780 #'(lambda (bufname pos coding)
789 (when (buffer-live-p (get-buffer bufname)) 781 (when (buffer-live-p (get-buffer bufname))
790 (pop-to-buffer bufname) 782 (pop-to-buffer bufname)
@@ -792,16 +784,35 @@ However, each of them encountered these problematic characters:\n")
792 (goto-char pos) 784 (goto-char pos)
793 (forward-char 1) 785 (forward-char 1)
794 (search-unencodable-char coding) 786 (search-unencodable-char coding)
795 (forward-char -1)))) 787 (forward-char -1))))))
796 'help-args (list bufname (car elt) 788 (dolist (elt (cdr coding))
797 (car coding)))))) 789 (insert " ")
790 (if (stringp from)
791 (insert (if (< i 10) (cdr elt) "..."))
792 (if (< i 10)
793 (insert-text-button
794 (cdr elt)
795 :type 'help-xref
796 'help-echo
797 "mouse-2, RET: jump to this character"
798 'help-function func1
799 'help-args (list bufname (car elt)))
800 (insert-text-button
801 "..."
802 :type 'help-xref
803 'help-echo
804 "mouse-2, RET: next unencodable character"
805 'help-function func2
806 'help-args (list bufname (car elt)
807 (car coding)))))
808 (setq i (1+ i))))
798 (insert "\n")) 809 (insert "\n"))
799 default-coding-system) 810 unsafe)
800 (insert "\ 811 (insert "\
801The first problematic character is at point in the displayed buffer,\n" 812The first problematic character is at point in the displayed buffer,\n"
802 (substitute-command-keys "\ 813 (substitute-command-keys "\
803and \\[universal-argument] \\[what-cursor-position] will give information about it.\n")))) 814and \\[universal-argument] \\[what-cursor-position] will give information about it.\n"))))
804 (insert (if (consp coding-system) 815 (insert (if safe
805 "\nSelect the above, or " 816 "\nSelect the above, or "
806 "\nSelect ") 817 "\nSelect ")
807 "\ 818 "\
@@ -814,8 +825,8 @@ one of the following safe coding systems, or edit the buffer:\n")
814 (fill-region-as-paragraph pos (point))))) 825 (fill-region-as-paragraph pos (point)))))
815 826
816 ;; Read a coding system. 827 ;; Read a coding system.
817 (if (consp coding-system) 828 (if safe
818 (setq codings (cons (car coding-system) codings))) 829 (setq codings (append safe codings)))
819 (let* ((safe-names (mapcar (lambda (x) (list (symbol-name x))) 830 (let* ((safe-names (mapcar (lambda (x) (list (symbol-name x)))
820 codings)) 831 codings))
821 (name (completing-read 832 (name (completing-read