* `M-x yank-media' @ 2021-11-06 21:05 Lars Ingebrigtsen 2021-11-06 23:09 ` H. Dieter Wilhelm ` (5 more replies) 0 siblings, 6 replies; 33+ messages in thread From: Lars Ingebrigtsen @ 2021-11-06 21:05 UTC (permalink / raw) To: emacs-devel [-- Attachment #1: Type: text/plain, Size: 162 bytes --] I've now finally added a framework for meaningfully yanking non-plain-text selections into Emacs. The only mode that supports it yet is message-mode, but look: [-- Attachment #2: Type: image/png, Size: 148090 bytes --] [-- Attachment #3: Type: text/plain, Size: 397 bytes --] Here I yanked an image from Chromium. The system works! 🤩 (See the manual(s) for details.) Other obvious modes is html-mode (for text/html and images) and ... image-mode? I guess? The latter could perhaps just prompt for a file name and save it (and then display it). -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-06 21:05 `M-x yank-media' Lars Ingebrigtsen @ 2021-11-06 23:09 ` H. Dieter Wilhelm 2021-11-07 3:05 ` [External] : " Drew Adams 2021-11-07 1:23 ` T.V Raman ` (4 subsequent siblings) 5 siblings, 1 reply; 33+ messages in thread From: H. Dieter Wilhelm @ 2021-11-06 23:09 UTC (permalink / raw) To: Lars Ingebrigtsen; +Cc: emacs-devel Lars Ingebrigtsen <larsi@gnus.org> writes: > I've now finally added a framework for meaningfully yanking > non-plain-text selections into Emacs. Finally fantastic, thank you very much, I waited for this! > The only mode that supports it > yet is message-mode, but look: > Here I yanked an image from Chromium. The system works! 🤩 > (See the manual(s) for details.) > Other obvious modes is html-mode (for text/html and images) and > ... image-mode? I guess? The latter could perhaps just prompt for a > file name and save it (and then display it). My hope is that it could also replace packages like org-attach-screenshot (on Melpa, for bringing images faster into an LaTeX export, for example). Dieter -- Best wishes H. Dieter Wilhelm Zwingenberg, Germany ^ permalink raw reply [flat|nested] 33+ messages in thread
* RE: [External] : Re: `M-x yank-media' 2021-11-06 23:09 ` H. Dieter Wilhelm @ 2021-11-07 3:05 ` Drew Adams 0 siblings, 0 replies; 33+ messages in thread From: Drew Adams @ 2021-11-07 3:05 UTC (permalink / raw) To: H. Dieter Wilhelm, Lars Ingebrigtsen; +Cc: emacs-devel@gnu.org > > I've now finally added a framework for meaningfully yanking > > non-plain-text selections into Emacs. > > Finally fantastic, thank you very much, I waited for this! Somewhat related (not media, but not text-yanking either): * With `highlight.el', you can copy (`M-w' on the highlight keymap) text properties from some text and yank (`C-y' on the same keymap) them onto some other text. * With Bookmark+ you can copy (`c' in the bookmark-tags keymap) and yank/paste tags from one bookmark to others - either paste-adding (`p') or paste-replacing (`q'). (You can also do those things with a mouse.) The general idea of copy/paste could no doubt be put to advantage in yet more ways in Emacs. Copy something from something and add it to, or replace, something in something else. ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-06 21:05 `M-x yank-media' Lars Ingebrigtsen 2021-11-06 23:09 ` H. Dieter Wilhelm @ 2021-11-07 1:23 ` T.V Raman 2021-11-07 10:02 ` Eli Zaretskii ` (3 subsequent siblings) 5 siblings, 0 replies; 33+ messages in thread From: T.V Raman @ 2021-11-07 1:23 UTC (permalink / raw) To: Lars Ingebrigtsen; +Cc: emacs-devel [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain; charset=gb18030, Size: 695 bytes --] Lars Ingebrigtsen <larsi@gnus.org> writes: org-mode where it turns into some kind of image link perhaps? > I've now finally added a framework for meaningfully yanking > non-plain-text selections into Emacs. The only mode that supports it > yet is message-mode, but look: > > > > > Here I yanked an image from Chromium. The system works! 0Ï5 > > (See the manual(s) for details.) > > Other obvious modes is html-mode (for text/html and images) and > ... image-mode? I guess? The latter could perhaps just prompt for a > file name and save it (and then display it). -- Thanks, --Raman(I Search, I Find, I Misplace, I Research) 7©4 Id: kg:/m/0285kf1 0Ü8 ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-06 21:05 `M-x yank-media' Lars Ingebrigtsen 2021-11-06 23:09 ` H. Dieter Wilhelm 2021-11-07 1:23 ` T.V Raman @ 2021-11-07 10:02 ` Eli Zaretskii 2021-11-07 13:12 ` Lars Ingebrigtsen 2021-11-08 3:07 ` Richard Stallman ` (2 subsequent siblings) 5 siblings, 1 reply; 33+ messages in thread From: Eli Zaretskii @ 2021-11-07 10:02 UTC (permalink / raw) To: Lars Ingebrigtsen; +Cc: emacs-devel > From: Lars Ingebrigtsen <larsi@gnus.org> > Date: Sat, 06 Nov 2021 22:05:06 +0100 > > I've now finally added a framework for meaningfully yanking > non-plain-text selections into Emacs. The only mode that supports it > yet is message-mode, but look: > > Other obvious modes is html-mode (for text/html and images) and > ... image-mode? I guess? The latter could perhaps just prompt for a > file name and save it (and then display it). Thanks. This new command doesn't seem to work for me on MS-Windows: I get this message: user-error: No handler in the current buffer for anything on the clipboard The documentation doesn't seem to hint that something non-trivial is needed for this to work. Also, should this be bound to a key? Perhaps even C-y? ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-07 10:02 ` Eli Zaretskii @ 2021-11-07 13:12 ` Lars Ingebrigtsen 2021-11-07 13:21 ` Eli Zaretskii 0 siblings, 1 reply; 33+ messages in thread From: Lars Ingebrigtsen @ 2021-11-07 13:12 UTC (permalink / raw) To: Eli Zaretskii; +Cc: emacs-devel Eli Zaretskii <eliz@gnu.org> writes: > This new command doesn't seem to work for me on MS-Windows: I get this > message: > > user-error: No handler in the current buffer for anything on the clipboard > > The documentation doesn't seem to hint that something non-trivial is > needed for this to work. I haven't tried this on Windows at all -- I have no idea what the clipboard stuff looks like over there. (Or on Macos, but I had planned on exploring that.) > Also, should this be bound to a key? Perhaps even C-y? There are so few modes that support media yanking that it's premature to put it on any key, I think. And certainly not on `C-y' -- that would break all sorts of things, I think. (People marking text in a web browser and hitting `C-y' in a html-mode buffer still expect to get just the plain text, while `yank-media' will give them more options, like text/html.) -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-07 13:12 ` Lars Ingebrigtsen @ 2021-11-07 13:21 ` Eli Zaretskii 2021-11-07 13:32 ` Lars Ingebrigtsen 0 siblings, 1 reply; 33+ messages in thread From: Eli Zaretskii @ 2021-11-07 13:21 UTC (permalink / raw) To: Lars Ingebrigtsen; +Cc: emacs-devel > From: Lars Ingebrigtsen <larsi@gnus.org> > Cc: emacs-devel@gnu.org > Date: Sun, 07 Nov 2021 14:12:54 +0100 > > Eli Zaretskii <eliz@gnu.org> writes: > > > This new command doesn't seem to work for me on MS-Windows: I get this > > message: > > > > user-error: No handler in the current buffer for anything on the clipboard > > > > The documentation doesn't seem to hint that something non-trivial is > > needed for this to work. > > I haven't tried this on Windows at all -- I have no idea what the > clipboard stuff looks like over there. (Or on Macos, but I had planned > on exploring that.) What does this require from the clipboard to work? What are the assumptions? > > Also, should this be bound to a key? Perhaps even C-y? > > There are so few modes that support media yanking that it's premature to > put it on any key, I think. And certainly not on `C-y' -- that would > break all sorts of things, I think. (People marking text in a web > browser and hitting `C-y' in a html-mode buffer still expect to get just > the plain text, while `yank-media' will give them more options, like > text/html.) AFAIK, that's what "other applications" do: they paste the content from the clipboard regardless of the type. Fine-tuned behavior, where the user can select exactly what he/she wants to past and how, is then available from a context menu. ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-07 13:21 ` Eli Zaretskii @ 2021-11-07 13:32 ` Lars Ingebrigtsen 2021-11-07 13:38 ` Po Lu ` (2 more replies) 0 siblings, 3 replies; 33+ messages in thread From: Lars Ingebrigtsen @ 2021-11-07 13:32 UTC (permalink / raw) To: Eli Zaretskii; +Cc: Alan Third, emacs-devel Eli Zaretskii <eliz@gnu.org> writes: > What does this require from the clipboard to work? What are the > assumptions? It's basically this on GNU/Linux: (gui-get-selection 'CLIPBOARD 'TARGETS) => [TIMESTAMP TARGETS MULTIPLE SAVE_TARGETS text/html text/_moz_htmlinfo text/_moz_htmlcontext image/png image/jpeg image/bmp image/x-bmp image/x-MS-bmp image/x-icon image/x-ico image/x-win-bitmap image/vnd\.microsoft\.icon application/ico image/ico image/icon text/ico image/tiff] This lists the available media types. I've just had a quick peek at what happens in Macos, and it's very different there. (gui-get-selection 'CLIPBOARD 'TARGETS) => "http" So gui-get-selection (or rather, ns-get-selection) has to grow support for this? I know absolutely nothing about the internals of the clipboard on Macos, so I've added Alan to the CCs -- perhaps he has some insights here. It basically just calls: static Lisp_Object ns_get_foreign_selection (Lisp_Object symbol, Lisp_Object target) { id pb; pb = ns_symbol_to_pb (symbol); return pb != nil ? ns_string_from_pasteboard (pb) : Qnil; } Which seems geared towards text/plain only? I haven't looked at Windows, but I'm guessing it has to grow a similar set of capabilities. > AFAIK, that's what "other applications" do: they paste the content > from the clipboard regardless of the type. Fine-tuned behavior, where > the user can select exactly what he/she wants to past and how, is then > available from a context menu. Yes, but it would just be too surprising in an Emacs context, in my opinion. Changing how something as fundamental as `C-y' works here would potentially be extremely annoying. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-07 13:32 ` Lars Ingebrigtsen @ 2021-11-07 13:38 ` Po Lu 2021-11-07 13:45 ` Lars Ingebrigtsen 2021-11-07 13:42 ` Eli Zaretskii 2021-11-23 23:42 ` Alan Third 2 siblings, 1 reply; 33+ messages in thread From: Po Lu @ 2021-11-07 13:38 UTC (permalink / raw) To: Lars Ingebrigtsen; +Cc: Eli Zaretskii, Alan Third, emacs-devel Lars Ingebrigtsen <larsi@gnus.org> writes: > I haven't looked at Windows, but I'm guessing it has to grow a similar > set of capabilities. I can't claim to understand how the clipboard works under MS-Windows, or indeed how Emacs handles the clipboard under X-Windows, but I don't think it will be easy to emulate the astoundingly overengineered, and sometimes useful, selection mechanism defined by the ICCCM. I think that when trying to put media into a selection, non-X systems tend to just put a link (such as a filename, or an inode number) to some file containing the contents of the media into the clipboard as plain text. AFAIK, though, these other systems just define something similar to cut buffers. ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-07 13:38 ` Po Lu @ 2021-11-07 13:45 ` Lars Ingebrigtsen 2021-11-08 0:56 ` Po Lu 0 siblings, 1 reply; 33+ messages in thread From: Lars Ingebrigtsen @ 2021-11-07 13:45 UTC (permalink / raw) To: Po Lu; +Cc: Eli Zaretskii, Alan Third, emacs-devel Po Lu <luangruo@yahoo.com> writes: > I think that when trying to put media into a selection, non-X systems > tend to just put a link (such as a filename, or an inode number) to > some file containing the contents of the media into the clipboard as > plain text. I see. Well, we can work with that, probably -- does the file typically contain any metadata that says what it is? (I.e., whether it's a PNG or HTML or whatever.) > AFAIK, though, these other systems just define something similar to cut > buffers. What's a cut buffer? -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-07 13:45 ` Lars Ingebrigtsen @ 2021-11-08 0:56 ` Po Lu 2021-11-08 1:10 ` Lars Ingebrigtsen 0 siblings, 1 reply; 33+ messages in thread From: Po Lu @ 2021-11-08 0:56 UTC (permalink / raw) To: Lars Ingebrigtsen; +Cc: Eli Zaretskii, Alan Third, emacs-devel Lars Ingebrigtsen <larsi@gnus.org> writes: > What's a cut buffer? The old "selection" mechanism on X-Windows. See `x-get-cut-buffer', `x-store-cut-buffer' and friends. I think these days it's only used by xterm and Emacs and nobody else. Thanks. ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-08 0:56 ` Po Lu @ 2021-11-08 1:10 ` Lars Ingebrigtsen 2021-11-08 2:12 ` Po Lu 0 siblings, 1 reply; 33+ messages in thread From: Lars Ingebrigtsen @ 2021-11-08 1:10 UTC (permalink / raw) To: Po Lu; +Cc: Eli Zaretskii, Alan Third, emacs-devel Po Lu <luangruo@yahoo.com> writes: > The old "selection" mechanism on X-Windows. See `x-get-cut-buffer', > `x-store-cut-buffer' and friends. > > I think these days it's only used by xterm and Emacs and nobody else. I see... but it looks like it was removed in 2010? If I'm grepping correctly. 2010-09-02 Jan Djärv <jan.h.d@swipnet.se> (x-selection-value): Rename from x-cut-buffer-or-selection-value. Update documentation, remove cut-buffer code. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-08 1:10 ` Lars Ingebrigtsen @ 2021-11-08 2:12 ` Po Lu 0 siblings, 0 replies; 33+ messages in thread From: Po Lu @ 2021-11-08 2:12 UTC (permalink / raw) To: Lars Ingebrigtsen; +Cc: Eli Zaretskii, Alan Third, emacs-devel Lars Ingebrigtsen <larsi@gnus.org> writes: >> The old "selection" mechanism on X-Windows. See `x-get-cut-buffer', >> `x-store-cut-buffer' and friends. >> >> I think these days it's only used by xterm and Emacs and nobody else. > I see... but it looks like it was removed in 2010? If I'm grepping > correctly. > 2010-09-02 Jan Djärv <jan.h.d@swipnet.se> > > (x-selection-value): Rename from x-cut-buffer-or-selection-value. > Update documentation, remove cut-buffer code. Hmm, that's `x-cut-buffer-or-selection-value', but it does seem to have been removed. I must've missed that. Thanks for the catch. ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-07 13:32 ` Lars Ingebrigtsen 2021-11-07 13:38 ` Po Lu @ 2021-11-07 13:42 ` Eli Zaretskii 2021-11-07 13:48 ` Lars Ingebrigtsen 2021-11-23 23:42 ` Alan Third 2 siblings, 1 reply; 33+ messages in thread From: Eli Zaretskii @ 2021-11-07 13:42 UTC (permalink / raw) To: Lars Ingebrigtsen; +Cc: alan, emacs-devel > From: Lars Ingebrigtsen <larsi@gnus.org> > Cc: emacs-devel@gnu.org, Alan Third <alan@idiocy.org> > Date: Sun, 07 Nov 2021 14:32:42 +0100 > > Eli Zaretskii <eliz@gnu.org> writes: > > > What does this require from the clipboard to work? What are the > > assumptions? > > It's basically this on GNU/Linux: > > (gui-get-selection 'CLIPBOARD 'TARGETS) > => > [TIMESTAMP TARGETS MULTIPLE SAVE_TARGETS text/html text/_moz_htmlinfo text/_moz_htmlcontext image/png image/jpeg image/bmp image/x-bmp image/x-MS-bmp image/x-icon image/x-ico image/x-win-bitmap image/vnd\.microsoft\.icon application/ico image/ico image/icon text/ico image/tiff] > > This lists the available media types. But those are just the types. How do we fetch the stuff afterwards? > I haven't looked at Windows, but I'm guessing it has to grow a similar > set of capabilities. The TARGETS thingy is already supported, has been for a long time: (gui-get-selection 'CLIPBOARD 'TARGETS) => [DataObject text/html HTML\ Format text/_moz_htmlinfo text/_moz_htmlcontext application/x-moz-file-promise-url application/x-moz-file-promise-dest-filename FILE_NAMES Preferred\ DropEffect application/x-moz-nativeimage DIB Ole\ Private\ Data BITMAP nil] (This is after "Copy Image" in Firefox.) But I suspect that's not all of the story. > > AFAIK, that's what "other applications" do: they paste the content > > from the clipboard regardless of the type. Fine-tuned behavior, where > > the user can select exactly what he/she wants to past and how, is then > > available from a context menu. > > Yes, but it would just be too surprising in an Emacs context, in my > opinion. Changing how something as fundamental as `C-y' works here > would potentially be extremely annoying. Let's see what others think. ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-07 13:42 ` Eli Zaretskii @ 2021-11-07 13:48 ` Lars Ingebrigtsen 2021-11-07 13:57 ` Eli Zaretskii 0 siblings, 1 reply; 33+ messages in thread From: Lars Ingebrigtsen @ 2021-11-07 13:48 UTC (permalink / raw) To: Eli Zaretskii; +Cc: alan, emacs-devel Eli Zaretskii <eliz@gnu.org> writes: > But those are just the types. How do we fetch the stuff afterwards? With (gui-get-selection 'CLIPBOARD 'image/png) and then some slight massaging; see yank-media--get-selection. >> I haven't looked at Windows, but I'm guessing it has to grow a similar >> set of capabilities. > > The TARGETS thingy is already supported, has been for a long time: > > (gui-get-selection 'CLIPBOARD 'TARGETS) > => > [DataObject text/html HTML\ Format text/_moz_htmlinfo text/_moz_htmlcontext application/x-moz-file-promise-url application/x-moz-file-promise-dest-filename FILE_NAMES Preferred\ DropEffect application/x-moz-nativeimage DIB Ole\ Private\ Data BITMAP nil] > > (This is after "Copy Image" in Firefox.) But I suspect that's not all > of the story. So that's why `yank-media' saying it can't find any matches, because it's looking for "image/.*" (in Message buffers). It sounds like application/x-moz-file-promise-dest-filename (or one of the other ones) might hold the file name where the image is? Does (gui-get-selection 'CLIPBOARD 'application/x-moz-file-promise-dest-filename) return anything? -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-07 13:48 ` Lars Ingebrigtsen @ 2021-11-07 13:57 ` Eli Zaretskii 2021-11-07 14:04 ` Lars Ingebrigtsen 0 siblings, 1 reply; 33+ messages in thread From: Eli Zaretskii @ 2021-11-07 13:57 UTC (permalink / raw) To: Lars Ingebrigtsen; +Cc: alan, emacs-devel > From: Lars Ingebrigtsen <larsi@gnus.org> > Cc: emacs-devel@gnu.org, alan@idiocy.org > Date: Sun, 07 Nov 2021 14:48:56 +0100 > > Eli Zaretskii <eliz@gnu.org> writes: > > > But those are just the types. How do we fetch the stuff afterwards? > > With > > (gui-get-selection 'CLIPBOARD 'image/png) > > and then some slight massaging; see yank-media--get-selection. I cannot figure out from that code what kind of "data" is expected from the above call. For example, if the data in the clipboard is an image? > > (gui-get-selection 'CLIPBOARD 'TARGETS) > > => > > [DataObject text/html HTML\ Format text/_moz_htmlinfo text/_moz_htmlcontext application/x-moz-file-promise-url application/x-moz-file-promise-dest-filename FILE_NAMES Preferred\ DropEffect application/x-moz-nativeimage DIB Ole\ Private\ Data BITMAP nil] > > > > (This is after "Copy Image" in Firefox.) But I suspect that's not all > > of the story. > > So that's why `yank-media' saying it can't find any matches, because > it's looking for "image/.*" (in Message buffers). Then that's non-portable, because this stuff is not standardized enough, AFAIK. We need more layers to hide platforms-specifics, I think. > It sounds like application/x-moz-file-promise-dest-filename (or one of > the other ones) might hold the file name where the image is? Does > > (gui-get-selection 'CLIPBOARD 'application/x-moz-file-promise-dest-filename) > > return anything? I don't expect it to, because I don't see any implementation for anything but text. ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-07 13:57 ` Eli Zaretskii @ 2021-11-07 14:04 ` Lars Ingebrigtsen 2021-11-07 14:08 ` Stefan Monnier 2021-11-07 14:09 ` Eli Zaretskii 0 siblings, 2 replies; 33+ messages in thread From: Lars Ingebrigtsen @ 2021-11-07 14:04 UTC (permalink / raw) To: Eli Zaretskii; +Cc: alan, emacs-devel Eli Zaretskii <eliz@gnu.org> writes: >> (gui-get-selection 'CLIPBOARD 'image/png) >> >> and then some slight massaging; see yank-media--get-selection. > > I cannot figure out from that code what kind of "data" is expected > from the above call. For example, if the data in the clipboard is an > image? Yes, on GNU/Linux, that call will return a string containing the image data. > Then that's non-portable, because this stuff is not standardized > enough, AFAIK. We need more layers to hide platforms-specifics, I > think. Yup. (Or rather, non-Linux systems should emulate Linux here somewhat.) -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-07 14:04 ` Lars Ingebrigtsen @ 2021-11-07 14:08 ` Stefan Monnier 2021-11-07 14:11 ` Lars Ingebrigtsen 2021-11-07 14:09 ` Eli Zaretskii 1 sibling, 1 reply; 33+ messages in thread From: Stefan Monnier @ 2021-11-07 14:08 UTC (permalink / raw) To: Lars Ingebrigtsen; +Cc: Eli Zaretskii, alan, emacs-devel > Yup. (Or rather, non-Linux systems should emulate Linux here somewhat.) FWIW, I think this has nothing to do with Linux and works the same under *BSD, for example, Stefan ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-07 14:08 ` Stefan Monnier @ 2021-11-07 14:11 ` Lars Ingebrigtsen 0 siblings, 0 replies; 33+ messages in thread From: Lars Ingebrigtsen @ 2021-11-07 14:11 UTC (permalink / raw) To: Stefan Monnier; +Cc: Eli Zaretskii, alan, emacs-devel Stefan Monnier <monnier@iro.umontreal.ca> writes: >> Yup. (Or rather, non-Linux systems should emulate Linux here somewhat.) > > FWIW, I think this has nothing to do with Linux and works the same under > *BSD, for example, Ah, right. Like Po Lu said, it's from ICCCM, i.e., an X Window system thing? -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-07 14:04 ` Lars Ingebrigtsen 2021-11-07 14:08 ` Stefan Monnier @ 2021-11-07 14:09 ` Eli Zaretskii 2021-11-07 14:13 ` Lars Ingebrigtsen 1 sibling, 1 reply; 33+ messages in thread From: Eli Zaretskii @ 2021-11-07 14:09 UTC (permalink / raw) To: Lars Ingebrigtsen; +Cc: alan, emacs-devel > From: Lars Ingebrigtsen <larsi@gnus.org> > Date: Sun, 07 Nov 2021 15:04:36 +0100 > Cc: alan@idiocy.org, emacs-devel@gnu.org > > > Then that's non-portable, because this stuff is not standardized > > enough, AFAIK. We need more layers to hide platforms-specifics, I > > think. > > Yup. (Or rather, non-Linux systems should emulate Linux here somewhat.) I don't think this could work, at least not in general. ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-07 14:09 ` Eli Zaretskii @ 2021-11-07 14:13 ` Lars Ingebrigtsen 0 siblings, 0 replies; 33+ messages in thread From: Lars Ingebrigtsen @ 2021-11-07 14:13 UTC (permalink / raw) To: Eli Zaretskii; +Cc: alan, emacs-devel Eli Zaretskii <eliz@gnu.org> writes: >> Yup. (Or rather, non-Linux systems should emulate Linux here somewhat.) > > I don't think this could work, at least not in general. I don't know -- but it seems like Windows has to put the data somewhere, right? So if application/x-moz-file-promise-dest-filename points to the file with the data, and that file is "some-temp-file.png", then gui-get-selection ... TARGETS (on Windows) could synthesise an 'image/png TARGET based on that. That's a lot of ifs, though. :-) -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-07 13:32 ` Lars Ingebrigtsen 2021-11-07 13:38 ` Po Lu 2021-11-07 13:42 ` Eli Zaretskii @ 2021-11-23 23:42 ` Alan Third 2021-11-24 7:14 ` Lars Ingebrigtsen 2 siblings, 1 reply; 33+ messages in thread From: Alan Third @ 2021-11-23 23:42 UTC (permalink / raw) To: Lars Ingebrigtsen; +Cc: Eli Zaretskii, emacs-devel [-- Attachment #1: Type: text/plain, Size: 1019 bytes --] On Sun, Nov 07, 2021 at 02:32:42PM +0100, Lars Ingebrigtsen wrote: > Eli Zaretskii <eliz@gnu.org> writes: > > > What does this require from the clipboard to work? What are the > > assumptions? > > It's basically this on GNU/Linux: > > (gui-get-selection 'CLIPBOARD 'TARGETS) > => > [TIMESTAMP TARGETS MULTIPLE SAVE_TARGETS text/html text/_moz_htmlinfo text/_moz_htmlcontext image/png image/jpeg image/bmp image/x-bmp image/x-MS-bmp image/x-icon image/x-ico image/x-win-bitmap image/vnd\.microsoft\.icon application/ico image/ico image/icon text/ico image/tiff] > > This lists the available media types. > > I've just had a quick peek at what happens in Macos, and it's very > different there. > > (gui-get-selection 'CLIPBOARD 'TARGETS) > => "http" > > So gui-get-selection (or rather, ns-get-selection) has to grow support > for this? I think the attached should sort this. It doesn't seem to do much on GNUstep, I suspect GNUstep itself doesn't support copying of much more than plain text. -- Alan Third [-- Attachment #2: 0001-Enable-yank-media-on-NS.patch --] [-- Type: text/x-diff, Size: 4125 bytes --] From 2606ecbed8df134370aed4c40215cf6928cb3215 Mon Sep 17 00:00:00 2001 From: Alan Third <alan@idiocy.org> Date: Tue, 23 Nov 2021 20:56:44 +0000 Subject: [PATCH] Enable yank-media on NS * src/nsselect.m (ns_get_foreign_selection): Handle non-plain text clipboard entries. (ns_string_from_pasteboard): Remove EOL conversion. (syms_of_nsselect): Define QTARGETS. --- src/nsselect.m | 80 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 3 deletions(-) diff --git a/src/nsselect.m b/src/nsselect.m index 5ab3ef77fe..e999835014 100644 --- a/src/nsselect.m +++ b/src/nsselect.m @@ -215,9 +215,74 @@ Updated by Christian Limpach (chris@nice.ch) static Lisp_Object ns_get_foreign_selection (Lisp_Object symbol, Lisp_Object target) { + NSDictionary<NSString *, NSString *> *typeLookup; id pb; pb = ns_symbol_to_pb (symbol); - return pb != nil ? ns_string_from_pasteboard (pb) : Qnil; + + /* Dictionary for looking up NS types from MIME types, and vice versa. */ + typeLookup + = [NSDictionary + dictionaryWithObjectsAndKeys: + @"text/plain", NSPasteboardTypeURL, +#if NS_USE_NSPasteboardTypeFileURL + @"text/plain", NSPasteboardTypeFileURL, +#else + @"text/plain", NSFilenamesPboardType, +#endif + @"text/html", NSPasteboardTypeHTML, + @"text/plain", NSPasteboardTypeMultipleTextSelection, + @"application/pdf", NSPasteboardTypePDF, + @"image/png", NSPasteboardTypePNG, + @"application/rtf", NSPasteboardTypeRTF, + @"application/rtfd", NSPasteboardTypeRTFD, + @"STRING", NSPasteboardTypeString, + @"text/plain", NSPasteboardTypeTabularText, + @"image/tiff", NSPasteboardTypeTIFF, + nil]; + + if (EQ (target, QTARGETS)) + { + NSMutableArray *types = [NSMutableArray arrayWithCapacity:3]; + + NSString *type; + NSEnumerator *e = [[pb types] objectEnumerator]; + while (type = [e nextObject]) + { + NSString *val = [typeLookup valueForKey:type]; + if (val && ! [types containsObject:val]) + [types addObject:val]; + } + + Lisp_Object v = Fmake_vector (make_fixnum ([types count]+1), Qnil); + ASET (v, 0, QTARGETS); + + for (int i = 0 ; i < [types count] ; i++) + ASET (v, i+1, intern ([[types objectAtIndex:i] UTF8String])); + + return v; + } + else + { + NSData *d; + NSArray *availableTypes; + NSString *result, *t; + + if (!NILP (target)) + availableTypes + = [typeLookup allKeysForObject: + [NSString stringWithLispString:SYMBOL_NAME (target)]]; + else + availableTypes = @[NSPasteboardTypeString]; + + t = [pb availableTypeFromArray:availableTypes]; + + result = [pb stringForType:t]; + if (result) + return [result lispString]; + + d = [pb dataForType:t]; + return make_string ([d bytes], [d length]); + } } @@ -234,8 +299,6 @@ Updated by Christian Limpach (chris@nice.ch) ns_string_from_pasteboard (id pb) { NSString *type, *str; - const char *utfStr; - int length; type = [pb availableTypeFromArray: ns_return_types]; if (type == nil) @@ -260,6 +323,14 @@ Updated by Christian Limpach (chris@nice.ch) } } + /* FIXME: Is the below EOL conversion even needed? I've removed it + for now so we can see if it causes problems. */ + return [str lispString]; + +#if 0 + const char *utfStr; + int length; + /* assume UTF8 */ NS_DURING { @@ -294,6 +365,7 @@ Updated by Christian Limpach (chris@nice.ch) NS_ENDHANDLER return make_string (utfStr, length); +#endif } @@ -491,6 +563,8 @@ Updated by Christian Limpach (chris@nice.ch) DEFSYM (QTEXT, "TEXT"); DEFSYM (QFILE_NAME, "FILE_NAME"); + DEFSYM (QTARGETS, "TARGETS"); + defsubr (&Sns_disown_selection_internal); defsubr (&Sns_get_selection); defsubr (&Sns_own_selection_internal); -- 2.33.0 ^ permalink raw reply related [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-23 23:42 ` Alan Third @ 2021-11-24 7:14 ` Lars Ingebrigtsen 2021-11-24 10:59 ` Alan Third 0 siblings, 1 reply; 33+ messages in thread From: Lars Ingebrigtsen @ 2021-11-24 7:14 UTC (permalink / raw) To: Alan Third; +Cc: Eli Zaretskii, emacs-devel Alan Third <alan@idiocy.org> writes: >> (gui-get-selection 'CLIPBOARD 'TARGETS) >> => "http" >> >> So gui-get-selection (or rather, ns-get-selection) has to grow support >> for this? > > I think the attached should sort this. Great! Please go ahead and push to Emacs 29, and I'll do some testing on Macos, too. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-24 7:14 ` Lars Ingebrigtsen @ 2021-11-24 10:59 ` Alan Third 2021-11-24 16:45 ` Lars Ingebrigtsen 0 siblings, 1 reply; 33+ messages in thread From: Alan Third @ 2021-11-24 10:59 UTC (permalink / raw) To: Lars Ingebrigtsen; +Cc: Eli Zaretskii, emacs-devel On Wed, Nov 24, 2021 at 08:14:36AM +0100, Lars Ingebrigtsen wrote: > Alan Third <alan@idiocy.org> writes: > > >> (gui-get-selection 'CLIPBOARD 'TARGETS) > >> => "http" > >> > >> So gui-get-selection (or rather, ns-get-selection) has to grow support > >> for this? > > > > I think the attached should sort this. > > Great! Please go ahead and push to Emacs 29, and I'll do some testing > on Macos, too. Done. Let me know if it's not doing the right thing, I'm not confident I understood how this is supposed to work. -- Alan Third ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-24 10:59 ` Alan Third @ 2021-11-24 16:45 ` Lars Ingebrigtsen 2021-11-25 0:53 ` Po Lu 0 siblings, 1 reply; 33+ messages in thread From: Lars Ingebrigtsen @ 2021-11-24 16:45 UTC (permalink / raw) To: Alan Third; +Cc: Eli Zaretskii, emacs-devel Alan Third <alan@idiocy.org> writes: > Done. Let me know if it's not doing the right thing, I'm not confident > I understood how this is supposed to work. I've now tried it on my Apple laptop, and it seems to work perfectly. 🤗 (I tried yanking images from Firefox and Safari into a Message buffer.) Now we only need support on the Windows side, and we'll have coverage from the three major platforms. Hm... that reminds me -- I haven't tested this on Wayland. My guess is that it won't work there, but that's an uninformed guess. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-24 16:45 ` Lars Ingebrigtsen @ 2021-11-25 0:53 ` Po Lu 2021-11-25 13:37 ` Lars Ingebrigtsen 0 siblings, 1 reply; 33+ messages in thread From: Po Lu @ 2021-11-25 0:53 UTC (permalink / raw) To: Lars Ingebrigtsen; +Cc: Alan Third, Eli Zaretskii, emacs-devel Lars Ingebrigtsen <larsi@gnus.org> writes: > Hm... that reminds me -- I haven't tested this on Wayland. My guess is > that it won't work there, but that's an uninformed guess. It should work fine, if Emacs runs in Xwayland. ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-25 0:53 ` Po Lu @ 2021-11-25 13:37 ` Lars Ingebrigtsen 0 siblings, 0 replies; 33+ messages in thread From: Lars Ingebrigtsen @ 2021-11-25 13:37 UTC (permalink / raw) To: Po Lu; +Cc: Alan Third, Eli Zaretskii, emacs-devel Po Lu <luangruo@yahoo.com> writes: >> Hm... that reminds me -- I haven't tested this on Wayland. My guess is >> that it won't work there, but that's an uninformed guess. > > It should work fine, if Emacs runs in Xwayland. But is that what happens normally? (It's been so long since I last messed around with Wayland; I should set up a laptop to use it to experiment with...) -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-06 21:05 `M-x yank-media' Lars Ingebrigtsen ` (2 preceding siblings ...) 2021-11-07 10:02 ` Eli Zaretskii @ 2021-11-08 3:07 ` Richard Stallman 2021-11-08 4:55 ` Lars Ingebrigtsen 2021-11-08 5:09 ` Lars Ingebrigtsen 2021-11-08 16:56 ` Uwe Brauer 5 siblings, 1 reply; 33+ messages in thread From: Richard Stallman @ 2021-11-08 3:07 UTC (permalink / raw) To: Lars Ingebrigtsen; +Cc: emacs-devel [[[ To any NSA and FBI agents reading my email: please consider ]]] [[[ whether defending the US Constitution against all enemies, ]]] [[[ foreign or domestic, requires you to follow Snowden's example. ]]] > I've now finally added a framework for meaningfully yanking > non-plain-text selections into Emacs. It sounds exciting -- could you say a little more about how it behaves? -- Dr Richard Stallman (https://stallman.org) Chief GNUisance of the GNU Project (https://gnu.org) Founder, Free Software Foundation (https://fsf.org) Internet Hall-of-Famer (https://internethalloffame.org) ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-08 3:07 ` Richard Stallman @ 2021-11-08 4:55 ` Lars Ingebrigtsen 0 siblings, 0 replies; 33+ messages in thread From: Lars Ingebrigtsen @ 2021-11-08 4:55 UTC (permalink / raw) To: Richard Stallman; +Cc: emacs-devel Richard Stallman <rms@gnu.org> writes: > It sounds exciting -- could you say a little more about how > it behaves? From the manual: @node Yanking Media @section Yanking Media If you choose, for instance, ``Copy Image'' in a web browser, that image is put onto the clipboard, and Emacs can access it via @code{gui-get-selection}. But in general, inserting image data into an arbitrary buffer isn't very useful---you can't really do much with it by default. So Emacs has a system to let modes register handlers for these ``complicated'' selections. @defun yank-media-handler types handler @var{types} can be a @acronym{MIME} media type symbol, a regexp to match these, or a list of these symbols and regexps. For instance: @example (yank-media-handler 'text/html #'my-html-handler) (yank-media-handler "image/.*" #'my-image-handler) @end example A mode can register as many handlers as required. The @var{handler} function is called with two parameters: The @acronym{MIME} media type symbol and the data (as a string). The handler should then insert the object into the buffer, or save it, or do whatever is appropriate for the mode. @end defun The @code{yank-media} command will consult the registered handlers in the current buffer, compare that with the available media types on the clipboard, and then pass on the matching selection to the handler (if any). If there's more than one matching selection, the user is queried first. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-06 21:05 `M-x yank-media' Lars Ingebrigtsen ` (3 preceding siblings ...) 2021-11-08 3:07 ` Richard Stallman @ 2021-11-08 5:09 ` Lars Ingebrigtsen 2021-11-08 14:29 ` Eli Zaretskii 2021-11-08 16:56 ` Uwe Brauer 5 siblings, 1 reply; 33+ messages in thread From: Lars Ingebrigtsen @ 2021-11-08 5:09 UTC (permalink / raw) To: emacs-devel I've now also added a `yank-media-types' command -- mostly for debugging. It lets people who are thinking about writing handlers explore what's actually on the clipboard (Firefox, for instance, puts a surprising amount of useful stuff there). -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-08 5:09 ` Lars Ingebrigtsen @ 2021-11-08 14:29 ` Eli Zaretskii 2021-11-09 3:39 ` Lars Ingebrigtsen 0 siblings, 1 reply; 33+ messages in thread From: Eli Zaretskii @ 2021-11-08 14:29 UTC (permalink / raw) To: Lars Ingebrigtsen; +Cc: emacs-devel > From: Lars Ingebrigtsen <larsi@gnus.org> > Date: Mon, 08 Nov 2021 06:09:38 +0100 > > I've now also added a `yank-media-types' command -- mostly for > debugging. It lets people who are thinking about writing handlers > explore what's actually on the clipboard (Firefox, for instance, puts a > surprising amount of useful stuff there). This command seems to assume that only the data types which have support in gui-get-selection are useful. But that is not necessarily true for a command that was meant to allow snooping and tinkering. For example, after copying text from Firefox on MS-Windows, I have: (gui-get-selection 'CLIPBOARD 'TARGETS) => [DataObject text/html HTML\ Format text/_moz_htmlcontext text/_moz_htmlinfo UTF8_STRING STRING text/x-moz-url-priv Ole\ Private\ Data OEM_STRING] But "M-x yank-media-types RET" followed by "?" shows just this: Possible completions are: clipboard:STRING If this command is supposed to be for exploring the selections, then perhaps it should produce a table of all the types, and some meta-data for every supported type? ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-08 14:29 ` Eli Zaretskii @ 2021-11-09 3:39 ` Lars Ingebrigtsen 0 siblings, 0 replies; 33+ messages in thread From: Lars Ingebrigtsen @ 2021-11-09 3:39 UTC (permalink / raw) To: Eli Zaretskii; +Cc: emacs-devel Eli Zaretskii <eliz@gnu.org> writes: > This command seems to assume that only the data types which have > support in gui-get-selection are useful. But that is not necessarily > true for a command that was meant to allow snooping and tinkering. > > For example, after copying text from Firefox on MS-Windows, I have: > > (gui-get-selection 'CLIPBOARD 'TARGETS) > => [DataObject text/html HTML\ Format text/_moz_htmlcontext text/_moz_htmlinfo UTF8_STRING STRING text/x-moz-url-priv Ole\ Private\ Data OEM_STRING] > > But "M-x yank-media-types RET" followed by "?" shows just this: > > Possible completions are: > clipboard:STRING Yeah, it filters out the types where `gui-get-selection' doesn't return anything, because those types aren't useful for people who want to add handlers to the modes. But I could make (for instance) the prefix not do any filtering and show everything. OK, added now. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: `M-x yank-media' 2021-11-06 21:05 `M-x yank-media' Lars Ingebrigtsen ` (4 preceding siblings ...) 2021-11-08 5:09 ` Lars Ingebrigtsen @ 2021-11-08 16:56 ` Uwe Brauer 5 siblings, 0 replies; 33+ messages in thread From: Uwe Brauer @ 2021-11-08 16:56 UTC (permalink / raw) To: emacs-devel [-- Attachment #1: Type: text/plain, Size: 339 bytes --] >>> "LI" == Lars Ingebrigtsen <larsi@gnus.org> writes: > I've now finally added a framework for meaningfully yanking > non-plain-text selections into Emacs. The only mode that supports it > yet is message-mode, but look: Very nice indeed. Candidates were such a feature would be very wellcome. 1. LaTeX (AuCTex) 2. Org mode [-- Attachment #2: smime.p7s --] [-- Type: application/pkcs7-signature, Size: 5673 bytes --] ^ permalink raw reply [flat|nested] 33+ messages in thread
end of thread, other threads:[~2021-11-25 13:37 UTC | newest] Thread overview: 33+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2021-11-06 21:05 `M-x yank-media' Lars Ingebrigtsen 2021-11-06 23:09 ` H. Dieter Wilhelm 2021-11-07 3:05 ` [External] : " Drew Adams 2021-11-07 1:23 ` T.V Raman 2021-11-07 10:02 ` Eli Zaretskii 2021-11-07 13:12 ` Lars Ingebrigtsen 2021-11-07 13:21 ` Eli Zaretskii 2021-11-07 13:32 ` Lars Ingebrigtsen 2021-11-07 13:38 ` Po Lu 2021-11-07 13:45 ` Lars Ingebrigtsen 2021-11-08 0:56 ` Po Lu 2021-11-08 1:10 ` Lars Ingebrigtsen 2021-11-08 2:12 ` Po Lu 2021-11-07 13:42 ` Eli Zaretskii 2021-11-07 13:48 ` Lars Ingebrigtsen 2021-11-07 13:57 ` Eli Zaretskii 2021-11-07 14:04 ` Lars Ingebrigtsen 2021-11-07 14:08 ` Stefan Monnier 2021-11-07 14:11 ` Lars Ingebrigtsen 2021-11-07 14:09 ` Eli Zaretskii 2021-11-07 14:13 ` Lars Ingebrigtsen 2021-11-23 23:42 ` Alan Third 2021-11-24 7:14 ` Lars Ingebrigtsen 2021-11-24 10:59 ` Alan Third 2021-11-24 16:45 ` Lars Ingebrigtsen 2021-11-25 0:53 ` Po Lu 2021-11-25 13:37 ` Lars Ingebrigtsen 2021-11-08 3:07 ` Richard Stallman 2021-11-08 4:55 ` Lars Ingebrigtsen 2021-11-08 5:09 ` Lars Ingebrigtsen 2021-11-08 14:29 ` Eli Zaretskii 2021-11-09 3:39 ` Lars Ingebrigtsen 2021-11-08 16:56 ` Uwe Brauer
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).