Emacs macro to generate a sequence?

Solution 1:

If you are using Emacs 23 (and maybe 22?), use kmacro-insert-counter which is bound to C-x C-k TAB by default. So for your example, you'd do:

C-x ( C-x C-k TAB . RET C-x )

So start macro, insert counter followed by '.', newline, end macro. Then C-x e e e e e e e etc. Or M-1 0 0 C-x e to get 100 of them.

EDIT:

Forgot to mention you can set the counter to an initial value also. For example to start at 1 instead of 0 do M-1 C-x C-k C-c.

And if you don't want the counter to increment at a particular point, prefix it with C-u. Of course the keystrokes are getting a bit ridiculous at this point, so I usually bind a key to insert-but-don't-increment.

Solution 2:

Those who feel there are too many tricks to memorize might find acquiring some elisp more profitable:

M-: (dotimes (i 20) (insert (format "%2d.\n" (1+ i))))