Merge remote-tracking branch 'origin/pr/4126'

This commit is contained in:
Florian Bruhin 2018-08-12 20:24:56 +02:00
commit 58dffafb1e
3 changed files with 18 additions and 1 deletions

View File

@ -918,6 +918,9 @@ Repeat a given command.
* +'times'+: How many times to repeat. * +'times'+: How many times to repeat.
* +'command'+: The command to run, with optional args. * +'command'+: The command to run, with optional args.
==== count
Multiplies with 'times' when given.
==== note ==== note
* This command does not split arguments after the last argument and handles quotes literally. * This command does not split arguments after the last argument and handles quotes literally.
* With this command, +;;+ is interpreted literally instead of splitting off a second command. * With this command, +;;+ is interpreted literally instead of splitting off a second command.

View File

@ -74,13 +74,18 @@ def later(ms: int, command, win_id):
@cmdutils.register(maxsplit=1, no_cmd_split=True, no_replace_variables=True) @cmdutils.register(maxsplit=1, no_cmd_split=True, no_replace_variables=True)
@cmdutils.argument('win_id', win_id=True) @cmdutils.argument('win_id', win_id=True)
def repeat(times: int, command, win_id): @cmdutils.argument('count', count=True)
def repeat(times: int, command, win_id, count=None):
"""Repeat a given command. """Repeat a given command.
Args: Args:
times: How many times to repeat. times: How many times to repeat.
command: The command to run, with optional args. command: The command to run, with optional args.
count: Multiplies with 'times' when given.
""" """
if count is not None:
times *= count
if times < 0: if times < 0:
raise cmdexc.CommandError("A negative count doesn't make sense.") raise cmdexc.CommandError("A negative count doesn't make sense.")
commandrunner = runners.CommandRunner(win_id) commandrunner = runners.CommandRunner(win_id)

View File

@ -41,6 +41,15 @@ Feature: Miscellaneous utility commands exposed to the user.
# If we have an error, the test will fail # If we have an error, the test will fail
Then no crash should happen Then no crash should happen
Scenario: :repeat with count
When I run :repeat 3 message-info "repeat-test 3" with count 2
Then the message "repeat-test 3" should be shown
And the message "repeat-test 3" should be shown
And the message "repeat-test 3" should be shown
And the message "repeat-test 3" should be shown
And the message "repeat-test 3" should be shown
And the message "repeat-test 3" should be shown
## :run-with-count ## :run-with-count
Scenario: :run-with-count Scenario: :run-with-count