>>>> "Heiko" == Heiko Muenkel
<muenkel(a)tnt.uni-hannover.de> writes:
Heiko> I know it's not the real fix for this problem, but it works
Heiko> for me.
Except that it should trash all your EURO SIGNs, no? (If not, you may
be winning because of a default to ISO 8859-15 in your language
environment. Try under LANG=C xemacs -vanilla. If you still get
correct EURO SIGNs, I'll be very surprised.)
Heiko> PPS: It works in the GNU Emacs too.
? I thought GNU Emacs had installed a fix to be compatible with the
XFree86 breakage. Unfortunately, I doubt the improved fix below
(which is easily generalizable to KOI8, VISCII, ISCII, and Unicode in
such segments) works in GNU Emacs. The basic string manipulation
should work (so you might prefer to add it to your library, so you can
use it in both Emacsen), but I rather doubt that GNU Emacs provides
the same hooks.
Heiko> Feel free, to put it in your distribution, if no one has
Heiko> fixed the real problem in the next XEmacs version.
Could you try this? Works for me in light testing in 21.5.12 (but no
EURO SIGN, just the umlaute characters from your mail). If it works
for you too, I'll clean it up and add it to the latin-unity package
(with a proper installer/uninstaller, of course).
------------------------------------------------------------------------
(require 'latin-unity-latin9) ; I doubt you need this, can't hurt
(defconst sjt/extended-segment-parser-re
(concat "\033%/" ; extended segment escape
"[0-4]" ; if we grok it, we should know width
"\\([\200-\377][\200-\377]\\)" ; length specification, base 128
"\\([^\002]*\\)" ; TODO: should match only Latin 1
"\002") ; ASCII STX = START OF TEXT
"Regexp to detect and parse X Compound Text extended segment parameters.")
(defconst sjt/coding-system-x11-aliases
"Coding system aliases used in X Compound Text extended segments.
NB: we sanity check all uses of this mapping, so even if the particular
XEmacs doesn't know that coding system, please report as a bug if you see
a broken paste of the form \"^[%/1\200\227iso8859-15\002...\"."
;; TODO: add to this list.
'(("iso8859-15" . iso-8859-15)))
(defun sjt/find-coding-system-from-alias (name)
(setq name (downcase name))
(cond ((find-coding-system (intern name)))
((let ((pair (assoc name sjt/coding-system-x11-aliases)))
(when pair (find-coding-system (cdr pair)))))
;; we could try guessing here, eg a prefix "iso" -> "iso-"
(t nil)))
(defun sjt/select-convert-from-text (selection type value)
"Converts a text selection to a Lisp string, handling X11 extended segments."
(when (stringp value)
(catch 'unconvertible
(while (string-match sjt/extended-segment-parser-re value)
(let* ((cs (find-coding-system (sjt/find-coding-system-from-alias
(match-string 2 value))))
(segstart (match-end 0))
(lenspec (match-string 1 value))
(length (+ (* 128 (- (char-to-int (aref lenspec 0)) 128))
(- (char-to-int (aref lenspec 1))
128
(length (match-string 2))
1)))
(segend (+ segstart length)))
(unless cs (throw 'unconvertible nil))
(setq value (concat (substring value 0 (match-beginning 0))
(decode-coding-string
(substring value segstart segend)
cs)
;; should eliminate while in favor of
;; tail-recursion on this substring
(substring value segend))))))
value))
(defun sjt/toggle-compound-text-converter ()
"Toggle the recognition and conversion of compound text extended segments."
(interactive)
(when (emacs-version>= 21 4)
(let ((cvt (cond ((eq (cdr (assoc 'TEXT selection-converter-in-alist))
'select-convert-from-text)
'sjt/select-convert-from-text)
(t 'select-convert-from-text)))
(alist selection-converter-in-alist))
;; no mercy!!
(while alist
(when (memq (cdar alist)
'(select-convert-from-text sjt/select-convert-from-text))
(setcdr (car alist) cvt))
(setq alist (cdr alist)))
(message "%s" cvt))))
;; OK, do it!
(sjt/toggle-compound-text-converter)
------------------------------------------------------------------------
--
Institute of Policy and Planning Sciences
http://turnbull.sk.tsukuba.ac.jp
University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN
Ask not how you can "do" free software business;
ask what your business can "do for" free software.