Subject: Re: bug#77731: [PATCH] Add yank-media-handler for copied files from file manager

From: Eli Zaretskii <[email-masked]>
Date: Fri, 11 Apr 2025 14:31:06 +0300

> From: Visuwesh <[email-masked]>
> Date: Fri, 11 Apr 2025 14:58:32 +0530
> 
> [ This has been sitting in my drafts folder for many months now.  ]
> 
> Attached patch adds a yank-media-handler to message-mode to attach files
> copied/cut from a file manager.  I tested this patch using pcmanfm and
> xfe.  The regexp for the media-type was chosen after the blogpost [1],
> pcmanfm in particular sets the media-type to
> x-special/gnome-copied-files.

Thanks, but copy/paste operations on files should first and foremost
be supported in Dired, no?  Limiting such support to message-mode
seems too narrow and much less useful than it could be, let alone what
users would expect.

Can we support this in Dired?

> I strip the null byte in the split-string call in the handler because
> pcmanfm adds a null byte at the end of clipboard selection.  I don't
> know if this is the case with other file managers.
> 
> I also cannot find the spec of this clipboard type but [2] and pcmanfm
> suggests that the selection is
> 
>     OPERATION
>     file://FILE1
>     file://FILE2...
> 
> where OPERATION is either cut or copy, and the rest of the lines are
> links to the files.  I do the same as what Org does to parse the above.
> 
> 1. https://larsee.com/blog/2019/05/clipboard-files/
> 2. https://indigo.re/posts/2021-12-21-clipboard-data.html

I wonder if this is too specific to the specific file managers you
tested this with.  If it is, should we try to support more file
managers?

> +(defun message--yank-media-copied-files-handler (_ data)
> +  "Attach files copied/cut from the file manager.

The name and the doc string should be more specific to the file
managers for which this is supposed to work.  I doubt that these
details are general enough to say that any file manager capable of
copy/pasting files will behave like that.

Btw, isn't copy/paste of files similar or maybe even equivalent to
drag-n-drop?  If so, perhaps a better way would be to use the DND
machinery we have in Emacs?  Adding Po Lu in case he has opinions or
comments about this.