Random entry: python and emacs: the rope way

Do you use google to find definitions?

Posted on September 13, 2008 at 5:13 PM.

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 :)

Creative Commons License A Django Site A MySQL Site ASO hosting RSS 2.0 Feed

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.

This site is Powered by Django using MySQL as database engine.

RSS Entries and RSS Comments