Perm url with updates: http://xahlee.org/emacs/emacs_lookup_ref.html
Dictionary, Google, PHP, Perl, ... Reference Lookup with Emacs
Xah Lee, 2008-11, 2010-11-01
This page shows you how to use emacs as a dictionary application, that allows you to lookup the definitions of a word under cursor, or any general reference such as Wikipedia, Google, or lookup documentation of computer language's keywords.
Looking Up Word Under Cursor
You can setup your emacs so that, pressing a button will lookup the definition of the word under cursor.
Place the following in your emacs init file:
(defun lookup-word-definition () "Look up the current word's definition in a browser. If a region is active (a phrase), lookup that phrase." (interactive) (let (myword myurl) (setq myword (if (and transient-mark-mode mark-active) (buffer-substring-no-properties (region-beginning) (region-end)) (thing-at-point 'symbol))) (setq myword (replace-regexp-in-string " " "%20" myword)) (setq myurl (concat "http://www.answers.com/main/ntquery?s=" myword)) (browse-url myurl) ;; (w3m-browse-url myurl) ;; if you want to browse using w3m )) (global-set-key (kbd "<f6>") 'lookup-word-definition)
With the above, pressing F6 will launch your browser and lookup definition of the word under cursor.
If you do a lot vocabulary research, you can have emacs open several dictionaries in one shot. Just add more of the “browse-url” line.
You can change the url to a different online dictionary reference website.
Here are some other online dictionary sites and their url search syntax, using sample word “curlicue”. AHD means American Heritage Dictionary.
- http://education.yahoo.com/reference/dictionary/entry/curlicue (AHD)
- http://www.answers.com/main/ntquery?s=curlicue (AHD)
- http://en.wiktionary.org/wiki/curlicue (wiktionary)
- http://m-w.com/dictionary/curlicue (Merriam Webster Collegiate)
- http://www.askoxford.com/concise_oed/curlicue (Compact Oxford Eng Dict )
- http://www.yourdictionary.com/curlicue (AHD)
- http://dictionary.reference.com/browse/curlicue (AHD, Random House, WordNet, ...)
- http://www.dict.org/bin/Dict?Form=Dict2&Database=*&Query=curlicue (Open Source Dicts)
If you prefer to lookup definitions within emacs, then you need to either install a web browser within emacs, the emacs-w3m. (Note: you might need to spend 30 minutes or more to get it to work.) Or, you can install a emacs dictionary client. See: Emacs Dictionary Lookup.
Perl, PHP, Ruby... Reference Lookup and Google, Wikipedia
The following is a example of looking up Wikipedia:
(defun lookup-wikipedia () "Look up the word under cursor in Wikipedia. This command generates a url for Wikipedia.com and switches you to browser. If a region is active (a phrase), lookup that phrase." (interactive) (let (myword myurl) (setq myword (if (and transient-mark-mode mark-active) (buffer-substring-no-properties (region-beginning) (region-end)) (thing-at-point 'symbol))) (setq myword (replace-regexp-in-string " " "_" myword)) (setq myurl (concat "http://en.wikipedia.org/wiki/" myword)) (browse-url myurl) ))
Here are some example urls for some reference lookup sites.
If you know a url syntax for Ruby, Python, lisp, or other langs, please add at the comment below. Thanks.