Add arg to run when count given for :set-cmd-text

This commit is contained in:
Michael Hoang 2017-09-23 18:40:42 +10:00
parent 8edaad51c3
commit 8506e1f4f2
3 changed files with 21 additions and 7 deletions

View File

@ -847,7 +847,7 @@ If the option name ends with '?', the value of the option is shown instead.
[[set-cmd-text]] [[set-cmd-text]]
=== set-cmd-text === set-cmd-text
Syntax: +:set-cmd-text [*--space*] [*--append*] 'text'+ Syntax: +:set-cmd-text [*--space*] [*--append*] [*--run-on-count*] 'text'+
Preset the statusbar to some text. Preset the statusbar to some text.
@ -857,6 +857,11 @@ Preset the statusbar to some text.
==== optional arguments ==== optional arguments
* +*-s*+, +*--space*+: If given, a space is added to the end. * +*-s*+, +*--space*+: If given, a space is added to the end.
* +*-a*+, +*--append*+: If given, the text is appended to the current text. * +*-a*+, +*--append*+: If given, the text is appended to the current text.
* +*-r*+, +*--run-on-count*+: If given with a count, the command is run with the given count rather than setting the command text.
==== count
The count if 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.

View File

@ -437,7 +437,8 @@ class MainWindow(QWidget):
# commands # commands
keyparsers[usertypes.KeyMode.normal].keystring_updated.connect( keyparsers[usertypes.KeyMode.normal].keystring_updated.connect(
status.keystring.setText) status.keystring.setText)
cmd.got_cmd.connect(self._commandrunner.run_safely) cmd.got_cmd[str].connect(self._commandrunner.run_safely)
cmd.got_cmd[str, int].connect(self._commandrunner.run_safely)
cmd.returnPressed.connect(tabs.on_cmd_return_pressed) cmd.returnPressed.connect(tabs.on_cmd_return_pressed)
# key hint popup # key hint popup

View File

@ -38,7 +38,7 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
Signals: Signals:
got_cmd: Emitted when a command is triggered by the user. got_cmd: Emitted when a command is triggered by the user.
arg: The command string. arg: The command string and also potentially the count.
clear_completion_selection: Emitted before the completion widget is clear_completion_selection: Emitted before the completion widget is
hidden. hidden.
hide_completion: Emitted when the completion widget should be hidden. hide_completion: Emitted when the completion widget should be hidden.
@ -47,7 +47,7 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
hide_cmd: Emitted when command input can be hidden. hide_cmd: Emitted when command input can be hidden.
""" """
got_cmd = pyqtSignal(str) got_cmd = pyqtSignal([str], [str, int])
clear_completion_selection = pyqtSignal() clear_completion_selection = pyqtSignal()
hide_completion = pyqtSignal() hide_completion = pyqtSignal()
update_completion = pyqtSignal() update_completion = pyqtSignal()
@ -91,7 +91,9 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
@cmdutils.register(instance='status-command', name='set-cmd-text', @cmdutils.register(instance='status-command', name='set-cmd-text',
scope='window', maxsplit=0) scope='window', maxsplit=0)
def set_cmd_text_command(self, text, space=False, append=False): @cmdutils.argument('count', count=True)
def set_cmd_text_command(self, text, count=None, space=False, append=False,
run_on_count=False):
"""Preset the statusbar to some text. """Preset the statusbar to some text.
// //
@ -101,8 +103,11 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
Args: Args:
text: The commandline to set. text: The commandline to set.
count: The count if given.
space: If given, a space is added to the end. space: If given, a space is added to the end.
append: If given, the text is appended to the current text. append: If given, the text is appended to the current text.
run_on_count: If given with a count, the command is run with the
given count rather than setting the command text.
""" """
if space: if space:
text += ' ' text += ' '
@ -114,6 +119,9 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
if not text or text[0] not in modeparsers.STARTCHARS: if not text or text[0] not in modeparsers.STARTCHARS:
raise cmdexc.CommandError( raise cmdexc.CommandError(
"Invalid command text '{}'.".format(text)) "Invalid command text '{}'.".format(text))
if run_on_count and count is not None:
self.got_cmd[str, int].emit(text, count)
else:
self.set_cmd_text(text) self.set_cmd_text(text)
@cmdutils.register(instance='status-command', hide=True, @cmdutils.register(instance='status-command', hide=True,
@ -156,7 +164,7 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
text = self.text() text = self.text()
self.history.append(text) self.history.append(text)
modeman.leave(self._win_id, usertypes.KeyMode.command, 'cmd accept') modeman.leave(self._win_id, usertypes.KeyMode.command, 'cmd accept')
self.got_cmd.emit(prefixes[text[0]] + text[1:]) self.got_cmd[str].emit(prefixes[text[0]] + text[1:])
@pyqtSlot(usertypes.KeyMode) @pyqtSlot(usertypes.KeyMode)
def on_mode_left(self, mode): def on_mode_left(self, mode):