Merge branch 'bind-alias' of https://github.com/rcorre/qutebrowser into rcorre-bind-alias

This commit is contained in:
Florian Bruhin 2016-08-10 09:35:28 +02:00
commit cc0579bd1a
5 changed files with 28 additions and 5 deletions

View File

@ -29,7 +29,7 @@ import functools
from qutebrowser.completion.models import miscmodels, urlmodel, configmodel
from qutebrowser.utils import objreg, usertypes, log, debug
from qutebrowser.config import configdata
from qutebrowser.config import configdata, config
_instances = {}
@ -155,6 +155,12 @@ def update(completions):
did_run.append(func)
@config.change_filter('aliases', function=True)
def _update_aliases():
"""Update completions that include command aliases."""
update([usertypes.Completion.command])
def init():
"""Initialize completions. Note this only connects signals."""
quickmark_manager = objreg.get('quickmark-manager')
@ -176,3 +182,5 @@ def init():
keyconf = objreg.get('key-config')
keyconf.changed.connect(
functools.partial(update, [usertypes.Completion.command]))
objreg.get('config').changed.connect(_update_aliases)

View File

@ -36,7 +36,7 @@ import collections.abc
from PyQt5.QtCore import pyqtSignal, QObject, QUrl, QSettings
from qutebrowser.config import configdata, configexc, textwrapper
from qutebrowser.config.parsers import ini, keyconf
from qutebrowser.config.parsers import ini
from qutebrowser.commands import cmdexc, cmdutils
from qutebrowser.utils import (message, objreg, utils, standarddir, log,
qtutils, error, usertypes)
@ -178,6 +178,7 @@ def _init_key_config(parent):
Args:
parent: The parent to use for the KeyConfigParser.
"""
from qutebrowser.config.parsers import keyconf
args = objreg.get('args')
try:
key_config = keyconf.KeyConfigParser(standarddir.config(), 'keys.conf',

View File

@ -25,7 +25,7 @@ import itertools
from PyQt5.QtCore import pyqtSignal, QObject
from qutebrowser.config import configdata, textwrapper
from qutebrowser.config import configdata, textwrapper, config
from qutebrowser.commands import cmdutils, cmdexc
from qutebrowser.utils import log, utils, qtutils, message, usertypes
@ -352,7 +352,8 @@ class KeyConfigParser(QObject):
line))
commands = [c.split(maxsplit=1)[0].strip() for c in commands]
for cmd in commands:
if cmd not in cmdutils.cmd_dict:
aliases = config.section('aliases')
if cmd not in cmdutils.cmd_dict and cmd not in aliases:
raise KeyConfigError("Invalid command '{}'!".format(cmd))
def _read_command(self, line):

View File

@ -61,6 +61,18 @@ Feature: Keyboard input
And I run :bind <ctrl-test23>
Then the message "<ctrl-test23> is bound to 'message-info bar' in normal mode" should be shown
Scenario: Binding to an alias
When I run :set aliases 'mib' 'message-info baz'
And I run :bind test25 mib
And I press the keys "test25"
Then the message "baz" should be shown
Scenario: Printing a bound alias
When I run :set aliases 'mib' 'message-info baz'
And I run :bind <test26> mib
And I run :bind <test26>
Then the message "<test26> is bound to 'mib' in normal mode" should be shown
# :unbind
Scenario: Binding and unbinding a keychain

View File

@ -214,7 +214,7 @@ class TestKeyConfigParser:
"""Test config.parsers.keyconf.KeyConfigParser."""
def test_cmd_binding(self, cmdline_test):
def test_cmd_binding(self, cmdline_test, config_stub):
"""Test various command bindings.
See https://github.com/The-Compiler/qutebrowser/issues/615
@ -222,6 +222,7 @@ class TestKeyConfigParser:
Args:
cmdline_test: A pytest fixture which provides testcases.
"""
config_stub.data = {'aliases': []}
kcp = keyconf.KeyConfigParser(None, None)
kcp._cur_section = 'normal'
if cmdline_test.valid: