From 0022b02d1688d46a650f0492fe0a12a0bccd28eb Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Mon, 8 Nov 2021 05:54:10 +0100 Subject: [PATCH] Clean up the yank-media data massaging * lisp/yank-media.el (yank-media--get-selection): Put the nul-massaging code... (yank-media-types--format): ... here instead, and decode utf-16 better. --- lisp/yank-media.el | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lisp/yank-media.el b/lisp/yank-media.el index aa7d8abfd48..bc57e96612c 100644 --- a/lisp/yank-media.el +++ b/lisp/yank-media.el @@ -82,15 +82,10 @@ all the different selection types." (defun yank-media--get-selection (type) (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))) + (when-let ((data (gui-get-selection 'CLIPBOARD type))) + (if (string-match-p "\\`text/" (symbol-name type)) + (yank-media-types--format type data) + data)))) ;;;###autoload (defun yank-media-handler (types handler) @@ -180,7 +175,11 @@ inserts images as images." 'utf-16-le)))))) (if coding-system (decode-coding-string data coding-system) - data))) + ;; Some programs add a nul character at the end of text/* + ;; selections. Remove that. + (if (zerop (elt data (1- (length data)))) + (substring data 0 (1- (length data))) + data)))) (t data))) -- 2.39.2