2012-07-09

I saw the Got Emacs? posting showing off the new emacs-24
rectangle-number-lines command, to number a bunch of lines in buffer,
i.e..:

foo
bar
cuux

becomes:

1 foo
2 bar
3 cuux

Very cool! An alternative is to use cua-mode, mark the column for the
numbers with cua-set-rectangle-mark (C-RET), and then use M-x cua-sequence-rectangle (which takes you throught the steps, and has a lot of
flexibility.

But let's look at yet another way: using replace-regexp. If we select (mark)
the list once more, we can do M-x replace-regexp RET ^ RET \#. RET Note that
the # is a special meta-character that represents the number of replacements already made. This has the somewhat clumsy side-effect that your
list be numbered, starting at 0 rather than 1, so you should add a
dummy-element at the beginning. Clearly, replace-regexp is inferior for
simply adding some line numbers – however, it has the flexibility to do some
smarter things.