]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix charset issues in text/html yanking
authorLars Ingebrigtsen <larsi@gnus.org>
Mon, 8 Nov 2021 00:15:02 +0000 (01:15 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Mon, 8 Nov 2021 00:15:06 +0000 (01:15 +0100)
* lisp/yank-media.el (yank-media--get-selection): Use
gui-backend-get-selection instead of the higher-level function
which guesses wrong on the charset on many types.
(yank-media): Fix the case where there's only one match.

lisp/yank-media.el

index 66eb23430ec6d1286073bc85fa2d65c0f3e15e4d..6d0d0b1a18119e9b231a8e2bfd405cea79032370 100644 (file)
@@ -48,7 +48,7 @@ the `register-yank-media-handler' mechanism."
     ;; We have a handler in the current buffer; if there's just
     ;; matching type, just call the handler.
     (if (length= all-types 1)
-        (funcall (cdar all-types)
+        (funcall (cdar all-types) (caar all-types)
                  (yank-media--get-selection (caar all-types)))
       ;; More than one type the user for what type to insert.
       (let ((type
@@ -77,15 +77,16 @@ the `register-yank-media-handler' mechanism."
    (gui-get-selection 'CLIPBOARD 'TARGETS)))
 
 (defun yank-media--get-selection (type)
-  (when-let ((data (gui-get-selection 'CLIPBOARD type)))
-    (when-let ((charset (get-text-property 0 'charset data)))
-      (setq data (encode-coding-string data charset)))
-    ;; Some programs add a nul character at the end of text/*
-    ;; selections.  Remove that.
-    (when (and (string-match-p "\\`text/" (symbol-name type))
-               (zerop (elt data (1- (length data)))))
-      (setq data (substring data 0 (1- (length data)))))
-    data))
+  (let ((selection-coding-system 'binary))
+    (when-let ((data (gui-backend-get-selection 'CLIPBOARD type)))
+      (when (string-match-p "\\`text/" (symbol-name type))
+        ;; Some programs add a nul character at the end of text/*
+        ;; selections.  Remove that.
+        (when (zerop (elt data (1- (length data))))
+          (setq data (substring data 0 (1- (length data)))))
+        (setq data (decode-coding-string
+                    data (car (detect-coding-string data)))))
+      data)))
 
 ;;;###autoload
 (defun register-yank-media-handler (types handler)