This is really a post about how awesome emacs is. To start, though, something sexier than emacs:
Beer! I like to brew. My wife and I brewed 250 bottles (an amber and a Belgian witbier) for our wedding. Now that I have a house, I can do things like buy bulk grains and hops. But which hops to buy? What grain do I want 50lbs of?
So, I went to this awesome database of brewing recipes. I want to learn to make a solid Belgian Dubbel, and would like to see what the most common recipes are. I want to read all of the recipes labeled eg (extract-grain) and see what they do. I also don’t want to spend 10 minutes finding and opening the 48 eg links on this page (out of hundreds of links).
Now, I know this sounds trivial, but listen — this can either be a tedious exercise, full of right clicking, eyeballing, and RSI escalation. Or it can be a fun logic puzzle.
Macros. In my emacs setup, if I hit F3, it records my keystrokes. Hitting F4 stops the recording, and hitting F4 again repeats the recorded sequence of keystrokes.
1) Line breaks. One of my pet peeves is the fact that gmail (and also most of my collaborator’s text editors) take normal text (one continuous line, formatted for your particular page)
and deform it into something like this (artificial line breaks; looks terrible if you scale)
I’m nerotic about these things, but don’t expect my collaborators to be. (But this blog’s audience? Compatible neuroses?)
Also — not something that a find-and-replace can fix. (Though query-replace with emacs, noting that C-q C-j inserts a linebreak, works well).
Basically what I did was the following sequence of keystrokes (on a mac):
– go to end of line (Cmd-right)
– go to next line (right)
– hit backspace (or delete)
– hit space.
One nice feature of this is that having it as a hotkey lets you decide when to use it. I basically want to use it for each paragraph, but not for, e.g., code or displayed math.
2) Beer! Back to beer, and a second screencast.
— view source (right click-select view source)
— copy to emacs
— start macro (f3)
– search for eg (C-s return; eg)
– move to front of line (Cmd-left)
– go up two lines
– highlight everything above this () or ()
– search for eg again
– go to end of line (Cmd-right)
– highlight (Cmd-Shift-left)
– cut (Cmd-x)
– paste at end of file (Cmd-down, paste)
– move to top of file (Cmd-up)
— end macro (f4)
Now I just hold F4 for ten seconds and I’m done.
Once I get a list of urls, I put “open” in front of each line (via macros or query-replace w/ C-q C-j), copy, and paste into a terminal and they all open as separate tabs in a browser. I can quickly browse them now.
(If I want to automate more, instead of opening, I can curl the url, write to a file, and do the same kind of macro as before to get the piece of the table with grain, hops, etc and get a big list of data to study.)
Epilogue. I’m not a trained programmer. MAGMA taught me most of what I `know’. I like coding bash scripts to do things and generally finding better ways to automate repetitive tasks in my life. Programmers might cringe at my use of macros (“Seriously? Just use regular expressions…”) But for a non-programmer, recording a series of keystrokes is a fun logic problem, while regular expressions requires reading a manual.
As a mathematician, in my idle time, I almost always want to do the first, and almost never want to do the second.