Ignore ;; for splitting with some commands.

Fixes #405.
This commit is contained in:
Florian Bruhin 2015-04-06 17:00:52 +02:00
parent 46d1760798
commit 20f0ef7ccc
6 changed files with 20 additions and 12 deletions

View File

@ -758,7 +758,8 @@ class Application(QApplication):
else:
return True
@cmdutils.register(instance='app', maxsplit=0, debug=True)
@cmdutils.register(instance='app', maxsplit=0, debug=True,
no_cmd_split=True)
def debug_pyeval(self, s):
"""Evaluate a python string and display the results as a web page.

View File

@ -116,7 +116,7 @@ class register: # pylint: disable=invalid-name
def __init__(self, instance=None, name=None, maxsplit=None, hide=False,
completion=None, modes=None, not_modes=None, needs_js=False,
debug=False, ignore_args=False, deprecated=False,
scope='global'):
no_cmd_split=False, scope='global'):
"""Save decorator arguments.
Gets called on parse-time with the decorator arguments.
@ -139,6 +139,7 @@ class register: # pylint: disable=invalid-name
self._deprecated = deprecated
self._debug = debug
self._ignore_args = ignore_args
self._no_cmd_split = no_cmd_split
if modes is not None:
for m in modes:
if not isinstance(m, usertypes.KeyMode):
@ -196,7 +197,8 @@ class register: # pylint: disable=invalid-name
completion=self._completion, modes=self._modes,
not_modes=self._not_modes, needs_js=self._needs_js,
is_debug=self._debug, ignore_args=self._ignore_args,
deprecated=self._deprecated, handler=func)
deprecated=self._deprecated, no_cmd_split=self._no_cmd_split,
handler=func)
for name in names:
cmd_dict[name] = cmd
aliases += names[1:]

View File

@ -46,6 +46,7 @@ class Command:
special_params: A dict with the names of the special parameters as
values.
flags_with_args: A list of flags which take an argument.
no_cmd_split: If true, ';;' to split sub-commands is ignored.
_type_conv: A mapping of conversion functions for arguments.
_name_conv: A mapping of argument names to parameter names.
_needs_js: Whether the command needs javascript enabled
@ -65,7 +66,7 @@ class Command:
def __init__(self, name, maxsplit, hide, instance, completion, modes,
not_modes, needs_js, is_debug, ignore_args, deprecated,
handler, scope):
no_cmd_split, handler, scope):
# I really don't know how to solve this in a better way, I tried.
# pylint: disable=too-many-arguments,too-many-locals
self.name = name
@ -81,6 +82,7 @@ class Command:
self.debug = is_debug
self.ignore_args = ignore_args
self.handler = handler
self.no_cmd_split = no_cmd_split
self.docparser = docutils.DocstringParser(handler)
self.parser = argparser.ArgumentParser(
name, description=self.docparser.short_desc,

View File

@ -279,11 +279,14 @@ class CommandRunner(QObject):
text: The text to parse.
count: The count to pass to the command.
"""
if ';;' in text:
for sub in text.split(';;'):
self.run(sub, count)
return
self.parse(text)
if ';;' in text:
# Get the first command and check if it doesn't want to have ;;
# split.
if not self._cmd.no_cmd_split:
for sub in text.split(';;'):
self.run(sub, count)
return
args = replace_variables(self._win_id, self._args)
if count is not None:
self._cmd.run(self._win_id, args, count=count)

View File

@ -139,7 +139,7 @@ class KeyConfigParser(QObject):
data = str(self)
f.write(data)
@cmdutils.register(instance='key-config', maxsplit=1)
@cmdutils.register(instance='key-config', maxsplit=1, no_cmd_split=True)
def bind(self, key, command, *, mode=None, force=False):
"""Bind a key to a command.

View File

@ -34,7 +34,7 @@ from qutebrowser.config import style
from qutebrowser.misc import consolewidget
@cmdutils.register(scope='window', maxsplit=1)
@cmdutils.register(scope='window', maxsplit=1, no_cmd_split=True)
def later(ms: {'type': int}, command, win_id: {'special': 'win_id'}):
"""Execute a command after some time.
@ -63,7 +63,7 @@ def later(ms: {'type': int}, command, win_id: {'special': 'win_id'}):
raise
@cmdutils.register(scope='window', maxsplit=1)
@cmdutils.register(scope='window', maxsplit=1, no_cmd_split=True)
def repeat(times: {'type': int}, command, win_id: {'special': 'win_id'}):
"""Repeat a given command.
@ -122,7 +122,7 @@ def debug_console():
con_widget.show()
@cmdutils.register(debug=True, maxsplit=0)
@cmdutils.register(debug=True, maxsplit=0, no_cmd_split=True)
def debug_trace(expr=""):
"""Trace executed code via hunter.