Emacs Redux

Return to the Essence of Text Editing

Google

| Comments

Wouldn’t it be cool to be able to invoke a Google search from the comfort of your beloved text editor? Here’s a couple of use-cases. You may wish to Google the selected region or to be prompted to enter a query manually. Apart from cool it’s also pretty simple to add such a feature to Emacs.

1
2
3
4
5
6
7
8
9
(defun google ()
  "Google the selected region if any, display a query prompt otherwise."
  (interactive)
  (browse-url
   (concat
    "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
    (url-hexify-string (if mark-active
         (buffer-substring (region-beginning) (region-end))
       (read-string "Google: "))))))

This command will display the query results in your default browser.

I’d suggest binding the command to C-c g if you plan to use it regularly.

1
(global-set-key (kbd "C-c g") 'google)

google is available in Prelude(but with a prelude- prefix).

Comments