From: Lars Ingebrigtsen Date: Mon, 8 Nov 2021 04:54:10 +0000 (+0100) Subject: Clean up the yank-media data massaging X-Git-Tag: emacs-29.0.90~3671^2~82 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=0022b02d1688d46a650f0492fe0a12a0bccd28eb;p=emacs.git 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. --- 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)))