From 3dae236eb252452fff7faea0611e4f1798759e08 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Mon, 8 Nov 2021 01:15:02 +0100 Subject: [PATCH] Fix charset issues in text/html yanking * 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 | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lisp/yank-media.el b/lisp/yank-media.el index 66eb23430ec..6d0d0b1a181 100644 --- a/lisp/yank-media.el +++ b/lisp/yank-media.el @@ -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) -- 2.39.2