Google search from inside emacs

Artur Malabarba, of endless parentheses, has a nice package called google this which provides a set of functions for querying google from emacs.

Here is my code to install google-this

;; google-this
(use-package google-this
  (google-this-mode 1))

The package provides a set of functions under the prefix C-c /. The simplest is C-c / RET which prompts you for a search in the minibuffer, with a default search string based on the text around the point. This sounds trivial, but I find myself using it all the time as it is more efficient than switching to my browser, moving to the search box and trying the search string.

The full list of commands is:

C-c / SPC google-this-region
C-c / a google-this-ray
C-c / c google-this-translate-query-or-region
C-c / e google-this-error
C-c / f google-this-forecast
C-c / g google-this-lucky-search
C-c / i google-this-lucky-and-insert-url
C-c / l google-this-line
C-c / m google-maps
C-c / n google-this-noconfirm
C-c / r google-this-cpp-reference
C-c / s google-this-symbol
C-c / t google-this
C-c / w google-this-word
C-c / <return> google-this-search
  • Clément Pit-Claudel

    Neat. One small thing: from lisp, I don’t think you need to pass “1” to mode functions. That is, it’s enough to write (google-this-mode) instead of (google-this-mode 1)

  • Justin Heyes-Jones
  • VanLaser

    ;; google-this operator on `go'
    (evil-define-operator evil-operator-google-search (beg end type)
    "Evil operator for google search. Uses `google-this` package."
    :move-point nil
    (interactive "")
    (google-this-string current-prefix-arg
    "n" " " (buffer-substring-no-properties beg end))
    (define-key evil-motion-state-map (kbd "g o") #'evil-operator-google-search)

    … and now I can “operate” (google) on any text-object know by “Vim”(Evil): word, paragraph, line, sentence etc. 🙂 Example: `goo` – google-search current line, `1goo` – search current line text between quotes, `goiw` – search crt word, `goip` – search inside crt paragraph etc. (and of course works with visual selection). And I just configured one key 🙂