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

From: Visuwesh <[email-masked]>
Date: Fri, 28 Jun 2024 09:50:33 +0530

[செவ்வாய் ஜூன் 25, 2024] Eli Zaretskii wrote:

>> From: Visuwesh <[email-masked]>
>> Cc: Eli Zaretskii <[email-masked]>,  [email-masked]
>> Date: Tue, 25 Jun 2024 10:06:35 +0530
>> 
>> BTW, I would be happy if I can do the above copying/cutting files from
>> _dired_ without resorting to xclip(1) to set non-STRING targets.  I
>> tried to do it with the facilities offered by Emacs but failed to set
>> _only_ the required target without other things like STRING.  The same
>> happened when I tried to copy an image to the clipboard.  I would be
>> happy to open a bug report or some such if you're interested.
>
> Isn't this the expected behavior?  The application that sets the
> clipboard data has no idea what the consumer might need or would want
> to do with the data.  It could past the image, or it could take the
> image's meta-data (STRING) and do something with it.  Or it could take
> the image's file name and copy the file somewhere.  Or something else.
> This is why it is customary to put all the relevant data types in the
> clipboard, so that the consumers could take whatever they need.

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")