This is a useful trick if you have a bunch of text that you need to munge and insert an incremented digit during. An example - you want to change:
one two three ... twenty
into:
one => 1, two => 2, three => 3, ... twenty => 20,
You can accomplish this with an emacs keyboard macro; you just need to add a lisp eval to the mix. First, you need to add the initial digit you need to the list:
one => 1, two three ...
The basic logic is: select the digit of the current line, save it to a register, move to our next line, insert the text we want, insert the incremented value in the register, finish the line. I’m going to assume if you’re read this far you know the basic routine for creating an emacs keyboard macro, so here’s the commented dump of the keystrokes needed:
C-( ;; start macro defun C-r ;; isearch-backward SPC ;; self-insert-command C-f ;; forward-char-command C-SPC ;; set-mark-command C-s ;; isearch-forward , ;; self-insert-command RET ;; newline C-b ;; backward-char-command C-x C-x ;; exchange-point-and-mark C-x x ;; copy-to-register a ;; self-insert-command C-n ;; next-line C-e ;; end-of-line SPC ;; self-insert-command => ;; self-insert-command * 2 SPC ;; self-insert-command M-: ;; eval-expression (insert ;; self-insert-command * 7 SPC ;; self-insert-command (number- to- string ;; self-insert-command * 17 SPC ;; self-insert-command (+ ;; self-insert-command * 2 SPC ;; self-insert-command 1 ;; self-insert-command SPC ;; self-insert-command C-x r g ;; insert-register a ;; self-insert-command C-e ;; end-of-line ))) ;; self-insert-command * 3 RET ;; newline , ;; self-insert-command C-e ;; end-of-line C-) ;; end macro defun
The interesting part is the M-: line, which starts a lisp eval mini-buffer, into which I insert: (insert (number-to-string (+ 1 CURVAL))), with CURVAL being inserted from the register. You can then run the macro as many times as needed (with C-x e) to comple all lines.
All those who are now thinking that it would probably have been quicker to either a) just do it all by hand or b) write a perl/python/ruby one-liner and run it over the text; are obviously not true emacs aficiandos.
I was pretty impressed by Jon Udell’s LibraryLookup Greasemonkey script, so I adapted it for Vancouver Public Library. What this does is automatically do a lookup in the VPL catalogue whenever you’re viewing a title on Amazon; if VPL has the item a link will be added to it. This requires the latest version of greasemonkey (version 0.2.6 as of this post).
Maciej Ceglowski has an opinion about Paul Graham. I am still giggling. Much like with David Foster Wallace, be sure to read the footnotes.