Corey Foote wrote:
I'm looking for a way to use the keyboard macro counter to insert the
value of the counter multiple times in a macro each with a different
format as well as increase / decrease it by a certain amount. For
example, I'm trying to create a macro which will create one of the
following lines every time it's invoked:
<option value="a"><%=string1%></option>
<option value="b"><%=string2%></option>
<option value="c"><%=string3%></option>
<option value="d"><%=string4%></option>
...
So I need it to insert 1 and a for the first invocation, 2 and b for
the second, 3 and c for the third, etc. I don't think it will work to
simply change the format, because I would also need to change the
value by +/- 97 as well. Is there an easy way to do this or should I
be using something else, like a register perhaps?
I found this years ago, but it doesn't increment letters.
(defun increment (n) (interactive "p")
;; Increment the number after point. With an argument, add that much.
(let (val)
(delete-region
(point)
(progn
(setq val (read (current-buffer)))
(if (not (numberp val)) (error "Not in front of a number"))
(point)))
(insert (int-to-string (+ val n)))))
(global-set-key "\C-c+" 'increment)