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.
Thanks,
-Ben
you might start by checking out the documentation on keyboard macros:
(info "(emacs) Keyboard Macros")
--
Joost Kremers joostk...@yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)
> 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.
C-M-% tmp SPC RET tmp\,(1+ \#) C-q C-j RET
--
David Kastrup
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)
HTH,
Colin S. Miller
Thanks David, I knew it was something relatively simple.
Happy Friday,
-Ben
>
> 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:
str1
str1
str1
str1
Hi Harry,
> 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, ...
Bye,
Tassilo
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:
• Emacs Lisp Examples
http://xahlee.org/emacs/elisp_examples.html
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.
This might be easier for many people.
• Elisp Wrapper For Perl Scripts
http://xahlee.org/emacs/elisp_perl_wrapper.html
Xah
∑ http://xahlee.org/
☄
Keyboard Macro Counters! That's what they're there for:
http://www.gnu.org/software/emacs/manual/html_node/emacs/Keyboard-Macro-Counter.html
Eric
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.
David
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?
Xah
∑ http://xahlee.org/
☄
You're writing for a web-browser?
I don't use a web-browser for newsgroups -- I use "trn4".
And with that, your unicode orwhatever looks pretty bad,
unreadable in some cases.
How about writing for just plain old ascii terminals, eg
adm3a or vt-100 -- isn't that the working assumption for
newsgroup text?
David
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?
That is too limiting.