Emacs: Command to Search Web 🚀
Write Command to Search Web, or Lookup Function Doc, Word Definition, Synonyms, or Image Search, Etc.
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 ))
To make this command search different search engine, such as google, yandex, baidu, dictionary, image search, YouTube search etc, you just need to change the URL.
Emacs, Web Browser
Emacs Lisp, writing a major mode. Essentials
- Elisp: Write a Major Mode for Syntax Coloring
- Elisp: Font Lock Mode
- Elisp: Syntax Color Comments
- Elisp: Write Comment/Uncomment Command
- Elisp: Keyword Completion
- Elisp: Create Keymap (keybinding)
- Elisp: Create Function Templates
- Emacs: Command to Search Web 🚀
- Elisp: Create a Hook
- Elisp: Major Mode Names
- Elisp: provide, require, features
- Elisp: load, load-file, autoload
- Elisp: Syntax Table