Subject: bug#65892: 30.0.50; yank-media fails for clipboard selection that are wiped after being accessed

From: Po Lu <[email-masked]>
Date: Fri, 28 Jun 2024 16:59:50 +0800

Visuwesh <[email-masked]> writes:

> While what you say makes perfect sense, I seldom find this to be the
> case.  But I think I worded my message too poorly.  As per the manual [1], I
> can set use text-property to set an alternate TARGET as
>
>     (gui-set-selection
>      'CLIPBOARD
>      (propertize "asd" 'x-special/gnome-copied-files
>                  "copy\nfile:///home/viz/.mkshrc\nfile:///home/viz/.profile\0"))
>
> If I do
>
>     (x-get-clipboard)
>
> I get
>
>     #("asd" 0 3 (x-special/gnome-copied-files "copy
>     file:///home/viz/.mkshrc
>     file:///home/viz/.profile\0"))
>
> (where I changed the actual NULL character to \0).  But 
>
>     (gui-get-selection 'CLIPBOARD 'x-special/gnome-copied-files) ;; => nil
>
> In fact, if I do
>
>     (gui-get-selection 'CLIPBOARD 'TARGETS)
>
> I get
>
>     [TIMESTAMP MULTIPLE TEXT COMPOUND_TEXT STRING UTF8_STRING text/plain text/plain\;charset=utf-8 TARGETS LENGTH DELETE FILE_NAME CHARACTER_POSITION LINE_NUMBER COLUMN_NUMBER OWNER_OS HOST_NAME USER CLASS NAME ATOM INTEGER SAVE_TARGETS]
>
> with the x-special/gnome-copied-files nowhere in sight.  If I evaluate
> x-get-clipboard in a fresh emacs -Q, I obviously don't see the
> text-property too.  I thought the inability of gui-get-selection to
> return the expected was because there isn't a proper function for the
> TARGET in selection-converter-alist but that should not matter since
> yank-media does handle this type fine with just a gui-get-selection
> call.  So the problem is with the inability to specify the TARGETS I
> think.  If I do
>
>     % printf '%s\0' "copy\nfile:///home/viz/.mkshrc\nfile:///home/viz/.profile" |xclip -t x-special/gnome-copied-files -selection clipboard
>
> I get
>
>     (gui-get-selection 'CLIPBOARD 'TARGETS) ;; => [TARGETS x-special/gnome-copied-files]
>
> If you replace x-special/gnome-copied-files with an image, the same
> argument holds.
>
> Perhaps I simply do not understand the manual but I cannot find how to
> set the TARGET properly.  It would be nice if the relevant info node
> could have examples of gui-set-selection that does sets the clipboard to
> have an image as the DATA, or something else.
>
> I hope this is clear.  Sorry for my late reply.
>
> 1. (info "(elisp) Window System Selections")

You misunderstand the purpose of permitting properties in selection data
strings, I think.  They are not designed to provide new data types, nor
do they in fact do so, but to enable specifying values specific to a
data type for which an existing selection converter is defined.

Undoubtedly Emacs can be extended with facilities that suit your
requirements, but the release is too close at hand for such new features
as these, I'm afraid.