This small snippet looks up a the current word or region in Wikipedia. If the cursor is before a word, it grabs the word. If you have marked a region, it grabs that. The function opens the search site in Wikipedia to lookup your searchterm.
I’ve used the sample from from Xah Lees page (http://ergoemacs.org/emacs/elisp_idioms.html).
;; ,----
;; | Wikipedia Lookup
;; `----
;; Looks up current word in Wikipedia in a browser. If a region is
;; active (a phrase), lookup hat phrase.
;; http://ergoemacs.org/emacs/elisp_idioms.html
(defun wikipedia-lookup ()
(interactive)
(let (myWord myUrl)
(setq myWord
(if (region-active-p)
(buffer-substring-no-properties (region-beginning) (region-end))
(thing-at-point 'symbol)))
(setq myUrl
(concat "http://de.wikipedia.org/wiki/Special:Search?search=" myWord))
(browse-url myUrl)))
You can do that for some other sites. Simply set the my Url to a different location:
- The LEO online dictionary: http://dict.leo.org/?search=
- Google: http://www.google.de/search?q=
- Emacs Wiki: http://www.google.de/search?q=site:emacswiki.org
I’ll give you the example for the emacs wiki. You have to put a ” ” space after the URL parameter “site:emacswiki.org ”
(defun emacswiki-lookup ()
(interactive)
(let (myWord myUrl)
(setq myWord
(if (region-active-p)
(buffer-substring-no-properties (region-beginning) (region-end))
(thing-at-point 'symbol)))
(setq myUrl
(concat "http://www.google.de/search?q=site:emacswiki.org " myWord))
(browse-url myUrl)))
If you define more lookups an interactive function would be nice which asks for the specific lookup:
- [e]macswiki
- [g]oogle
- [l]eo
- [w]ikipedia
Don’t know how to do that. š