Awesome suggestions

27.05.2010 22:28

Every once in a while we have a hack day at Zemanta. It's supposed to be a day when you use the office hours to explore any interesting ideas that are always pushed back by more important work. At least in my case, the most interesting ideas usually pop up just after the hack day.

This is also how this little hack came to life. My thinking went into this direction:

Zemanta's in-text link suggestions appear fine and fancy at first, but over time two problems became apparent. First, I myself rarely find the suggested explanatory links useful. It is reasonable to presume that the readers of my posts are also familiar enough with the topic that they find links to such basic explanations as Wikipedia redundant. And secondly, I often manually include in-text links that are much more related to the topic (previous posts on this topic, tickets in bug trackers, other blogs, etc.) Zemanta uses the "Related articles" list on the bottom of the post for such links, but I prefer to include them in-line. This means they can easily get overlooked if the text is flooded with Zemanta's automatic explanatory in-text links.

Now what if there was a way to automatically suggest those in-text links that I currently include manually and save me some copy-and-paste between the browser's location bar and the text editor? Destination URLs of all those links are already in the browser, because I either have them bookmarked or I recently read them when researching the topic of the blog post.

And the best thing is the Firefox browser already has a wonderful suggestion engine out of the box. It's just hard to recognize because by default it's limited to the location text entry field.

Yes, I'm talking about the so-called AwesomeBar.

So I made a tiny Firefox extension that exports the nsIAutoCompleteSearch interface of the Places system through a socket, so that any program on the same computer can access it. Then I wrote a client in the form of a Vim plug-in that throws at it pieces of text you're writing and displays the suggested links for you to choose. Yes, I know Vim was perhaps a bad choice, but this is what I use for blogging and I know how to use its scripting interface.

The plug-in adds a new keybinding (F10 by default). It invokes a function that takes the last typed phrase and runs it through the AwesomeBar magic. Here's how it looks in practice:

Awesomeggest demonstration, pressing F10

Press F10...

Awesomeggest demonstration, choose a web page from the list

choose a web page from the list...

Awesomeggest demonstration, HTML link is inserted

and a HTML link is inserted into the text.

Javascript isn't exactly my cup of tea, so the code is a bit clunky and sometimes the extension just refuses to work for no apparent reason. In any case, see the source for more technical details. There's really not much of it.

The code is available in a git repository under the GPLv2 for your enjoyment. All the usual warnings apply - this might eat your cookies and it certainly exposes your browsing history to every process on the host and possibly the entire internet.

$ git clone

I've been using this for a while now and it's useful to some degree. For one it's pretty good in practice at finding the correct web page, if only the anchor phase appears in the page URL or title (which seems to most of the times). The slowness of the search function in Firefox makes it a little less convenient to use and the Vim interface is pretty bad. An asynchronous search (like in the Firefox URL bar) would make performance problems much less noticeable, but is as far as I see beyond the capability of Vim scripting. Perhaps there is some brave soul out there that will prove how much better some other editor can be at this?

As always, any comments or patches are most welcome.

Posted by Tomaž | Categories: Code

Add a new comment

(No HTML tags allowed. Separate paragraphs with a blank line.)