Tim Visher has a new VimGolf in Emacs up. This time it's a simple alignment problem using
align-regexp, a function that we've talked about before. In this case he just used the simple
align-regexp case and was done in about 6 keystrokes, much less than the 18 that the best Vim solution took.
It turns out the the
align function, of which
align-regexp is a special case, is very flexible. It will try to align the region or current group of text in a context dependent way. The action of
align is specified by a set of rules that specify context (such as major mode), a regular expression, and some other attributes. The list of rules is in the variable
align-rules-list. The documentation for that variable explains the various options and gives its current value. You can also pass in your own list of rules. The
align-regexp function basically just prompts you for an ad hoc rule.
Unfortunately, the documentation isn't very good and the rules can be quite complex. Visher mentions this page from the EmacsWiki that gives some examples but it is by no means a complete explanation. This is a very powerful function and I wish the documentation on it was better. Unfortunately it isn't even mentioned in the Emacs manual.