[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Pasting under X11 (Xfree86-4.2) broken
Re: Pasting under X11 (Xfree86-4.2) broken
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 produce totally garbled text:
> 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))
+ encoding textlen chset)
+ (narrow-to-region (point) (+ (point) len))
+ (while (re-search-forward
+ 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
+ (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.
+ (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)))
+ (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
+ (encode-coding-region from to 'compound-text) ; FIXME!
+ 'ctext-with-extensions 5 ?x
+ "Compound text encoding with Extended Segment extensions."
+ '((post-read-conversion . ctext-post-read-conversion)
+ (pre-write-conversion . ctext-pre-write-conversion)))
'iso-safe 2 ?-
"Convert all characters but ASCII to `?'."
'(ascii nil nil nil