Emacs Rocks

Tim Visher has started a growth industry with his VimGolf in Emacs videos. First, some of us starting writing about the videos, then people started issuing their own challenges, and now he has a direct competitor with Emacs Rocks. I don’t know how Visher feels about that but I’m delighted. It’s more fun and more opportunities to learn some nifty Emacs tricks.

For example, the second and third episodes reconsider the problem explored in VimGolf in Emacs e006. The final solution solves the problem in an incredible 10 keystrokes, beating the best Vim score by 7 strokes.

Not all the Emacs Rocks episodes discuss VimGolf problems through. Episode 1 deals with a small refactoring of some JavaScript code. In that video he needs to mark a rectangle and uses a nice trick that could be brought to bear on yesterday’s post. Recall that the problem was to sort

California             423,970 km²
Taiwan                  36,008 km²
Japan                  377,944 km²
Germany                357,021 km²
Iraq                   438,317 km²
Iran                 1,648,195 km²
Korea (North+South)    219,140 km²
Mexico               1,964,375 km²

by the number of square kilometers. I did that by marking the rectangle containing the numbers and calling sort-columns. I wasn’t really thinking about VimGolf so I didn’t mark the rectangle in an optimum way; I just said put the point here, set the mark, put the point there and call sort-columns. Here’s how the trick from Emacs Rocks can be used to mark the rectangle.

Let’s assume that after the first part of the problem, the point is left at the end of the last line. If we do a 【Ctrl+r␣␣42Return】 (where ␣ is a space), we end up two spaces in front of the the 423,970 in the first line, which is just where we want to be. Furthermore, since incremental search sets the mark at the starting point, we have marked the rectangle in only 6 keystrokes. A similar trick works if we begin with the point at the beginning of the first line: type 【Ctrl+e】 to move to the end of the line, then 【Ctrl+s1,9Return】 【Ctrl+3 Ctrl+b】 to move the point right before the 1,964,375.

I already knew that incremental search sets the mark, of course, because it tells me every time I do an incremental search. The insight I gained from Episode 1 of Emacs Rocks is that it can be a quick and easy way of marking a rectangle.

So welcome to Emacs Rocks. There are 6 episodes so far and I’ve enjoyed them all and am looking forward to more. It’s always nice to see Emacs in action.

Update ⌴ → ␣ (Thanks to Xah Lee for telling me the correct character for space)

This entry was posted in General and tagged . Bookmark the permalink.