From 2536766cacdd5a38c56fd852e75f830328c84a8f Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Mon, 2 May 2016 22:54:47 -0400 Subject: [PATCH] Run :bind to print the current binding. The arg is now optional. If omitted, :bind prints the current binding as a message. If --mode is given, the binding for that mode is printed. --- qutebrowser/config/parsers/keyconf.py | 21 +++++++++++++++++---- tests/integration/features/keyinput.feature | 14 ++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/qutebrowser/config/parsers/keyconf.py b/qutebrowser/config/parsers/keyconf.py index 487659984..74252cc92 100644 --- a/qutebrowser/config/parsers/keyconf.py +++ b/qutebrowser/config/parsers/keyconf.py @@ -27,7 +27,7 @@ from PyQt5.QtCore import pyqtSignal, QObject from qutebrowser.config import configdata, textwrapper from qutebrowser.commands import cmdutils, cmdexc -from qutebrowser.utils import log, utils, qtutils +from qutebrowser.utils import log, utils, qtutils, message class KeyConfigError(Exception): @@ -150,19 +150,32 @@ class KeyConfigParser(QObject): data = str(self) f.write(data) - @cmdutils.register(instance='key-config', maxsplit=1, no_cmd_split=True) - def bind(self, key, command, *, mode=None, force=False): + @cmdutils.register(instance='key-config', maxsplit=1, no_cmd_split=True, + win_id='win_id') + def bind(self, key, win_id, command=None, *, mode=None, force=False): """Bind a key to a command. Args: key: The keychain or special key (inside `<...>`) to bind. - command: The command to execute, with optional args. + command: The command to execute, with optional args, or None to + print the current binding. mode: A comma-separated list of modes to bind the key in (default: `normal`). force: Rebind the key if it is already bound. """ if mode is None: mode = 'normal' + + if command is None: + cmd = self.get_bindings_for(mode).get(key, None) + if cmd is None: + message.info(win_id, "{} is unbound in {} mode".format( + key, mode)) + else: + message.info(win_id, "{} is bound to '{}' in {} mode".format( + key, cmd, mode)) + return + mode = self._normalize_sectname(mode) for m in mode.split(','): if m not in configdata.KEY_DATA: diff --git a/tests/integration/features/keyinput.feature b/tests/integration/features/keyinput.feature index 1d930da24..656391de5 100644 --- a/tests/integration/features/keyinput.feature +++ b/tests/integration/features/keyinput.feature @@ -31,6 +31,20 @@ Feature: Keyboard input And I press the keys "test5" Then the message "test5-2" should be shown + Scenario: Printing an unbound key + When I run :bind test6 + Then the message "test6 is not bound in normal mode" should be shown + + Scenario: Printing a bound key + When I run :bind test6 message-info foo + And I run :bind test6 + Then the message "test6 is bound to 'message-info foo' in normal mode" should be shown + + Scenario: Printing a bound key in a given mode + When I run :bind --mode=caret test6 message-info bar + And I run :bind --mode=caret test6 + Then the message "test6 is bound to 'message-info bar' in caret mode" should be shown + # :unbind Scenario: Binding and unbinding a keychain