From 961fa07fb016bf67edb4fc09b6fa037478e477b4 Mon Sep 17 00:00:00 2001 From: wishfort36 <42300264+wishfort36@users.noreply.github.com> Date: Sat, 11 Aug 2018 17:59:45 +0200 Subject: [PATCH 1/5] Core functionality --- qutebrowser/misc/utilcmds.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/qutebrowser/misc/utilcmds.py b/qutebrowser/misc/utilcmds.py index 702c62cac..99ccc8ecf 100644 --- a/qutebrowser/misc/utilcmds.py +++ b/qutebrowser/misc/utilcmds.py @@ -74,13 +74,20 @@ def later(ms: int, command, win_id): @cmdutils.register(maxsplit=1, no_cmd_split=True, no_replace_variables=True) @cmdutils.argument('win_id', win_id=True) -def repeat(times: int, command, win_id): +@cmdutils.argument('count', count=True) +@cmdutils.argument('mulcount', flag='c') +def repeat(times: int, command, win_id, count=None, mulcount=False): """Repeat a given command. Args: times: How many times to repeat. command: The command to run, with optional args. + mulcount: Multiply 'times' with [count]. """ + + if mulcount and count is not None: + times *= count + if times < 0: raise cmdexc.CommandError("A negative count doesn't make sense.") commandrunner = runners.CommandRunner(win_id) From b085a8a7de3e05c592e3c706a090d750783f561c Mon Sep 17 00:00:00 2001 From: wishfort36 <42300264+wishfort36@users.noreply.github.com> Date: Sat, 11 Aug 2018 18:18:39 +0200 Subject: [PATCH 2/5] Update documentation --- doc/help/commands.asciidoc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index 3d60cce64..fef4c07f6 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -910,7 +910,7 @@ The tab index to reload. [[repeat]] === repeat -Syntax: +:repeat 'times' 'command'+ +Syntax: +:repeat [*--mulcount*] 'times' 'command'+ Repeat a given command. @@ -918,6 +918,9 @@ Repeat a given command. * +'times'+: How many times to repeat. * +'command'+: The command to run, with optional args. +==== optional arguments +* +*-c*+, +*--mulcount*+: When given, 'times' will be multiplied with [count]. + ==== note * 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. From f27195d3601ea3b249f2a056a1d4163dc4ff5004 Mon Sep 17 00:00:00 2001 From: wishfort36 <42300264+wishfort36@users.noreply.github.com> Date: Sat, 11 Aug 2018 18:31:17 +0200 Subject: [PATCH 3/5] Have 'times' multiply with [count] by default --- doc/help/commands.asciidoc | 6 +++--- qutebrowser/misc/utilcmds.py | 6 ++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index fef4c07f6..06f5da6c6 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -910,7 +910,7 @@ The tab index to reload. [[repeat]] === repeat -Syntax: +:repeat [*--mulcount*] 'times' 'command'+ +Syntax: +:repeat 'times' 'command'+ Repeat a given command. @@ -918,8 +918,8 @@ Repeat a given command. * +'times'+: How many times to repeat. * +'command'+: The command to run, with optional args. -==== optional arguments -* +*-c*+, +*--mulcount*+: When given, 'times' will be multiplied with [count]. +==== count +Multiplies with 'times' when given ==== note * This command does not split arguments after the last argument and handles quotes literally. diff --git a/qutebrowser/misc/utilcmds.py b/qutebrowser/misc/utilcmds.py index 99ccc8ecf..e867dd0b8 100644 --- a/qutebrowser/misc/utilcmds.py +++ b/qutebrowser/misc/utilcmds.py @@ -75,17 +75,15 @@ def later(ms: int, command, win_id): @cmdutils.register(maxsplit=1, no_cmd_split=True, no_replace_variables=True) @cmdutils.argument('win_id', win_id=True) @cmdutils.argument('count', count=True) -@cmdutils.argument('mulcount', flag='c') -def repeat(times: int, command, win_id, count=None, mulcount=False): +def repeat(times: int, command, win_id, count=None): """Repeat a given command. Args: times: How many times to repeat. command: The command to run, with optional args. - mulcount: Multiply 'times' with [count]. """ - if mulcount and count is not None: + if count is not None: times *= count if times < 0: From adb371f305348a2cede447b354ea5ebd7cb8257d Mon Sep 17 00:00:00 2001 From: wishfort36 <42300264+wishfort36@users.noreply.github.com> Date: Sat, 11 Aug 2018 19:04:18 +0200 Subject: [PATCH 4/5] Add test --- tests/end2end/features/utilcmds.feature | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/end2end/features/utilcmds.feature b/tests/end2end/features/utilcmds.feature index 5ccbac9b3..fc397f506 100644 --- a/tests/end2end/features/utilcmds.feature +++ b/tests/end2end/features/utilcmds.feature @@ -41,6 +41,15 @@ Feature: Miscellaneous utility commands exposed to the user. # If we have an error, the test will fail Then no crash should happen + Scenario: :repeat with count + When I run :run-with-count 2 repeat 3 message-info "repeat-test 3" + 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 Scenario: :run-with-count From 8e2307c546fa774cc593949065940951f7cf6530 Mon Sep 17 00:00:00 2001 From: farlusiva Date: Sat, 11 Aug 2018 19:32:41 +0200 Subject: [PATCH 5/5] Docstring things, change test - Update the docstring for repeat - Remove the blank line after the docstring - Update the docstring with scripts/dev/src2asciidoc.py - Simplify the test --- doc/help/commands.asciidoc | 2 +- qutebrowser/misc/utilcmds.py | 2 +- tests/end2end/features/utilcmds.feature | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index 06f5da6c6..6daff3bcc 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -919,7 +919,7 @@ Repeat a given command. * +'command'+: The command to run, with optional args. ==== count -Multiplies with 'times' when given +Multiplies with 'times' when given. ==== note * This command does not split arguments after the last argument and handles quotes literally. diff --git a/qutebrowser/misc/utilcmds.py b/qutebrowser/misc/utilcmds.py index e867dd0b8..d108a56ac 100644 --- a/qutebrowser/misc/utilcmds.py +++ b/qutebrowser/misc/utilcmds.py @@ -81,8 +81,8 @@ def repeat(times: int, command, win_id, count=None): Args: times: How many times to repeat. command: The command to run, with optional args. + count: Multiplies with 'times' when given. """ - if count is not None: times *= count diff --git a/tests/end2end/features/utilcmds.feature b/tests/end2end/features/utilcmds.feature index fc397f506..fac335813 100644 --- a/tests/end2end/features/utilcmds.feature +++ b/tests/end2end/features/utilcmds.feature @@ -42,7 +42,7 @@ Feature: Miscellaneous utility commands exposed to the user. Then no crash should happen Scenario: :repeat with count - When I run :run-with-count 2 repeat 3 message-info "repeat-test 3" + 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