Mercurial > emacs
comparison lisp/gnus/mm-util.el @ 90070:95879cc1ed20
Revision: miles@gnu.org--gnu-2004/emacs--unicode--0--patch-81
Merge from emacs--cvs-trunk--0
Patches applied:
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-748
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-749
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-750
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-751
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-753
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-754
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-755
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-757
Update from CVS
* miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-78
Merge from emacs--cvs-trunk--0
* miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-79
- miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-80
Update from CVS
* miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-81
Merge from emacs--cvs-trunk--0
* miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-82
Update from CVS
author | Miles Bader <miles@gnu.org> |
---|---|
date | Sun, 02 Jan 2005 09:13:19 +0000 |
parents | e24e2e78deda 22da0004ae3c |
children | a01e7a9f1659 |
comparison
equal
deleted
inserted
replaced
90069:fa0a5c4db2c8 | 90070:95879cc1ed20 |
---|---|
523 (if (setq b (mm-coding-system-p b)) | 523 (if (setq b (mm-coding-system-p b)) |
524 (> (length (memq (coding-system-base a) priorities)) | 524 (> (length (memq (coding-system-base a) priorities)) |
525 (length (memq (coding-system-base b) priorities))) | 525 (length (memq (coding-system-base b) priorities))) |
526 t)))) | 526 t)))) |
527 | 527 |
528 (defun mm-find-mime-charset-region (b e) | 528 (eval-when-compile |
529 (autoload 'latin-unity-massage-name "latin-unity") | |
530 (autoload 'latin-unity-maybe-remap "latin-unity") | |
531 (autoload 'latin-unity-representations-feasible-region "latin-unity") | |
532 (autoload 'latin-unity-representations-present-region "latin-unity") | |
533 (defvar latin-unity-coding-systems) | |
534 (defvar latin-unity-ucs-list)) | |
535 | |
536 (defun mm-xemacs-find-mime-charset-1 (begin end) | |
537 "Determine which MIME charset to use to send region as message. | |
538 This uses the XEmacs-specific latin-unity package to better handle the | |
539 case where identical characters from diverse ISO-8859-? character sets | |
540 can be encoded using a single one of the corresponding coding systems. | |
541 | |
542 It treats `mm-coding-system-priorities' as the list of preferred | |
543 coding systems; a useful example setting for this list in Western | |
544 Europe would be '(iso-8859-1 iso-8859-15 utf-8), which would default | |
545 to the very standard Latin 1 coding system, and only move to coding | |
546 systems that are less supported as is necessary to encode the | |
547 characters that exist in the buffer. | |
548 | |
549 Latin Unity doesn't know about those non-ASCII Roman characters that | |
550 are available in various East Asian character sets. As such, its | |
551 behavior if you have a JIS 0212 LATIN SMALL LETTER A WITH ACUTE in a | |
552 buffer and it can otherwise be encoded as Latin 1, won't be ideal. | |
553 But this is very much a corner case, so don't worry about it." | |
554 (let ((systems mm-coding-system-priorities) csets psets curset) | |
555 | |
556 ;; Load the Latin Unity library, if available. | |
557 (when (and (not (featurep 'latin-unity)) (locate-library "latin-unity")) | |
558 (require 'latin-unity)) | |
559 | |
560 ;; Now, can we use it? | |
561 (if (featurep 'latin-unity) | |
562 (progn | |
563 (setq csets (latin-unity-representations-feasible-region begin end) | |
564 psets (latin-unity-representations-present-region begin end)) | |
565 | |
566 (catch 'done | |
567 | |
568 ;; Pass back the first coding system in the preferred list | |
569 ;; that can encode the whole region. | |
570 (dolist (curset systems) | |
571 (setq curset (latin-unity-massage-name 'buffer-default curset)) | |
572 | |
573 ;; If the coding system is a universal coding system, then | |
574 ;; it can certainly encode all the characters in the region. | |
575 (if (memq curset latin-unity-ucs-list) | |
576 (throw 'done (list curset))) | |
577 | |
578 ;; If a coding system isn't universal, and isn't in | |
579 ;; the list that latin unity knows about, we can't | |
580 ;; decide whether to use it here. Leave that until later | |
581 ;; in `mm-find-mime-charset-region' function, whence we | |
582 ;; have been called. | |
583 (unless (memq curset latin-unity-coding-systems) | |
584 (throw 'done nil)) | |
585 | |
586 ;; Right, we know about this coding system, and it may | |
587 ;; conceivably be able to encode all the characters in | |
588 ;; the region. | |
589 (if (latin-unity-maybe-remap begin end curset csets psets t) | |
590 (throw 'done (list curset)))) | |
591 | |
592 ;; Can't encode using anything from the | |
593 ;; `mm-coding-system-priorities' list. | |
594 ;; Leave `mm-find-mime-charset' to do most of the work. | |
595 nil)) | |
596 | |
597 ;; Right, latin unity isn't available; let `mm-find-charset-region' | |
598 ;; take its default action, which equally applies to GNU Emacs. | |
599 nil))) | |
600 | |
601 (defmacro mm-xemacs-find-mime-charset (begin end) | |
602 (when (featurep 'xemacs) | |
603 `(mm-xemacs-find-mime-charset-1 ,begin ,end))) | |
604 | |
605 (defun mm-find-mime-charset-region (b e &optional hack-charsets) | |
529 "Return the MIME charsets needed to encode the region between B and E. | 606 "Return the MIME charsets needed to encode the region between B and E. |
530 nil means ASCII, a single-element list represents an appropriate MIME | 607 nil means ASCII, a single-element list represents an appropriate MIME |
531 charset, and a longer list means no appropriate charset." | 608 charset, and a longer list means no appropriate charset." |
532 (let (charsets) | 609 (let (charsets) |
533 ;; The return possibilities of this function are a mess... | 610 ;; The return possibilities of this function are a mess... |
564 ;; `utf-16...'.) | 641 ;; `utf-16...'.) |
565 (not (string-match "utf-16" (symbol-name cs)))) | 642 (not (string-match "utf-16" (symbol-name cs)))) |
566 (setq systems nil | 643 (setq systems nil |
567 charsets (list cs)))))) | 644 charsets (list cs)))))) |
568 charsets)) | 645 charsets)) |
646 ;; If we're XEmacs, and some coding system is appropriate, | |
647 ;; mm-xemacs-find-mime-charset will return an appropriate list. | |
648 ;; Otherwise, we'll get nil, and the next setq will get invoked. | |
649 (setq charsets (mm-xemacs-find-mime-charset b e)) | |
650 | |
569 ;; Fixme: won't work for unibyte Emacs 22: | 651 ;; Fixme: won't work for unibyte Emacs 22: |
570 | 652 |
571 ;; Otherwise we're not multibyte, we're XEmacs, or a single | 653 ;; We're not multibyte, or a single coding system won't cover it. |
572 ;; coding system won't cover it. | |
573 (setq charsets | 654 (setq charsets |
574 (mm-delete-duplicates | 655 (mm-delete-duplicates |
575 (mapcar 'mm-mime-charset | 656 (mapcar 'mm-mime-charset |
576 (delq 'ascii | 657 (delq 'ascii |
577 (mm-find-charset-region b e)))))) | 658 (mm-find-charset-region b e)))))) |