To reproduce the bug, 1. Install pcmanfm 2. emacs -Q 3. Eval the following lines (defun vz/message-yank-media-copied-files-handler (_ data) "Attach files copied/cut from the file manager. DATA is a string where the first line is the operation to perform: copy or cut. Rest are file: links. The operation is always ignored, and the files are only attached." (let* ((files (cdr (split-string data "[\0\n\r]" t "^file://")))) (dolist (f files) (mml-attach-file f (or (mm-default-file-type f) "application/octet-stream"))))) (add-hook 'message-mode-hook (defun vz/message-register-yank-media-handler () (yank-media-handler "x-special/gnome-copied-files" #'vz/message-yank-media-copied-files-handler))) 4. C-x m 5. Cut a file from pcmanfm using C-x 6. In Emacs, choose the message-mode buffer and say M-x yank-media 7. Witness the wrong-type-argument error This happens because pcmanfm "wipes" the clipboard data it is accessed once. This is a problem because yank-media uses yank-media--get-selection to access the clipboard data twice · Once in yank-media--find-matching-media to find out if the buffer's registered handlers can work with the data (see pcase-dolist form in yank-media function). At this point, vz/message-register-yank-media-handler is chosen since it can handle x-special/gnome-copied-files (which is the type used for the cut file). · Second when yank-media calls the handler to do its thing, which can be seen in the funcall forms in yank-media function again. The problem here is that once yank-media--find-matching-media calls yank-media--get-selection to get the clipboard selection, pcmanfm wipes the clipboard so when yank-media calls that function again and passes the return value to the handler, the handler receives nil. The attached patch fixes this issue by making yank-media--find-matching-media return the selection value, and passing the returned value to the handler avoiding calling yank-media--get-selection again. P.S. I don't know if it is a problem with other file managers. P.P.S. I plan on submitting a patch to add the yank-media-handler here once this bug is fixed.