In the previous episode of this blog, I mused about how Emacs should perhaps handle non-text yanking (i.e., HTML and images).
I didn’t really want to write a mode to examine the clipboard and the selections, but I did anyway just now, and I discovered something kinda interesting.
Well I never!
Anyway, this is basically what the mode looks like:
It just lists all the types of selection that exist under the primary/secondary selections, as well as the clipboard. In this instance, I’ve done a “Copy image” in Firefox. So I can inspect the text/html “version” the image…
Which turns out to be the <img;> bit, logically enough.
And the image/png is the image itself, even more logically enough.
But here’s the slightly interesting bit: If you mark some text in Firefox (i.e., put the text into the primary selection in nerd speak), you get these selection types:
And the TEXT bit is as you’d expect…
But what’s that text/x-moz-url-priv?
It’s the URL of the page you marked the text on! This can obviously be used for UX purposes, like providing a function that’d simultaneously quote something and do the link at the same time. Like this:
So something like:
(when-let ((url (x-get-selection-internal 'PRIMARY 'text/x-moz-url-priv))) (insert (format "On <a href="%S">somebody</a> wrote:\n\n" (ewp-decode-text-selection url)))) (insert "<blockquote>\n") (insert (substring-no-properties (current-kill 0))) (insert "</blockquote>\n\n")
You can find this stuff on Microsoft Github.
Chrome isn’t as helpful as Firefox here, you just get a very minimal selection list when marking some text there:
(Oh, yeah, I added a command to do screenshots directly from the ewp composition buffer. Otherwise this blog would have taken me HOURS and HOURS to make.)
Of course, how useful this stuff is outside of a writing-for-the-web context is debatable…
PERSON A: It’s not useful!
PERSON B: Oh, OK.
Well, that was a short debate!