emacs-diffs
[Top][All Lists]
Advanced

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

master 5e66c75: Fix charset issues when yanking non-plain-text elements


From: Lars Ingebrigtsen
Subject: master 5e66c75: Fix charset issues when yanking non-plain-text elements
Date: Sun, 7 Nov 2021 20:04:56 -0500 (EST)

branch: master
commit 5e66c75e0b6b91b6f5d9aa46c824e8209ade8f2a
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    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).
---
 lisp/select.el | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/lisp/select.el b/lisp/select.el
index 3c9f961..8412405 100644
--- a/lisp/select.el
+++ b/lisp/select.el
@@ -303,23 +303,29 @@ addition to `STRING'; MS-Windows supports `TARGETS', 
which reports
 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)))
+    (when (stringp 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))



reply via email to

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