diff --git a/qutebrowser/commands/keys.py b/qutebrowser/commands/keys.py index eaca9825f..39a28ed65 100644 --- a/qutebrowser/commands/keys.py +++ b/qutebrowser/commands/keys.py @@ -3,7 +3,8 @@ import re from PyQt5.QtCore import QObject, pyqtSignal -from qutebrowser.commands.utils import CommandParser, ArgumentCountError +from qutebrowser.commands.utils import (CommandParser, ArgumentCountError, + NoSuchCommandError) class KeyParser(QObject): """Parser for vim-like key sequences""" @@ -86,17 +87,15 @@ class KeyParser(QObject): count = int(countstr) if countstr else None try: - self.commandparser.parse(cmdstr_hay) - except ValueError: + self.commandparser.parse_check_run(cmdstr_hay, count=count, + ignore_exc=False) + except NoSuchCommandError: return - try: - self.commandparser.check() except ArgumentCountError: logging.debug('Filling statusbar with partial command {}'.format( cmdstr_hay)) self.set_cmd_text.emit(cmdstr_hay + ' ') return - self.commandparser.run(count=count) def _match_key(self, cmdstr_needle): """Tries to match a given cmdstr with any defined command""" diff --git a/qutebrowser/commands/utils.py b/qutebrowser/commands/utils.py index d1b64f497..a0a65674d 100644 --- a/qutebrowser/commands/utils.py +++ b/qutebrowser/commands/utils.py @@ -11,6 +11,9 @@ cmd_dict = {} class ArgumentCountError(TypeError): pass +class NoSuchCommandError(ValueError): + pass + def register_all(): """Register and initialize all commands.""" # We do this here to avoid a circular import, since commands.commands @@ -43,7 +46,7 @@ class CommandParser(QObject): cmd = cmd_dict[cmdstr] except KeyError: self.error.emit("{}: no such command".format(cmdstr)) - raise ValueError + raise NoSuchCommandError if len(parts) == 1: args = [] @@ -67,13 +70,16 @@ class CommandParser(QObject): else: self.cmd.run(self.args) - def parse_check_run(self, text, count=None): + def parse_check_run(self, text, count=None, ignore_exc=True): try: self.parse(text) self.check() - except (ArgumentCountError, ValueError): - return - self.run() + except (ArgumentCountError, NoSuchCommandError): + if ignore_exc: + return + else: + raise + self.run(count=count) class Command(QObject): """Base skeleton for a command. See the module help for