aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2019-06-22 11:34:23 +0300
committerEli Zaretskii2019-06-22 11:34:23 +0300
commit58a3c54c7ea86ea6b715483e7b017008a78fbf14 (patch)
tree003d8e6d5ff0d57aa5bb3959887e15dcbf6ea22e
parent27d28d43d12999cf04d823ec9e08228d1b862a49 (diff)
downloademacs-58a3c54c7ea86ea6b715483e7b017008a78fbf14.tar.gz
emacs-58a3c54c7ea86ea6b715483e7b017008a78fbf14.zip
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.
-rw-r--r--lisp/select.el22
1 files changed, 14 insertions, 8 deletions
diff --git a/lisp/select.el b/lisp/select.el
index af6bf467e4a..935ad10cbf3 100644
--- a/lisp/select.el
+++ b/lisp/select.el
@@ -49,16 +49,17 @@ the current system default encoding on 9x/Me, `utf-16le-dos'
49 49
50For X Windows: 50For X Windows:
51When sending text via selection and clipboard, if the target 51When sending text via selection and clipboard, if the target
52data-type matches with the type of this coding system, it is used 52data-type matches this coding system according to the table
53for encoding the text. Otherwise (including the case that this 53below, it is used for encoding the text. Otherwise (including
54variable is nil), a proper coding system is used as below: 54the case that this variable is nil), a proper coding system is
55selected as below:
55 56
56data-type coding system 57data-type coding system
57--------- ------------- 58--------- -------------
58UTF8_STRING utf-8 59UTF8_STRING utf-8
59COMPOUND_TEXT compound-text-with-extensions 60COMPOUND_TEXT compound-text-with-extensions
60STRING iso-latin-1 61STRING iso-latin-1
61C_STRING no-conversion 62C_STRING raw-text-unix
62 63
63When receiving text, if this coding system is non-nil, it is used 64When receiving text, if this coding system is non-nil, it is used
64for decoding regardless of the data-type. If this is nil, a 65for decoding regardless of the data-type. If this is nil, a
@@ -476,10 +477,15 @@ two markers or an overlay. Otherwise, it is nil."
476 (setq str (encode-coding-string str coding))) 477 (setq str (encode-coding-string str coding)))
477 478
478 ((eq type 'C_STRING) 479 ((eq type 'C_STRING)
479 ;; If STR is unibyte (the normal case), use it; otherwise 480 ;; According to ICCCM Protocol v2.0 (para 2.7.1), C_STRING
480 ;; we assume some of the characters are eight-bit, and 481 ;; is a zero-terminated sequence of raw bytes that
481 ;; take their lower 8 bits. 482 ;; shouldn't be interpreted as text in any encoding.
482 (setq str (string-make-unibyte str))) 483 ;; Therefore, if STR is unibyte (the normal case), we use
484 ;; it as-is; otherwise we assume some of the characters
485 ;; are eight-bit and ensure they are converted to their
486 ;; single-byte representation.
487 (or (null (multibyte-string-p str))
488 (setq str (encode-coding-string 'raw-text-unix str))))
483 489
484 (t 490 (t
485 (error "Unknown selection type: %S" type))))) 491 (error "Unknown selection type: %S" type)))))