Monthly Archives: July 2016

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
  :config
  (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

Use visible bookmarks to quickly jump around a file

The visible bookmarks package lets you bookmark positions in the current buffer and then jump between them. This is really useful if you are working on large files and have a few common locations you want to keep returning to. It is more efficient than jumping around the mark ring or moving through edit points.

Here is my code to install and configure visible bookmarks with the recommended key bindings:

(use-package bm
  :bind (("<C-f2>" . bm-toggle)
         ("<f2>" . bm-next)
         ("<S-f2>" . bm-previous)))

Here is a trivial illustration where I use <C-f2> to place three bookmarks (causing those lines to be highlighted) and then <f2> and <S-f2> to move up and down through them, before using <C-f2> again to toggle the bookmarks off.

visible-bookmarks.gif

The package will also let you cycle through bookmarks in multiple buffers, and move in order of “last in first out”. See the documentation for more information.

Move to the beginning of a line the smart way

I’ve moved away from using my recommended setup, prelude in favour of completely writing my own customisation file. I would still recommend prelude for beginner and intermediate Emacs users, but I wanted full control for myself. I have missed a few things from prelude, but happily the author provides some of his useful functions in a stand alone package called crux.

One of my favourite tools from crux is crux-move-beginning-of-line, which I use in place of the normal C-a to move to the start of the line. The crux version has the extra benefit that the first time you use it, it moves the point to the first non-whitespace character on the line. Repeating it moves to the start of the line, and more repeats toggle back and forth.

Here’s how I install and configure crux to do this.

(use-package crux
  :bind (("C-a" . crux-move-beginning-of-line)))

Crux has lots of other useful tools, so go and check them out.