emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 58a3c54: Avoid using string-make-unibyte in select.


From: Eli Zaretskii
Subject: [Emacs-diffs] master 58a3c54: Avoid using string-make-unibyte in select.el
Date: Sat, 22 Jun 2019 04:35:25 -0400 (EDT)

branch: master
commit 58a3c54c7ea86ea6b715483e7b017008a78fbf14
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    Avoid using string-make-unibyte in select.el
    
    * lisp/select.el (selection-coding-system): Doc fix.
    (xselect--encode-string): For C_STRING, if the text is not
    already unibyte, use encode-coding-string instead of
    string-make-multibyte to make it unibyte.
---
 lisp/select.el | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/lisp/select.el b/lisp/select.el
index af6bf46..935ad10 100644
--- a/lisp/select.el
+++ b/lisp/select.el
@@ -49,16 +49,17 @@ the current system default encoding on 9x/Me, `utf-16le-dos'
 
 For X Windows:
 When sending text via selection and clipboard, if the target
-data-type matches with the type of this coding system, it is used
-for encoding the text.  Otherwise (including the case that this
-variable is nil), a proper coding system is used as below:
+data-type matches this coding system according to the table
+below, it is used for encoding the text.  Otherwise (including
+the case that this variable is nil), a proper coding system is
+selected as below:
 
 data-type      coding system
 ---------      -------------
 UTF8_STRING    utf-8
 COMPOUND_TEXT  compound-text-with-extensions
 STRING         iso-latin-1
-C_STRING       no-conversion
+C_STRING       raw-text-unix
 
 When receiving text, if this coding system is non-nil, it is used
 for decoding regardless of the data-type.  If this is nil, a
@@ -476,10 +477,15 @@ two markers or an overlay.  Otherwise, it is nil."
            (setq str (encode-coding-string str coding)))
 
           ((eq type 'C_STRING)
-            ;; If STR is unibyte (the normal case), use it; otherwise
-            ;; we assume some of the characters are eight-bit, and
-            ;; take their lower 8 bits.
-           (setq str (string-make-unibyte str)))
+            ;; According to ICCCM Protocol v2.0 (para 2.7.1), C_STRING
+            ;; is a zero-terminated sequence of raw bytes that
+            ;; shouldn't be interpreted as text in any encoding.
+            ;; Therefore, if STR is unibyte (the normal case), we use
+            ;; it as-is; otherwise we assume some of the characters
+            ;; are eight-bit and ensure they are converted to their
+            ;; single-byte representation.
+            (or (null (multibyte-string-p str))
+                (setq str (encode-coding-string 'raw-text-unix str))))
 
           (t
            (error "Unknown selection type: %S" type)))))



reply via email to

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