emacs-diffs
[Top][All Lists]
Advanced

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

master 0022b02: Clean up the yank-media data massaging


From: Lars Ingebrigtsen
Subject: master 0022b02: Clean up the yank-media data massaging
Date: Sun, 7 Nov 2021 23:54:17 -0500 (EST)

branch: master
commit 0022b02d1688d46a650f0492fe0a12a0bccd28eb
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    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 aa7d8ab..bc57e96 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)))
 



reply via email to

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