Gnus development mailing list
 help / color / mirror / Atom feed
From: Aidan Kehoe <kehoea@parhasard.net>
Cc: ding@gnus.org
Subject: Re: XEmacs, Gnus and mm-coding-system priorities.
Date: Tue, 07 Dec 2004 00:10:28 +0000	[thread overview]
Message-ID: <16820.62708.663703.64580.z25zdq@parhasard.net> (raw)
In-Reply-To: <b9yeki45fb4.fsf@jpl.org>

[-- Attachment #1: Type: text/plain, Size: 1602 bytes --]


Hi! again, 

 Ar an séiú lá de mí na Nollaig, scríobh Katsumi Yamaoka: 

 > [...] I tried your patch with the old mm-util.el and confirmed it works.
 > However, it doesn't work with non-Latin characters:
 > 
 > (let ((mm-coding-system-priorities '(shift_jis)))
 >   (rfc2047-encode-string (string (make-char 'japanese-jisx0208 38 66))))

I was wrong, I can work around this. Since latin-unity knows the list of
coding systems it can map into, we can check each entry in
mm-coding-system-priorities for validity before trying to remap with it. So,
for example, if shift_jis is in mm-coding-system-priorities, the latin unity
code should just give up, and mm-find-mime-charset falls back to the code
you had written.

I~ve a revised patch and test set (including your tests from the last mail)
attached that addresses this. I~m also going to post this to gnu.emacs.gnus
because ding@gnus evidently doesn~t like me :-) .

In terms of usability, I~m starting to feel strongly that
mm-coding-systems-priorities should be initialised to '(iso-8859-1
iso-8859-15 iso-8859-2 iso-8859-16 utf-8) for non-East-Asian
locales. Americans don~t care, but for non-English speaking Europeans the
Mule breakage just another reason not to use an Emacs. 

Best regards, 

        - Aidan
-- 
~As democracy is perfected, the office of president represents, more and
more closely, the inner soul of the people. On some great and glorious day
the plain folks of the land will reach their heart~s desire at last and the
White House will be adorned by a downright moron.~ ~ H.L. Mencken 


[-- Attachment #2: Further revision of mm-util.el to behave better under XEmacs. --]
[-- Type: text/x-patch, Size: 4116 bytes --]

--- mm-util.el.orig	2004-12-06 23:20:17.000000000 +0000
+++ mm-util.el	2004-12-06 23:54:27.000000000 +0000
@@ -584,6 +584,73 @@
 		(length (memq (coding-system-base b) priorities)))
 	   t))))
 
+(defun mm-xemacs-find-mime-charset (begin end)
+  "Determine which MIME charset to use to send region as message.
+This uses the XEmacs-specific latin-unity package to better handle the case
+where identical characters from diverse ISO-8859-? character sets can be
+encoded using a single one of the corresponding coding systems. 
+
+It treats `mm-coding-system-priorities' as the list of preferred coding
+systems; a useful example setting for this list in Western Europe would be
+'(iso-8859-1 iso-8859-15 utf-8), which would default to the very standard
+Latin 1 coding system, and only move to coding systems that are less
+supported as is necessary to encode the characters that exist in the buffer.
+
+Latin Unity doesn't know about those non-ASCII Roman characters that are
+available in various East Asian character sets.  As such, its behavior if
+you have a JIS 0212 LATIN SMALL LETTER A WITH ACUTE in a buffer and it can
+otherwise be encoded as Latin 1, won't be ideal.  But this is very much a
+corner case, so don't worry about it.  "
+  (let ((systems mm-coding-system-priorities) csets psets curset chars-region)
+
+    ;; Load the Latin Unity library, if available.
+    (when (and (not (featurep 'latin-unity)) (locate-library "latin-unity"))
+      (require 'latin-unity))
+
+    ;; Now, can we use it?
+    (if (featurep 'latin-unity)
+	(progn 
+	  (assert (featurep 'xemacs) 
+		  (concat "We only expect latin-unity on XEmacs--this code "
+			  "will break on the FSF's Emacs.  "))
+	  (setq csets (latin-unity-representations-feasible-region begin end)
+		psets (latin-unity-representations-present-region begin end)
+		chars-region (delq 'ascii (charsets-in-region begin end)))
+
+	  (catch 'done
+
+	    ;; Pass back the first coding system in the preferred list that
+	    ;; can encode the whole region.
+	    (dolist (curset systems)
+	      (setq curset (latin-unity-massage-name curset 'buffer-default))
+
+	      ;; If the coding system is a universal coding system, then it
+	      ;; can certainly encode all the characters in the region. 
+	      (if (memq curset latin-unity-ucs-list)
+		  (throw 'done (list curset)))
+
+	      ;; If a coding system isn't universal, and isn't in the list
+	      ;; that latin unity knows about, we can't decide whether to
+	      ;; use it here. Leave that until later in mm-find-mime-charset
+	      ;; region function, whence we have been called.
+	      (unless (memq curset latin-unity-coding-systems)
+		(throw 'done nil))
+
+	      ;; Right, we know about this coding system, and it may
+	      ;; conceivably be able to encode all the characters in the
+	      ;; region.
+	      (if (latin-unity-maybe-remap begin end curset csets psets t)
+		  (throw 'done (list curset))))
+
+	    ;; Can't encode using anything from the
+	    ;; mm-coding-system-priorities list. Leave mm-find-mime-charset
+	    ;; to do most of the work.
+	    nil))
+
+      ;; Right, latin unity isn't available; let mm-find-charset-region 
+      ;; take its default action, which equally applies to GNU Emacs. 
+      nil)))
+
 (defun mm-find-mime-charset-region (b e &optional hack-charsets)
   "Return the MIME charsets needed to encode the region between B and E.
 nil means ASCII, a single-element list represents an appropriate MIME
@@ -625,8 +692,12 @@
 			 (setq systems nil
 			       charsets (list cs))))))
 	       charsets))
-	;; Otherwise we're not multibyte, we're XEmacs, or a single
-	;; coding system won't cover it.
+        ;; If we're XEmacs, and some coding system is appropriate,
+        ;; mm-xemacs-find-mime-charset will return an appropriate list.
+        ;; Otherwise, we'll get nil, and the next setq will get invoked.
+        (setq charsets (mm-xemacs-find-mime-charset b e))
+
+        ;; We're not multibyte, or a single coding system won't cover it.
 	(setq charsets
 	      (mm-delete-duplicates
 	       (mapcar 'mm-mime-charset

[-- Attachment #3: Test Lisp for the mm-util.el revision. --]
[-- Type: application/emacs-lisp, Size: 3397 bytes --]

  parent reply	other threads:[~2004-12-07  0:10 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-03 16:55 Aidan Kehoe
2004-12-06  2:30 ` Katsumi Yamaoka
2004-12-06 13:35   ` Aidan Kehoe
2004-12-06 15:19   ` Katsumi Yamaoka
2004-12-06 22:30   ` Katsumi Yamaoka
2004-12-07  1:03     ` Katsumi Yamaoka
2004-12-07  0:10   ` Aidan Kehoe [this message]
2004-12-07  1:04     ` Katsumi Yamaoka
2004-12-07 12:32       ` Katsumi Yamaoka
2004-12-17 12:21         ` Aidan Kehoe
2004-12-17 12:46           ` Katsumi Yamaoka
2004-12-17 16:09             ` Katsumi Yamaoka
2004-12-31  9:01         ` XEmacs hangs in rfc2047-encode-string (Was: XEmacs, Gnus and mm-coding-system priorities.) Steinar Bang
2004-12-31 11:47           ` XEmacs hangs in rfc2047-encode-string Reiner Steib
2004-12-31 14:41             ` Steinar Bang
2004-12-31 19:10               ` Andrey Slusar
2005-01-01  9:04                 ` Steinar Bang
2005-01-01 18:03                   ` Andrey Slusar
2005-01-01 19:25                     ` Steinar Bang
2005-01-01 22:05                       ` Andrey Slusar
2005-01-02  7:49                         ` Steinar Bang
2004-12-31 12:53           ` Steinar Bang
2004-12-31 13:42           ` Arnaud Giersch
2004-12-31 14:45             ` Steinar Bang
2004-12-07  1:03 ` XEmacs, Gnus and mm-coding-system priorities Katsumi Yamaoka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=16820.62708.663703.64580.z25zdq@parhasard.net \
    --to=kehoea@parhasard.net \
    --cc=ding@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).