Use commandparser.parse_check_run() for keys.py
This commit is contained in:
parent
7c33bffdb2
commit
8e71f0cb8c
@ -3,7 +3,8 @@ import re
|
|||||||
|
|
||||||
from PyQt5.QtCore import QObject, pyqtSignal
|
from PyQt5.QtCore import QObject, pyqtSignal
|
||||||
|
|
||||||
from qutebrowser.commands.utils import CommandParser, ArgumentCountError
|
from qutebrowser.commands.utils import (CommandParser, ArgumentCountError,
|
||||||
|
NoSuchCommandError)
|
||||||
|
|
||||||
class KeyParser(QObject):
|
class KeyParser(QObject):
|
||||||
"""Parser for vim-like key sequences"""
|
"""Parser for vim-like key sequences"""
|
||||||
@ -86,17 +87,15 @@ class KeyParser(QObject):
|
|||||||
count = int(countstr) if countstr else None
|
count = int(countstr) if countstr else None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.commandparser.parse(cmdstr_hay)
|
self.commandparser.parse_check_run(cmdstr_hay, count=count,
|
||||||
except ValueError:
|
ignore_exc=False)
|
||||||
|
except NoSuchCommandError:
|
||||||
return
|
return
|
||||||
try:
|
|
||||||
self.commandparser.check()
|
|
||||||
except ArgumentCountError:
|
except ArgumentCountError:
|
||||||
logging.debug('Filling statusbar with partial command {}'.format(
|
logging.debug('Filling statusbar with partial command {}'.format(
|
||||||
cmdstr_hay))
|
cmdstr_hay))
|
||||||
self.set_cmd_text.emit(cmdstr_hay + ' ')
|
self.set_cmd_text.emit(cmdstr_hay + ' ')
|
||||||
return
|
return
|
||||||
self.commandparser.run(count=count)
|
|
||||||
|
|
||||||
def _match_key(self, cmdstr_needle):
|
def _match_key(self, cmdstr_needle):
|
||||||
"""Tries to match a given cmdstr with any defined command"""
|
"""Tries to match a given cmdstr with any defined command"""
|
||||||
|
@ -11,6 +11,9 @@ cmd_dict = {}
|
|||||||
class ArgumentCountError(TypeError):
|
class ArgumentCountError(TypeError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class NoSuchCommandError(ValueError):
|
||||||
|
pass
|
||||||
|
|
||||||
def register_all():
|
def register_all():
|
||||||
"""Register and initialize all commands."""
|
"""Register and initialize all commands."""
|
||||||
# We do this here to avoid a circular import, since commands.commands
|
# We do this here to avoid a circular import, since commands.commands
|
||||||
@ -43,7 +46,7 @@ class CommandParser(QObject):
|
|||||||
cmd = cmd_dict[cmdstr]
|
cmd = cmd_dict[cmdstr]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.error.emit("{}: no such command".format(cmdstr))
|
self.error.emit("{}: no such command".format(cmdstr))
|
||||||
raise ValueError
|
raise NoSuchCommandError
|
||||||
|
|
||||||
if len(parts) == 1:
|
if len(parts) == 1:
|
||||||
args = []
|
args = []
|
||||||
@ -67,13 +70,16 @@ class CommandParser(QObject):
|
|||||||
else:
|
else:
|
||||||
self.cmd.run(self.args)
|
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:
|
try:
|
||||||
self.parse(text)
|
self.parse(text)
|
||||||
self.check()
|
self.check()
|
||||||
except (ArgumentCountError, ValueError):
|
except (ArgumentCountError, NoSuchCommandError):
|
||||||
return
|
if ignore_exc:
|
||||||
self.run()
|
return
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
self.run(count=count)
|
||||||
|
|
||||||
class Command(QObject):
|
class Command(QObject):
|
||||||
"""Base skeleton for a command. See the module help for
|
"""Base skeleton for a command. See the module help for
|
||||||
|
Loading…
Reference in New Issue
Block a user