Zamansky: Learning Elisp #16

Mike Zamansky is back after the holidays with another video on learning Elisp. This video starts a new project on using Web APIs in an Elisp application. Specifically, the purpose of the project is to implement an interactive thesaurus that you can use while writing in Emacs.

The basic plan is to leverage the Merriam-Webster dictionary API to map a word into its synonyms. The API is free to use but you need to register and get a key first. Once you have the key, you need merely query the API with the word you want synonyms for and your key. The answer comes back as a complex JSON structure that must be parsed to get the answer.

Zamansky’s plan is to first get the JSON structure and then to process it. This video considers the first part of the plan. That turns out to be pretty easy. You make the query and receive the answer with url-retrieve-synchronously. The only problem is that url-retrieve-synchronously puts the answer in a separate buffer so you need to use with-current-buffer to extract the JSON from the temporary buffer that url-retrieve-synchronously creates.

The whole thing takes a function that is only 9 lines of Elisp. That’s a lot of processing for just a few lines of code and is a great example of how concise Elisp—and indeed, any Lisp—can be in expressing an algorithm.

The next video will consider processing the JSON to extract the synonyms and replace the target word with one of them. The current video is 21 minutes, 16 seconds so you’ll definitely need to set some time aside for it but as usual with Zamansky’s videos, it’s a worthwhile investment.

This entry was posted in General and tagged , . Bookmark the permalink.