* Insert keyboard macro counter value with multiple formats and values in a single iteration
@ 2008-09-02 14:19 Corey Foote
0 siblings, 0 replies; 4+ messages in thread
From: Corey Foote @ 2008-09-02 14:19 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 1081 bytes --]
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?
Thanks!
Sincerely,
Corey Foote
_________________________________________________________________
Talk to your Yahoo! Friends via Windows Live Messenger. Find out how.
http://www.windowslive.com/explore/messenger?ocid=TXT_TAGLM_WL_messenger_yahoo_082008
[-- Attachment #2: Type: text/html, Size: 1341 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Insert keyboard macro counter value with multiple formats and values in a single iteration
[not found] <mailman.18202.1220365168.18990.help-gnu-emacs@gnu.org>
@ 2008-09-02 18:17 ` Ken Goldman
2008-09-02 21:10 ` Andreas Politz
0 siblings, 1 reply; 4+ messages in thread
From: Ken Goldman @ 2008-09-02 18:17 UTC (permalink / raw)
To: help-gnu-emacs
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)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Insert keyboard macro counter value with multiple formats and values in a single iteration
2008-09-02 18:17 ` Insert keyboard macro counter value with multiple formats and values in a single iteration Ken Goldman
@ 2008-09-02 21:10 ` Andreas Politz
2008-09-03 6:12 ` Chet
0 siblings, 1 reply; 4+ messages in thread
From: Andreas Politz @ 2008-09-02 21:10 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Insert keyboard macro counter value with multiple formats and values in a single iteration
2008-09-02 21:10 ` Andreas Politz
@ 2008-09-03 6:12 ` Chet
0 siblings, 0 replies; 4+ messages in thread
From: Chet @ 2008-09-03 6:12 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-09-03 6:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.18202.1220365168.18990.help-gnu-emacs@gnu.org>
2008-09-02 18:17 ` Insert keyboard macro counter value with multiple formats and values in a single iteration Ken Goldman
2008-09-02 21:10 ` Andreas Politz
2008-09-03 6:12 ` Chet
2008-09-02 14:19 Corey Foote
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.