4 ms·
There is the \# character, which is replaced with the number of times a replacement has been done. So, M-x replace-regexp Replace regexp: test\(.+\)
by trjordan 15y ago
There is the \# character, which is replaced with the number of times a replacement has been done. So,
M-x replace-regexp
Replace regexp: test\(.+\)
Replace regexp with test\#
You can actually drop arbitrary lisp in the middle of search/replace expressions. So, if you'd like to number from 1 instead of 0,
M-x replace-regexp
Replace regexp: test\(.+\)
Replace regexp with test\,(1+ \#\)
I'm sure with more lisp tricks, you can get delimited lists:
M-x replace-regexp
Replace regexp: test\(.+\)
Replace regexp with test\,(aref ["one", "two", "three"] (mod \# 3))
(Not sure that works, but you get the idea).
Anyway, all of this was basically stolen from Steve Yegge. You should totally go read his article if you're interested: http://steve-yegge.blogspot.com/2006/06/shiny-and-new-emacs-22.html http://steve-yegge.blogspot.com/2006/06/shiny-and-new-emacs-...