Subject: bug#71377: 30.0.50; command `yank-meida` raise error (wrong-type-argument sequencep TARGETS)

From: Robert Pluim <[email-masked]>
Date: Wed, 05 Jun 2024 17:03:48 +0200

>>>>> On Wed, 05 Jun 2024 17:30:30 +0800, "Christopher M. Miles" <[email-masked]> said:

    Christopher> ------------------------------------------------------------------------
    Christopher> When I execute command `yank-media` in Org-mode buffer to paste the
    Christopher> copied image from web browser.

    Christopher> I meet the bellowing error (I got it through `toggle-debug-on-error`):

    Christopher> #+begin_example
    Christopher> Debugger entered--Lisp error: (wrong-type-argument sequencep TARGETS)
    Christopher>   mapc(#f(compiled-function (elt) #<bytecode 0x1a7575f8530bcbb9>) TARGETS)
    Christopher>   seq-do(#f(compiled-function (elt) #<bytecode 0x1a7575f8530bcbb9>) TARGETS)
    Christopher>   #f(compiled-function #'sequence #<bytecode 0x16733c95d11ee092>)(#f(compiled-function (elt) #<bytecode 0x1b8299eb0aa0c2e9>) TARGETS)
    Christopher>   apply(#f(compiled-function #'sequence #<bytecode 0x16733c95d11ee092>) #f(compiled-function (elt) #<bytecode 0x1b8299eb0aa0c2e9>) TARGETS nil)
    Christopher>   seq-map(#f(compiled-function (elt) #<bytecode 0x1b8299eb0aa0c2e9>) TARGETS)
    Christopher>   seq-filter(#f(compiled-function (type) #<bytecode 0xaadcd526d212301>) TARGETS)
    Christopher>   yank-media--find-matching-media("x/special-\\(?:gnome|KDE|mate\\)-files")
    Christopher>   #f(compiled-function () (interactive nil) #<bytecode 0x91d13bd79da85fd>)()
    Christopher>   apply(#f(compiled-function () (interactive nil) #<bytecode 0x91d13bd79da85fd>) nil)
    Christopher>   yank-media()
    Christopher>   funcall-interactively(yank-media)
    Christopher>   call-interactively(yank-media nil nil)
    Christopher>   command-execute(yank-media)
    Christopher> #+end_example

    Christopher> For a test, I copy an image in Arc web browser:
    Christopher> source image URL: https://img1.doubanio.com/view/photo/raw/public/p2895245009.jpg

    Christopher> My environment:
    Christopher> - GNU Emacs 30.0.50 (build 2, aarch64-apple-darwin23.4.0, NS appkit-2487.50 Version 14.4.1 (Build 23E224))
    Christopher>  of 2024-05-14
    Christopher> - Org mode: 9.7-pre
    Christopher> - macOS: appkit-2487.50 Version 14.4.1 (Build 23E224)

On macOS, if there is a selection active, then it is returned, even
when `yank-media' is actually querying to see which media types are
supported. The following fixes it for me, but I donʼt know a great
deal about the selection code on macOS.

diff --git a/src/nsselect.m b/src/nsselect.m
index bb6679cd2ab..f5cef42eacc 100644
--- a/src/nsselect.m
+++ b/src/nsselect.m
@@ -205,6 +205,9 @@ Updated by Christian Limpach ([email-masked])
                         Lisp_Object target_type)
 {
   Lisp_Object local_value;
+  if (EQ (selection_name, QCLIPBOARD)
+      && EQ (target_type, QTARGETS))
+    return Qnil;
   local_value = assq_no_quit (selection_name, Vselection_alist);
   return local_value;
 }

Robert
--