From b7ea8e79790db549037a1b86bf490324e7f9496c Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 11 Dec 2014 20:25:54 +0100 Subject: [PATCH] Support a maxsplit argument for commands. --- qutebrowser/app.py | 2 +- qutebrowser/browser/commands.py | 6 +++--- qutebrowser/browser/quickmarks.py | 2 +- qutebrowser/commands/cmdutils.py | 9 +++++---- qutebrowser/commands/command.py | 7 ++++--- qutebrowser/commands/runners.py | 5 +++-- 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index dcb4c2fa7..6919a4c48 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -602,7 +602,7 @@ class Application(QApplication): if shutdown: self.shutdown() - @cmdutils.register(instance='app', split=False, debug=True) + @cmdutils.register(instance='app', maxsplit=0, debug=True) def debug_pyeval(self, s): """Evaluate a python string and display the results as a webpage. diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index fd15e4881..4fbacf0b6 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -270,7 +270,7 @@ class CommandDispatcher: tabbar.setSelectionBehaviorOnRemove(old_selection_behavior) @cmdutils.register(instance='command-dispatcher', name='open', - split=False, scope='window', + maxsplit=0, scope='window', completion=[usertypes.Completion.quickmark_by_url]) def openurl(self, url, bg=False, tab=False, window=False, count: {'special': 'count'}=None): @@ -777,7 +777,7 @@ class CommandDispatcher: finally: tabbed_browser.setUpdatesEnabled(True) - @cmdutils.register(instance='command-dispatcher', split=False, + @cmdutils.register(instance='command-dispatcher', maxsplit=0, scope='window') def spawn(self, *args): """Spawn a command in a shell. @@ -823,7 +823,7 @@ class CommandDispatcher: quickmark_manager.prompt_save(self._win_id, self._current_url()) @cmdutils.register(instance='command-dispatcher', scope='window', - split=False, + maxsplit=0, completion=[usertypes.Completion.quickmark_by_name]) def quickmark_load(self, name, tab=False, bg=False, window=False): """Load a quickmark. diff --git a/qutebrowser/browser/quickmarks.py b/qutebrowser/browser/quickmarks.py index 19042d10f..2705c76f4 100644 --- a/qutebrowser/browser/quickmarks.py +++ b/qutebrowser/browser/quickmarks.py @@ -110,7 +110,7 @@ class QuickmarkManager(QObject): else: set_mark() - @cmdutils.register(instance='quickmark-manager', split=False, + @cmdutils.register(instance='quickmark-manager', maxsplit=0, completion=[usertypes.Completion.quickmark_by_name]) def quickmark_del(self, name): """Delete a quickmark. diff --git a/qutebrowser/commands/cmdutils.py b/qutebrowser/commands/cmdutils.py index 757072dad..0152f52c9 100644 --- a/qutebrowser/commands/cmdutils.py +++ b/qutebrowser/commands/cmdutils.py @@ -101,7 +101,8 @@ class register: # pylint: disable=invalid-name _instance: The object from the object registry to be used as "self". _scope: The scope to get _instance for. _name: The name (as string) or names (as list) of the command. - _split: Whether to split the arguments. + _maxsplit: The maxium amounts of splits to do for the commandline, or + None. _hide: Whether to hide the command or not. _completion: Which completion to use for arguments, as a list of strings. @@ -111,7 +112,7 @@ class register: # pylint: disable=invalid-name _ignore_args: Whether to ignore the arguments of the function. """ - def __init__(self, instance=None, name=None, split=True, hide=False, + 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, scope='global'): """Save decorator arguments. @@ -125,7 +126,7 @@ class register: # pylint: disable=invalid-name if modes is not None and not_modes is not None: raise ValueError("Only modes or not_modes can be given!") self._name = name - self._split = split + self._maxsplit = maxsplit self._hide = hide self._instance = instance self._scope = scope @@ -187,7 +188,7 @@ class register: # pylint: disable=invalid-name if name in cmd_dict: raise ValueError("{} is already registered!".format(name)) cmd = command.Command( - name=names[0], split=self._split, hide=self._hide, + name=names[0], maxsplit=self._maxsplit, hide=self._hide, instance=self._instance, scope=self._scope, completion=self._completion, modes=self._modes, not_modes=self._not_modes, needs_js=self._needs_js, diff --git a/qutebrowser/commands/command.py b/qutebrowser/commands/command.py index fd80ed003..992adda46 100644 --- a/qutebrowser/commands/command.py +++ b/qutebrowser/commands/command.py @@ -34,7 +34,8 @@ class Command: Attributes: name: The main name of the command. - split: Whether to split the arguments. + maxsplit: The maximum amount of splits to do for the commandline, or + None. hide: Whether to hide the arguments or not. desc: The description of the command. handler: The handler function to call. @@ -60,13 +61,13 @@ class Command: ['kwargs', 'type', 'name', 'flag', 'special']) - def __init__(self, name, split, hide, instance, completion, modes, + def __init__(self, name, maxsplit, hide, instance, completion, modes, not_modes, needs_js, is_debug, ignore_args, 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 - self.split = split + self.maxsplit = maxsplit self.hide = hide self._instance = instance self.completion = completion diff --git a/qutebrowser/commands/runners.py b/qutebrowser/commands/runners.py index 931e07bac..96ef8693b 100644 --- a/qutebrowser/commands/runners.py +++ b/qutebrowser/commands/runners.py @@ -247,7 +247,7 @@ class CommandRunner(QObject): """ if not argstr: self._args = [] - elif self._cmd.split: + elif self._cmd.maxsplit is None: self._args = split.split(argstr, keep=keep) else: # If split=False, we still want to split the flags, but not @@ -266,7 +266,8 @@ class CommandRunner(QObject): arg = arg.strip() if not arg.startswith('-'): self._args = [] - args = split.simple_split(argstr, keep=keep, maxsplit=i) + args = split.simple_split(argstr, keep=keep, + maxsplit=i + self._cmd.maxsplit) for s in args: # remove quotes and replace \" by " s = re.sub(r"""(^|[^\\])["']""", r'\1', s)