bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Pasting under X11 (Xfree86-4.2) broken


From: Eli Zaretskii
Subject: Re: Pasting under X11 (Xfree86-4.2) broken
Date: Wed, 13 Feb 2002 12:27:36 +0200 (IST)

On Wed, 13 Feb 2002, Florian Hars wrote:

> If I paste something which I have selected with the mouse in some
> other (XFree-4.2)-window, emacs2[01] produce totally garbled text:
> 
> %/1=80=8eiso8859-15=81=e4=81=f6=81=fc 
> %/1=80=8eiso8859-15=81=c4=81=d6=81=dc
> 
> What is the point in explicitly marking latin-9 characters in a
> latin-9 environment as latin-9 when it is evident that they can only
> be latin-9?

Your interpretation of the problem is mistaken: it's not Emacs marking 
the characters, it's how the characters are already marked in the X 
selection.  iso8859-15 is not one of the standard ICCCM character sets, 
so XFree uses an extension mechanism to put such characters into X 
selections.  Unfortunately, Emacs does not yet support these extensions, 
so you see the leading sequence verbatim.

I'm working on adding this support.  I include below a patch I wrote just 
yesterday, which should solve this in most cases.  It is not yet tested 
extensively, but please try it and tell me if it works for you.

After applying the patch, byte-compile mule-conf.el, say "make install" 
in the Emacs source tree's top directory, and then use the new coding 
system ctext-with-extensions (e.g., via C-x RET x, or permanently in 
your .emacs) to paste X selections.

> Every other program (at least XEmacs ans all GTK-based
> programs) gets this right.

I'm guessing you were using a non-mule version of XEmacs, since XEmacs 
doesn't support this encoding either.

Here's the patch I promised:

*** lisp/international/mule-conf.e~0    Fri Mar  9 02:27:36 2001
--- lisp/international/mule-conf.el     Tue Feb 12 15:46:50 2002
***************
*** 405,411 ****
--- 405,493 ----
  (define-coding-system-alias 'x-ctext 'compound-text)
  (define-coding-system-alias 'ctext 'compound-text)
  
+ (defvar non-standard-icccm-encodings-alist
+   '(("ISO8859-15" . latin-iso8859-15)
+     ("ISO8859-14" . latin-iso8859-14)
+     ("KOI8-R" . koi8-r)
+     ("BIG5-0" . chinese-big5-1))
+   "Alist of font charset names defined by XLFD, and the corresponding charset
+ or coding system.")
+ 
+ ;; Functions to support "Non-Standard Character Set Encodings" defined
+ ;; by the ICCCM spec.  We support that by converting the leading
+ ;; sequence of the ``extended segment'' to the corresponding ISO-2022
+ ;; sequences, or vice versa.
+ (defun ctext-post-read-conversion (len)
+   "Decode LEN characters encoded as Compound Text with Extended Segments."
+   (let ((pt (point-marker))
+       (opt (point-marker))
+       (npt (make-marker))
+       (modified-p (buffer-modified-p))
+       last-coding-system-used
+       encoding textlen chset)
+     (narrow-to-region (point) (+ (point) len))
+     (buffer-disable-undo)
+     (while (re-search-forward
+           "\\(\e\\)%/[0-4]\\([\200-\377][\200-\377]\\)\\([^\002]+\\)\002"
+           nil 'move)
+       (set-marker npt (point))
+       (set-marker pt (match-beginning 0))
+       (setq encoding (match-string 3))
+       (setq textlen (- (+ (* (- (aref (match-string 2) 0) 128) 128)
+                         (- (aref (match-string 2) 1) 128))
+                      (1+ (length encoding))))
+       (setq chset (cdr (assoc-ignore-case encoding
+                                         non-standard-icccm-encodings-alist)))
+       (cond ((null chset))
+           ((charsetp chset)
+            ;; If it's a charset, replace the leading escape sequence
+            ;; with a standard ISO-2022 sequence.  We will decode all
+            ;; such segments later, in one go, when we exit the loop
+            ;; or find an extended segment that names a coding
+            ;; system, not a charset.
+            (replace-match
+             (concat "\\1"
+                     (if (= 0 (charset-iso-graphic-plane chset))
+                         ;; GL charsets
+                         (if (= 1 (charset-dimension chset)) "(" "$(")
+                       ;; GR charsets
+                       (if (= 96 (charset-chars chset))
+                           "-"
+                         (if (= 1 (charset-dimension chset)) ")" "$)")))
+                     (string (charset-iso-final-char chset)))
+             t)
+            (goto-char (+ (point) textlen)))
+           ((coding-system-p chset)
+            ;; If it's a coding system, we need to decode the segment
+            ;; right away.  But first, decode what we've skipped
+            ;; across until now.
+            (when (> pt opt)
+              (decode-coding-region opt pt 'compound-text))
+            (delete-region pt npt)
+            (set-marker npt (+ npt textlen))
+            (decode-coding-region pt npt chset)
+            (goto-char npt)
+            (set-marker opt npt))))
+     ;; Decode what's left.
+     (when (> (point) opt)
+       (decode-coding-region opt (point) 'compound-text))
+     (set-buffer-multibyte t)
+     (set-buffer-modified-p modified-p)
+     (- (point-max) (point-min))))
+ 
+ (defun ctext-pre-write-conversion (from to)
+   "Encode characters between FROM and TO as Compound Text w/Extended 
Segments."
+   (encode-coding-region from to 'compound-text)       ; FIXME!
+   nil)
+ 
  (make-coding-system
+  'ctext-with-extensions 5 ?x
+  "Compound text encoding with Extended Segment extensions."
+  nil
+  '((post-read-conversion . ctext-post-read-conversion)
+    (pre-write-conversion . ctext-pre-write-conversion)))
+ 
+ (make-coding-system
   'iso-safe 2 ?-
   "Convert all characters but ASCII to `?'."
   '(ascii nil nil nil




reply via email to

[Prev in Thread] Current Thread [Next in Thread]