Skip to content

Instantly share code, notes, and snippets.

@hjmr
Created November 19, 2016 05:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hjmr/4d4adea0d822e2a724b5881a415b4bab to your computer and use it in GitHub Desktop.
Save hjmr/4d4adea0d822e2a724b5881a415b4bab to your computer and use it in GitHub Desktop.

[Emacs] Search words and show results in EWW

A setting to enable search words in a region when the region is specified or a word at the point when the region is not specified. Results are displayed in EWW-mode which enables to do everything inside Emacs.

(setq eww-search-prefix "https://www.google.co.jp/search?btnI&q=")
;;
(defun my-eww-search--words (words)
  "search web search engine for word on cursor."
  (let ((search_words (read-from-minibuffer "EWW search for: " words)))
    (split-window-sensibly)
    (eww search_words)))
;;
(defun my-eww-search-words ()
  "Search the region when transient-mark-mode is on, a word at point otherwise."
  (interactive)
  (cond
   ((region-active-p)
    (and transient-mark-mode mark-active)
    (my-eww-search--words (buffer-substring-no-properties (mark) (point))))
   (t
    (my-eww-search--words (thing-at-point 'word t)))))
(global-set-key "\C-cg" 'my-eww-search-words)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment