help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Insert keyboard macro counter value with multiple formats and values


From: Andreas Politz
Subject: Re: Insert keyboard macro counter value with multiple formats and values in a single iteration
Date: Tue, 02 Sep 2008 23:10:35 +0200
User-agent: Mozilla-Thunderbird 2.0.0.16 (X11/20080724)

Ken Goldman wrote:
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)

Here is a command for the other way around.

(defun foo ()
  (interactive)
  (insert (format "%c" (+ kmacro-counter 97))))

-ap


reply via email to

[Prev in Thread] Current Thread [Next in Thread]