[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Insert keyboard macro counter value with multiple formats and values
From: |
Chet |
Subject: |
Re: Insert keyboard macro counter value with multiple formats and values in a single iteration |
Date: |
Tue, 02 Sep 2008 23:12:21 -0700 |
User-agent: |
Emacs Gnus |
Andreas Politz <politza@fh-trier.de> writes:
> 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
This can be done in many ways. There are also inse t-rectangle-number or
such functions available online - I use my own which does something similar.
(defun increment-char (n) (interactive "p")
"Increment the char after point. With an argument, add that much."
(let ((c (char-after)))
(delete-char 1)
(insert-char (+ c n) 1)))
Makes the integer start value and char start values independent, if desired.
Chetan