Use maxsplit=1 for :repeat and :later.

This commit is contained in:
Florian Bruhin 2014-12-11 21:25:05 +01:00
parent 0acd61368e
commit 8bad7c0e4c

View File

@ -30,17 +30,16 @@ from qutebrowser.config import style
from qutebrowser.widgets import console from qutebrowser.widgets import console
@cmdutils.register(scope='window') @cmdutils.register(scope='window', maxsplit=1)
def later(ms: {'type': int}, *command, win_id: {'special': 'win_id'}): def later(ms: {'type': int}, command, win_id: {'special': 'win_id'}):
"""Execute a command after some time. """Execute a command after some time.
Args: Args:
ms: How many milliseconds to wait. ms: How many milliseconds to wait.
*command: The command to run, with optional args. command: The command to run, with optional args.
""" """
if ms < 0: if ms < 0:
raise cmdexc.CommandError("I can't run something in the past!") raise cmdexc.CommandError("I can't run something in the past!")
cmdline = ' '.join(command)
commandrunner = runners.CommandRunner(win_id) commandrunner = runners.CommandRunner(win_id)
app = objreg.get('app') app = objreg.get('app')
timer = usertypes.Timer(name='later', parent=app) timer = usertypes.Timer(name='later', parent=app)
@ -52,7 +51,7 @@ def later(ms: {'type': int}, *command, win_id: {'special': 'win_id'}):
raise cmdexc.CommandError("Numeric argument is too large for " raise cmdexc.CommandError("Numeric argument is too large for "
"internal int representation.") "internal int representation.")
timer.timeout.connect( timer.timeout.connect(
functools.partial(commandrunner.run_safely, cmdline)) functools.partial(commandrunner.run_safely, command))
timer.timeout.connect(timer.deleteLater) timer.timeout.connect(timer.deleteLater)
timer.start() timer.start()
except: # pylint: disable=bare-except except: # pylint: disable=bare-except
@ -60,20 +59,19 @@ def later(ms: {'type': int}, *command, win_id: {'special': 'win_id'}):
raise raise
@cmdutils.register(scope='window') @cmdutils.register(scope='window', maxsplit=1)
def repeat(times: {'type': int}, *command, win_id: {'special': 'win_id'}): def repeat(times: {'type': int}, command, win_id: {'special': 'win_id'}):
"""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.
""" """
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.")
cmdline = ' '.join(command)
commandrunner = runners.CommandRunner(win_id) commandrunner = runners.CommandRunner(win_id)
for _ in range(times): for _ in range(times):
commandrunner.run_safely(cmdline) commandrunner.run_safely(command)
@cmdutils.register(debug=True) @cmdutils.register(debug=True)