Emacs: Lookup Google, Dictionary, Documentation

By Xah Lee. Date: . Last updated: .

Emacs: xah-lookup.el, Lookup the Web

For ready to-use-package, see

Emacs: xah-lookup.el, Lookup the Web

Write Your Own Lookup Command

Here's how to write a command to lookup the web of the word under cursor.

This is useful when you are writing a major mode for a programing language. You want to provide a command that lookup function (the word under cursor)'s documentation.

(require 'browse-url) ; part of gnu emacs

(defun my-lookup-wikipedia ()
  "Look up the word under cursor in Wikipedia.
If there is a text selection (a phrase), use that.

This command switches to browser."
  (interactive)
  (let (word)
    (setq word
          (if (use-region-p)
              (buffer-substring-no-properties (region-beginning) (region-end))
            (current-word)))
    (setq word (replace-regexp-in-string " " "_" word))
    (browse-url (concat "http://en.wikipedia.org/wiki/" word))
    ;; (eww myUrl) ; emacs's own browser
    ))

You can setup a key such as F8 for easy access. See: Emacs: How to Define Keys.

You can change the URL in the above definition to other reference sites.

Elisp, Writing Major Mode

  1. Syntax Coloring
  2. Font Lock Mode
  3. Define Face
  4. Color Comment
  5. Comment Command
  6. Your Own Comment Command
  7. Keyword Completion Command
  8. Create Keymap
  9. Abbrev/Template
  10. Text Properties
  11. Overlay Highlighting
  12. Lookup Doc
  13. Syntax Table

  1. How to Name Your Major Mode
  2. provide, require, features
  3. load, load-file, autoload

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard: Best Keyboards for Emacs

Emacs

Emacs Lisp

Misc