From 7d1549aaeb38d22501dc73afbc6398c1379db97c Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 19 Sep 2017 13:14:41 +0200 Subject: [PATCH] Make mode optionally in ConfigAPI.bind and .unbind --- doc/help/configuring.asciidoc | 2 ++ qutebrowser/config/configfiles.py | 4 ++-- tests/unit/config/test_configfiles.py | 20 ++++++++++++++------ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/doc/help/configuring.asciidoc b/doc/help/configuring.asciidoc index 703978019..2842db632 100644 --- a/doc/help/configuring.asciidoc +++ b/doc/help/configuring.asciidoc @@ -162,6 +162,8 @@ To bind a key: config.bind(',v', 'spawn mpv {url}', mode='normal') ---- +For bindings in normal mode, you can also leave out the `, mode='normal'` part. + If the key is already bound, `force=True` needs to be given to rebind it: [source,python] diff --git a/qutebrowser/config/configfiles.py b/qutebrowser/config/configfiles.py index 3810bca8c..fb8ac5f6d 100644 --- a/qutebrowser/config/configfiles.py +++ b/qutebrowser/config/configfiles.py @@ -180,11 +180,11 @@ class ConfigAPI: with self._handle_error('setting', name): self._config.set_obj(name, value) - def bind(self, key, command, *, mode, force=False): + def bind(self, key, command, *, mode='normal', force=False): with self._handle_error('binding', key): self._keyconfig.bind(key, command, mode=mode, force=force) - def unbind(self, key, *, mode): + def unbind(self, key, *, mode='normal'): with self._handle_error('unbinding', key): self._keyconfig.unbind(key, mode=mode) diff --git a/tests/unit/config/test_configfiles.py b/tests/unit/config/test_configfiles.py index 73b091293..63e231d09 100644 --- a/tests/unit/config/test_configfiles.py +++ b/tests/unit/config/test_configfiles.py @@ -191,16 +191,24 @@ class TestConfigPy: configfiles.read_config_py(confpy.filename) assert config.instance._values['colors.hints.bg'] == expected - def test_bind(self, confpy): - confpy.write('config.bind(",a", "message-info foo", mode="normal")') + @pytest.mark.parametrize('line, mode', [ + ('config.bind(",a", "message-info foo")', 'normal'), + ('config.bind(",a", "message-info foo", "prompt")', 'prompt'), + ]) + def test_bind(self, confpy, line, mode): + confpy.write(line) configfiles.read_config_py(confpy.filename) - expected = {'normal': {',a': 'message-info foo'}} + expected = {mode: {',a': 'message-info foo'}} assert config.instance._values['bindings.commands'] == expected - def test_unbind(self, confpy): - confpy.write('config.unbind("o", mode="normal")') + @pytest.mark.parametrize('line, key, mode', [ + ('config.unbind("o")', 'o', 'normal'), + ('config.unbind("y", mode="prompt")', 'y', 'prompt'), + ]) + def test_unbind(self, confpy, line, key, mode): + confpy.write(line) configfiles.read_config_py(confpy.filename) - expected = {'normal': {'o': None}} + expected = {mode: {key: None}} assert config.instance._values['bindings.commands'] == expected def test_mutating(self, confpy):