Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

register yank-media-handler so we can paste images #804

Closed
unhammer opened this issue Oct 19, 2023 · 7 comments
Closed

register yank-media-handler so we can paste images #804

unhammer opened this issue Oct 19, 2023 · 7 comments

Comments

@unhammer
Copy link

Expected Behavior

When an image is in the clipboard, yanking/pasting should create a file with the image in the same dir (perhaps customizable) and add a markdown image link.

See https://yhetil.org/orgmode/87jzsintv0.fsf@gmail.com/ for examples of yank-media handlers (this issue prompted by https://old.reddit.com/r/emacs/comments/17alspd/intelligent_paste_in_emacs/k5fnuta/ )

Actual Behavior

It pastes the latest text instead (and messages Selection owner couldn’t convert: text/plain;charset=utf-8)

Steps to Reproduce

  1. Copy some image contents to clipboard
  2. M-x markdown-mode in emacs
  3. C-y

Software Versions

  • Markdown Mode: 2.4-dev
  • Emacs: 29.1
  • OS: Ubuntu 22.04.3 LTS
@syohex
Copy link
Collaborator

syohex commented Oct 25, 2023

How about #807 ?

@unhammer
Copy link
Author

Nice! I can now M-x yank-media in a markdown-buffer and it does the right thing :-)

If I drag from thunar into emacs, it still just opens the file – I believe this requires (setq-local dnd-protocol-alist (cons '("^file:///" . markdown--dnd-local-file-handler-which-is-not-yet-implemented) dnd-protocol-alist)) as in https://yhetil.org/orgmode/87jzsintv0.fsf@gmail.com/ ?

If I use yank instead of yank-media with an image in clipboard contents I still get the "Selection owner couldn't convert" – is this something that should work, or is plain yank always expected to only yank text and never images?

@syohex
Copy link
Collaborator

syohex commented Oct 25, 2023

I'll look into dnd later.

If I use yank instead of yank-media with an image in clipboard contents I still get the "Selection owner couldn't convert" – is this something that should work, or is plain yank always expected to only yank text and never images?

I'm not sure yet, but I suppose yank always yanks text.

@syohex
Copy link
Collaborator

syohex commented Oct 27, 2023

I've also implemented the dnd feature

@syohex syohex closed this as completed Oct 28, 2023
@the42
Copy link

the42 commented Oct 30, 2023

Is this meant to work cross-plattform or exclusively for Gnome? I am using Emacs 29.1. on Windows and when an image is on the clipboard and I call yank-media in a markdown-buffer I get the following message:

yank-media: No handler in the current buffer for anything on the clipboard

@syohex
Copy link
Collaborator

syohex commented Oct 30, 2023

Emacs has not supported images in clipboard on Windows yet.So this feature works only on Desktop Linux and macOS.

https://www.gnu.org/software/emacs/manual/html_node/elisp/Window-System-Selections.html

When Emacs runs on MS-Windows, it does not implement X selections in general, but it does support the clipboard. gui-get-selection and gui-set-selection on MS-Windows support the text data type only; if the clipboard holds other types of data, Emacs treats the clipboard as empty. The supported data type is STRING.

@9viz
Copy link

9viz commented Nov 4, 2023

You might also want to support the XDS protocol so that you can e.g., directly drag an image shown in firefox and drop it onto Emacs frame without needing to save it first somewhere, etc. Po Lu's initial message in the linked thread should be of help (and the later patches of course).

I neglected to do this in the org-mode patch but you definitely want to call decode-coding-string on the string returned by url-unhex-string in the copied files yank-media handler.

If I use yank instead of yank-media with an image in clipboard contents I still get the "Selection owner couldn't convert" – is this something that should work, or is plain yank always expected to only yank text and never images?

See the subthread https://yhetil.org/emacs-devel/837ddk9tc8.fsf@gnu.org/ and the conclusion therein.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants