summaryrefslogtreecommitdiff
path: root/lisp/select.el
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2021-11-11 05:22:02 +0100
committerLars Ingebrigtsen <larsi@gnus.org>2021-11-11 05:22:02 +0100
commit396355f46b964d6a63ced9fe48fb6c7fb43d8f06 (patch)
tree30b8f3afb1eb42b7eb20a1df0ec8a2defa3e503f /lisp/select.el
parent42037d8948f0209a88c64949adf5016229e4beec (diff)
downloademacs-396355f46b964d6a63ced9fe48fb6c7fb43d8f06.tar.gz
Re-fix charset issues when yanking non-plain-text elements
* lisp/select.el (gui-get-selection): Make (gui-get-selection 'CLIPBOARD 'text/html) get decoded correctly (bug#31149), but still avoid the logic on Windows.
Diffstat (limited to 'lisp/select.el')
-rw-r--r--lisp/select.el24
1 files changed, 17 insertions, 7 deletions
diff --git a/lisp/select.el b/lisp/select.el
index 3c9f961f6db..43424d94b39 100644
--- a/lisp/select.el
+++ b/lisp/select.el
@@ -304,22 +304,32 @@ the formats available in the clipboard if TYPE is `CLIPBOARD'."
(let ((data (gui-backend-get-selection (or type 'PRIMARY)
(or data-type 'STRING))))
(when (and (stringp data)
- (setq data-type (get-text-property 0 'foreign-selection data)))
+ ;; If this text property is set, then the data needs to
+ ;; be decoded -- otherwise it has already been decoded
+ ;; by the lower level functions.
+ (get-text-property 0 'foreign-selection data))
(let ((coding (or next-selection-coding-system
selection-coding-system
(pcase data-type
('UTF8_STRING 'utf-8)
('COMPOUND_TEXT 'compound-text-with-extensions)
('C_STRING nil)
- ('STRING 'iso-8859-1)
- (_ (error "Unknown selection data type: %S"
- type))))))
- (setq data (if coding (decode-coding-string data coding)
- ;; This is for C_STRING case.
+ ('STRING 'iso-8859-1)))))
+ (setq data
+ (cond (coding (decode-coding-string data coding))
;; We want to convert each non-ASCII byte to the
;; corresponding eight-bit character, which has
;; a codepoint >= #x3FFF00.
- (string-to-multibyte data))))
+ ((eq data-type 'C_STRING)
+ (string-to-multibyte data))
+ ;; Guess at the charset for types like text/html
+ ;; -- it can be anything, and different
+ ;; applications use different encodings.
+ ((string-match-p "\\`text/" (symbol-name data-type))
+ (decode-coding-string
+ data (car (detect-coding-string data))))
+ ;; Do nothing.
+ (t data))))
(setq next-selection-coding-system nil)
(put-text-property 0 (length data) 'foreign-selection data-type data))
data))