Discussion:
repeat the last command n times
Florian Kaufmann
2006-03-12 13:59:15 UTC
Permalink
Hello

I am searching for a command that repeats the last command n times. I
know there is repeat, usually bound to C-x z. However, if y want to
repeat the last command 12 times, I have to press z 12 times. Id rather
liked to enter 12 directly.
Using universal-argument, usually bound to C-u, also doesn't fit, since
its only an argument for the next command, and not in every case a
repeat count. For example I cant use it to repeat yank.
I thought I could write a little lisp function by myself and use the
command-history. But as its descriptions says it only contains commands
that read an argument from command line. It doesn't contain commands
like yank.
Using the output of view-lossage might be quite tricky, since I think
its not so easy to find out from this information which the last
command was.
Last but not least I could make use of keyboard macros. But then again,

(start-kbd-macro)[command-to-repeat](end-kbd-macro)(universal-argument)[repeat-count](call-last-kbd-macro)
seems quite more cumbersome than a simple
[command-to-repeat][my-super-repeat-command][repeat-count] or a
[my-super-repeat-next-command][repeat-command][command-to-repeat]

Any further ideas?

Greetings

Florian Kaufmann
Drew Adams
2006-03-13 21:11:37 UTC
Permalink
I am searching for a command that repeats the last command n times. I
know there is repeat, usually bound to C-x z. However, if y want to
repeat the last command 12 times, I have to press z 12 times. Id rather
liked to enter 12 directly.

Did you try this? M-x my-command C-u 12 C-x z

However, that doesn't seem to work for all commands. It works, for instance,
for character insertion, but not for `yank'. For example, `a C-u 12 C-x z'
inserts 13 a's, but `C-y C-u 12 C-x z' does not perform 13 yanks.

I don't know if this inconsistency is a bug or a feature, but it is the same
going back to at least Emacs 20. The doc string doesn't help much in this
regard. It seems to indicate that the prefix arg should always be applied.

Here's the doc for `C-x z' (`repeat'):

Repeat most recently executed command.
With prefix arg, apply new prefix arg to that command; otherwise, use
the prefix arg that was used before (if any).

If this command is invoked by a multi-character key sequence, it can then
be repeated by repeating the final character of that sequence. This
behavior
can be modified by the global variable `repeat-on-final-keystroke'."

Those who are familiar with what this command does or should do: Should the
doc string clarify the different cases where `C-u' does not have the
indicated effect?
bojohan+ (Johan Bockgård)
2006-03-13 21:43:39 UTC
Permalink
Post by Drew Adams
Repeat most recently executed command.
With prefix arg, apply new prefix arg to that command; otherwise, use
the prefix arg that was used before (if any).
If this command is invoked by a multi-character key sequence, it can then
be repeated by repeating the final character of that sequence. This
behavior
can be modified by the global variable `repeat-on-final-keystroke'."
Should the doc string clarify the different cases where `C-u' does
not have the indicated effect?
It works just as indicated.
--
Johan Bockgård
Florian Kaufmann
2006-03-13 22:58:22 UTC
Permalink
As John said, it works as indicated. That is, it doesn't work together
with yank, because yank doesn't take the argument as a repeat count.
The existence of an argument just tells yank that the point should be
at the beginning of the inserted sequence after insertion. C-u 12 C-y
doesn't make 12 yanks, but 1 yank with the point being at beginning of
the inserted string. Now the documentation of repeat (that is C-x z)
sais that it passes the argument to the command to be repeated. Thus
C-y C-u 12 C-x z makes first a yank, then repeats it one time. After
the second yank, the repeated one, the point will be at the beginning
of the inserted string.

Flo
Drew Adams
2006-03-17 04:36:30 UTC
Permalink
As John said, it works as indicated. That is, it doesn't work together
with yank, because yank doesn't take the argument as a repeat count.
The existence of an argument just tells yank that the point should be
at the beginning of the inserted sequence after insertion. C-u 12 C-y
doesn't make 12 yanks, but 1 yank with the point being at beginning of
the inserted string. Now the documentation of repeat (that is C-x z)
sais that it passes the argument to the command to be repeated. Thus
C-y C-u 12 C-x z makes first a yank, then repeats it one time. After
the second yank, the repeated one, the point will be at the beginning
of the inserted string.

Thank you for making it clear, Florian. The main point is that the prefix
arg is passed to the previous command (the one that is repeated), and it is
that command that interprets the arg as it likes (as usual).

Actually, a prefix arg for `yank' is more complicated than what you
describe. A plain `C-u' (no number) has the effect you describe. But if a
number N is supplied, then `yank' inserts the Nth most recent entry in the
kill-ring. In the example given, `C-u 12 C-y' inserts the 12th most recently
killed span of text.

Continue reading on narkive:
Loading...