* * * * *
                                        
                     Why didn't I get a copy of this memo?
                                        
> X11 has these things called “selections.” They have names. There are really
> only two you need to know about: the **Primary** selection and the
> **Clipboard** selection. An application is said to “own” a selection when
> it raises its hand and says, “I have the Primary selection now.” Only one
> application can own a selection at a time, so when one app asserts
> selection ownership, the previous owner loses it.
> 
> …
> 
> One of the really cool, yet rarely used, features of the selection
> mechanism is that it can negotiate what data formats to use. It's not just
> about text. When one application asks another for the selection, part of
> their communication involves the requester asking the owner for the list of
> types in which they are capable of delivering the selection data; then the
> requester picks the format they like best, and asks for it that way.
> 

“X Selections, X Cut Buffers, and Emacs Kill Rings [1]”

I've been struggling with writing blog entries for years [2], and yet, here I
am, one day short of nine years [3] still writing posts the old fashioned way
painfully [4] (that link shows the steps I go through in quoting a page for
this blog, and as you can see, it's several manual steps).

But on an unrelated project to this blog (and work) I had to dive into the
inner workings of the X11 clipboard. In doing so, I came across Jamie
Zawinski's [5] page on X Selections, X Cut Buffers, and Emacs Kill Rings [6],
which pretty much describes at a high level how the whole X11 clipboard thing
works, but there was this bit about half-way down the page:

> The content negotiation mechansim is very powerful, and I wish more
> applications would take advantage of it.
> 
> You can experiment with content negotiation with other apps from an XEmacs
> lisp-interaction buffer. To see what types an app will convert its
> selection to, make a selection in that app, and then type:
> 
> -----[ EMACS ]-----
> (get-selection-internal 'PRIMARY 'TARGETS)
> ==> [TARGETS TIMESTAMP TEXT STRING LENGTH FILE_NAME 
>      OWNER_OS HOST_NAME USER CLASS NAME CLIENT_WINDOW 
>      PROCESS COMPOUND_TEXT]
> 
> (get-selection-internal 'PRIMARY 'FILE_NAME)
> ==> "http://www.jwz.org/doc/x-cut-and-paste.html"
> -----[ END OF LINE ]-----
> 

“X Selections, X Cut Buffers, and Emacs Kill Rings [7]”

TARGETS? There might be more to the current primary (or clipboard) selection
than just plain text? I must play around with this. And lo' I did.

And I'm glad I did, because what I found was amazing.

I highlighted some text in Firefox [8] (running under Linux and X11 [9]), and
selected (through some code I had to write—there appears to be no other way
to do this other than XEmacs [10], which I don't have installed, nor do I
wish to install) the PRIMARY TARGETS, figure out what format the data is
returned (an array of X11 atoms for what it's worth) and well … what do you
know …

-----[ data ]-----
TIMESTAMP
TARGETS
text/html
text/_moz_htmlcontext
text/_moz_htmlinfo
UTF8_STRING
COMPOUND_TEXT
TEXT
STRING
text/x-moz-url-priv
-----[ END OF LINE ]-----

Hmm … So, instead of getting just the plain text (and let me pull some text
from my own page here) …

-----[ data ]-----
Journals

    * Ceej's black book
    * Randomly Ever After
    * Orange is Holy
    * Wlofie's Online Journal
    * Azagthoth's Livejournal
    * Resilient's Livejournal
    * Ftrain
-----[ END OF LINE ]-----

I can get the actual HTML (HyperText Markup Language)?

-----[ HTML ]-----
Journals

	<ul>
		<li><a class="external" href="http://snippy.ceejbot.com/wiki/show/start" title="C. J.Silverio">Ceej's black book</a></li> 
		<li><a class="external" href="http://www.asecular.com/ran/" title="TheGus">Randomly Ever After</a></li> 
		<li><a class="external" href="http://www.springdew.com/" title="Spring Dew">Orange is Holy</a></li> 
		<li><a class="external" href="http://wlofie.dyndns.org/diary/" title="Wlofie">Wlofie's Online Journal</a></li> 
		<li><a class="external" href="http://www.livejournal.com/users/azagthoth/" title="Rob Summers">Azagthoth's Livejournal</a></li> 
		<li><a class="external" href="http://www.livejournal.com/users/resilient/">Resilient's Livejournal</a></li> 
		<li><a class="external" href="http://ftrain.com/" title="Paul Ford">Ftrain</a></li> 
	</ul>
-----[ END OF LINE ]-----

The answer appears to be yes (it's in UCS2 [11] format for the record). And
the URL (Uniform Resource Locator)?

-----[ data ]-----
http://boston.conman.org/2003/11/19.2
-----[ END OF LINE ]-----

Well … I'll be … (and this too, is in UCS2 format).

Some quick hacking, and now I have a program that will select the URL and
HTML from the Firefox primary text selection, format it within a <BLOCKQUOTE>
tag, with the CITE and TITLE attributes filled in, and the final <P> tag with
the citation information. And it's easy enough to run said program inside the
current editor I use.

> Journals
> 
> * Ceej's black book (C. J. Silverio) [12]
> * Randomly Ever After (TheGus) [13]
> * Orange is Holy (Spring Dew) [14]
> * Wlofie's Online Journal (Wlofie) [15]
> * Azagthoth's Livejournal (Rob Summers) [16]
> * Resilient's Livejournal (Michelle Reagin) [17]
> * Ftrain (Paul Ford) [18]
> 

“Hypertext editing and the Semantic Web - The Boston Diaries - Captain Napalm
[19]”

Wheeee!

Okay, enough nonsense … this has given me some ideas on an HTML editor …

Update on Tuesday, November 29^th, 2011

Because someone asked, I made the source code [20] available for download.
There's not much in the way of documentation, but I figure that if you
understand what this is doing, then you can probably compile it without
issue.


[1] http://www.jwz.org/doc/x-cut-and-paste.html
[2] gopher://gopher.conman.org/0Phlog:2002/07/11.2
[3] gopher://gopher.conman.org/1Phlog:1999/12/04
[4] gopher://gopher.conman.org/0Phlog:2003/11/19.2
[5] http://www.jwz.org/
[6] http://www.jwz.org/doc/x-cut-and-paste.html
[7] http://www.jwz.org/doc/x-cut-and-paste.html
[8] http://www.mozilla.com/firefox/
[9] http://www.x.org/
[10] http://www.xemacs.org/
[11] http://en.wikipedia.org/wiki/UTF-16
[12] http://snippy.ceejbot.com/wiki/show/start
[13] http://www.asecular.com/ran/
[14] http://www.springdew.com/
[15] http://wlofie.dyndns.org/diary/
[16] http://www.livejournal.com/users/azagthoth/
[17] http://www.livejournal.com/users/resilient/
[18] http://ftrain.com/
[19] http://boston.conman.org/2003/11/19.2
[20] gopher://gopher.conman.org/9Phlog:2008/12/03/blockquote.tar.gz

Email author at sean@conman.org