New on MELPA - define word at point22 May 2015
Doing things in Emacs is superlatively better than having to switch to another application.
In this case, "doing things" is getting the dictionary definition of word at point, and "superlatively" is a word that I didn't know - a straw that broke the camel's back and caused me to finally automate the process of getting the definition of a word that I encounter in an Emacs buffer.
The whole process of writing the
define-word package took around 30
minutes, I just had to:
- See which engine DuckDuckGo uses.
- Follow to wordnik.
- Try to get an API key, read their draconian TOS and decide that I don't want to agree to it just to get their key.
- Examine the HTML that it returns and note that it's quite regular.
- Write a 10 line function with
re-search-forwardto extract the word definitions from a sample page that I saved with
Then just wrap the function in an
url-retrieve and done. It's a
good thing that I learned to use
url-retrieve when I wrote
Here's how it looks like in action, the word under point is "Authors" and instead of visiting this page, you can see it right away in your Echo Area:
The result is displayed simply with
message, so it doesn't mess with
your window config. You read it, press any key and the Echo Area
popup will vanish automatically.
Install the package from MELPA or check it out at github. You just need to decide where to bind it:
(global-set-key (kbd "C-c d") 'define-word-at-point) (global-set-key (kbd "C-c D") 'define-word)
At less than 50 lines, the source is very easy to understand. So if you're looking to write some Elisp that retrieves and parses some HTML from a web service, it's nice to look at a simple implementation of how it's done.