Do you use google to find definitions?

UPDATE:For this code to work you need to include the mm-url library. The code is now fixed

If so, here’s a little snippet I wrote for emacs to have all this power just one keystroke away

(require 'mm-url)
(defun google-define-word-or-phrase (query)
  (interactive "sInsert word or phrase to search: ")
  (let* ((url (concat "http://www.google.com.pe/search?hl=en&q=define%3A"
              (replace-regexp-in-string " " "+" query)))
     (definition
       (save-excursion
         (with-temp-buffer
           (mm-url-insert url)
           (goto-char (point-min))
           (if (search-forward "No definitions found of " nil t)
           "No definitions found"
         (buffer-substring (search-forward "<li>") (- (search-forward "<") 1)))))))
    (message "%s: %s" query definition)))

(global-set-key [f5] 'google-define-word-or-phrase)

This uses google’s define: operator to look up for a word or phrase. Copy & Paste this code into your .emacs and with pressinf F5 you will be prompted for your query. Have fun

If you have any comments on the code they will be more than welcome :)

Comments are currently closed.