I use keyboard macros fairly frequently, but I often run into a situation where I would like to increment a number in the macro, e.g., if I start with:
tmp tmp tmp tmp
and I want to end with: tmp1 tmp2 tmp3 tmp4
I know how to create the macro where it would result in: tmp1 tmp1 tmp1 tmp1
Is there a way to make the number increment each time the macro is executed? Otherwise I am forced to step down through each line and manually put the numbers in 1, 2, 3, 4, ... Naturally this is a greatly shortened example for illustration purposes, and often the incrementing takes place within a longer statement e.g., tmp(:,1) = function(x,y). My interest here is how to increment or decrement the number in a more automatic fashion.
I don't mind doing something other than macros, or even external commands (perl/sed/awk, etc.) to assist with this.
Benjamin wrote: > I use keyboard macros fairly frequently, but I often run into a > situation where I would like to increment a number in the macro, e.g.,
you might start by checking out the documentation on keyboard macros:
(info "(emacs) Keyboard Macros")
-- Joost Kremers joostkrem...@yahoo.com Selbst in die Unterwelt dringt durch Spalten Licht EN:SiS(9)
Benjamin <jben...@gmail.com> writes: > I use keyboard macros fairly frequently, but I often run into a > situation where I would like to increment a number in the macro, e.g., > if I start with:
> tmp tmp tmp tmp
> and I want to end with: > tmp1 > tmp2 > tmp3 > tmp4
> I don't mind doing something other than macros, or even external > commands (perl/sed/awk, etc.) > to assist with this.
Benjamin wrote: > I use keyboard macros fairly frequently, but I often run into a > situation where I would like to increment a number in the macro, e.g., > if I start with:
> tmp tmp tmp tmp
> and I want to end with: > tmp1 > tmp2 > tmp3 > tmp4
Benjamin, These functions are useful for this situation C-u 1 C-x r n a (number-to-register a) C-x r i a (insert-register a) C-x r + a (increment-register a)
"Colin S. Miller" <no-spam-thank-...@csmiller.demon.co.uk> writes:
> Benjamin, > These functions are useful for this situation > C-u 1 C-x r n a (number-to-register a) > C-x r i a (insert-register a) > C-x r + a (increment-register a)
I wondered if you could show an example of how this works in a macro... when I try, it just continues to insert 1.
To reproduce: Create macro of: C-u 1 C-x r n a C-x r i a C-x r + a
then walk down this column inserting the macro
str str str str
By running the macro at the end of each line, I get:
> To reproduce: > Create macro of: > C-u 1 C-x r n a > C-x r i a > C-x r + a
The first part (setting register a to 1) must not be part of the macro, but must be done beforehand. Else, each time the macro executes, register a will be set to 1, then you insert the 1, and then you increment it to 2.
So here's how to do it:
C-u 1 C-x r n a ;; Set register a to 1 F3 ;; Start definition of a macro C-x r i a ;; insert value of register a C-x r + a ;; Increment register a F4 ;; End macro definition
Then any additional F4 will insert 2, 3, 4, 5, 6, ...
> I use keyboard macros fairly frequently, but I often run into a > situation where I would like to increment a number in the macro, e.g., > if I start with:
> tmp tmp tmp tmp
> and I want to end with: > tmp1 > tmp2 > tmp3 > tmp4
> I know how to create the macro where it would result in: > tmp1 > tmp1 > tmp1 > tmp1
> Is there a way to make the number increment each time the macro is > executed? > Otherwise I am forced to step down through each line and manually put > the numbers in 1, 2, 3, 4, ... > Naturally this is a greatly shortened example for illustration > purposes, and often the incrementing takes place within a longer > statement e.g., tmp(:,1) = function(x,y). My interest here is how to > increment or decrement the number in a more automatic fashion.
> I don't mind doing something other than macros, or even external > commands (perl/sed/awk, etc.) > to assist with this.
This is a frequently asked question in emacs communities.
Different people has different solution. For me, i wrote a function to do it. I documented it in this page:
The following is excerpt: ------------------------------------ Sometimes, you need to insert a vertical column of sequential integers into a block of text, like this:
do this x times do this x times do this x times ...
where the “x” should be 1, 2, 3, ... The following code does it.
(defun insert-counter-column (n) "Insert a sequence of integers vertically. Example: do this 1 times do this 2 times do this 3 times ...
If there are not enough existing lines after the cursor when this function is called, it aborts at the last line.
See also: `kill-rectangle' and `string-rectangle'." (interactive "nEnter the max integer: ") (let ((i 1) colpos) (setq colpos (- (point) (point-at-bol))) (while (<= i n) (insert (number-to-string i)) (next-line) (beginning-of-line) (forward-char colpos) (setq i (1+ i)) )))
Note: if you are a perl programer (or python, ruby, etc), you can easily write a function in your lang and have a emacs wrapper calling it. So that, you select you text, press a hotkey, and emacs call your script, feed it the current selection, and return the output replacing the current text selection.
On Oct 2, 10:05 pm, Benjamin <jben...@gmail.com> wrote:
> I use keyboard macros fairly frequently, but I often run into a > situation where I would like to increment a number in the macro, e.g., > if I start with:
Keyboard Macro Counters! That's what they're there for:
> and I want to end with: > tmp1 > tmp2 > tmp3 > tmp4
> I know how to create the macro where it would result in: > tmp1 > tmp1 > tmp1 > tmp1
> Is there a way to make the number increment each time the macro is > executed? > Otherwise I am forced to step down through each line and manually put > the numbers in 1, 2, 3, 4, ... > Naturally this is a greatly shortened example for illustration > purposes, and often the incrementing takes place within a longer > statement e.g., tmp(:,1) = function(x,y). My interest here is how to > increment or decrement the number in a more automatic fashion.
> I don't mind doing something other than macros, or even external > commands (perl/sed/awk, etc.) > to assist with this.
In article <d9407676-bb83-46a4-9804-0450cc190...@v37g2000prg.googlegroups.com>, Xah Lee <xah...@gmail.com> wrote:
Please -- I know you love your nice control-chars your posts always include, but it sure makes it near IMPOSSIBLE for us to read, or especially to NICELY save, them.
Suggestion:
Each post you make, DOUBLE it: first part "your way", then a dashed line or lines, then again, but without that stuff in it. Just plain ascii, minus any within-line control-chars.
(Presumably you take the trouble to write your posts, to think them through, etc, because you want us to READ them, to BENEFIT from them, perhaps to even SAVE them. Seems to me that it would thus be to YOUR benefit to make them as easy as possible to read, and likewise to save away, maybe even for OTHERS to read (attributed to you, of course).)
> In article <d9407676-bb83-46a4-9804-0450cc190...@v37g2000prg.googlegroups.com>, > Xah Lee <xah...@gmail.com> wrote:
> Please -- I know you love your nice control-chars your posts > always include, but it sure makes it near IMPOSSIBLE for us > to read, or especially to NICELY save, them.
> Suggestion:
> Each post you make, DOUBLE it: first part "your way", then > a dashed line or lines, then again, but without that stuff > in it. Just plain ascii, minus any within-line control-chars.
> (Presumably you take the trouble to write your posts, to think > them through, etc, because you want us to READ them, to BENEFIT > from them, perhaps to even SAVE them. Seems to me that it would > thus be to YOUR benefit to make them as easy as possible to read, > and likewise to save away, maybe even for OTHERS to read (attributed > to you, of course).)
> Thanks for at least considering the above.
Hi David,
was it you who wrote me at least twice about this issue in the past in separate times?
If i didn't recall incorrectly, i never got any reasons what is the problem.
The "control chars" you mention, are unicode characters, and pretty standard ones, such as curly quotes and bullets.
I wrote all my posts using just emacs, and they show correctly in just about all web browsers from groups.google.com. There is no problem in copy and pasting them, nor can i imagine there any problem in saving them as file, in any of Windows, Mac, or linux. the encoding used is utf-8, default in mac, linuxes, and fully supported Windows.
unicode is charset in langs like xml, java... etc.
can you be explicit exactly what is the problem? is it some news reader that does not support unicode? i haven't tried, but it'd be a major shame if u telling me emacs+gnus or Mozilla's Thunderbird does not support unicode out of the box?
>On Oct 17, 6:46 pm, dkco...@panix.com (David Combs) wrote: >> In article <d9407676-bb83-46a4-9804-0450cc190...@v37g2000prg.googlegroups.com>, >> Xah Lee <xah...@gmail.com> wrote:
>> Please -- I know you love your nice control-chars your posts >> always include, but it sure makes it near IMPOSSIBLE for us >> to read, or especially to NICELY save, them.
>> Suggestion:
>> Each post you make, DOUBLE it: first part "your way", then >> a dashed line or lines, then again, but without that stuff >> in it. Just plain ascii, minus any within-line control-chars.
>> (Presumably you take the trouble to write your posts, to think >> them through, etc, because you want us to READ them, to BENEFIT >> from them, perhaps to even SAVE them. Seems to me that it would >> thus be to YOUR benefit to make them as easy as possible to read, >> and likewise to save away, maybe even for OTHERS to read (attributed >> to you, of course).)
>> Thanks for at least considering the above.
>Hi David,
>was it you who wrote me at least twice about this issue in the past in >separate times?
>If i didn't recall incorrectly, i never got any reasons what is the >problem.
>The "control chars" you mention, are unicode characters, and pretty >standard ones, such as curly quotes and bullets.
>I wrote all my posts using just emacs, and they show correctly in just >about all web browsers from groups.google.com. There is no problem in >copy and pasting them, nor can i imagine there any problem in saving >them as file, in any of Windows, Mac, or linux. the encoding used is >utf-8, default in mac, linuxes, and fully supported Windows.
>unicode is charset in langs like xml, java... etc.
>can you be explicit exactly what is the problem? is it some news >reader that does not support unicode? i haven't tried, but it'd be a >major shame if u telling me emacs+gnus or Mozilla's Thunderbird does >not support unicode out of the box?
Thunderbird is a mail and news client, not a browser, although it can show HTML-formatted messages.
> I don't use a web-browser for newsgroups -- I use "trn4".
You should upgrade, or accept being left behind,
> And with that, your unicode orwhatever looks pretty bad, > unreadable in some cases.
Unicode is not necessary in Usenet posts, I'll give you that, but I hope that you won't insist on 7-bit us-ascii text. That is too US-parochial. I use ISO-8859-1 (ISO Latin 1) because I need it for my Swedish alphabet (a-z plus åäö, mostly), but Thunderbird is capable of showing Unicode if necessary. Most modern Linuxes, e g Ubuntu, use UTF-8 by default, by the way.
> How about writing for just plain old ascii terminals, eg > adm3a or vt-100 -- isn't that the working assumption for > newsgroup text?