by jfager · 15y ago · 0 comments
http://www.emacswiki.org/emacs/KeyboardMacrosTricks
From there:
If you want to produce this list:
test1
test2
test3
...
Do like this:
C-x r n q (store the number 1 in register q)
C-x ( (start macro recording)
test C-x r i q (insert contents of register q)
C-x r + q (increment register q by 1)
RET (new line)
C-x ) (stop macro recording)Here's my definitions:
(defvar *rolling-counter* 0)
(defun rolling-increment-number-at-point ()
(interactive)
(incf *rolling-counter*)
(skip-chars-backward "0123456789")
(or (looking-at "[0123456789]+")
(error "No number at point"))
(replace-match (number-to-string (+ *rolling-counter*
(string-to-number (match-string 0))))))
(defun clear-rolling-history ()
(interactive)
(setf *rolling-counter* 0))