Merge branch 'bind-alias' of https://github.com/rcorre/qutebrowser into rcorre-bind-alias
This commit is contained in:
commit
cc0579bd1a
@ -29,7 +29,7 @@ import functools
|
|||||||
|
|
||||||
from qutebrowser.completion.models import miscmodels, urlmodel, configmodel
|
from qutebrowser.completion.models import miscmodels, urlmodel, configmodel
|
||||||
from qutebrowser.utils import objreg, usertypes, log, debug
|
from qutebrowser.utils import objreg, usertypes, log, debug
|
||||||
from qutebrowser.config import configdata
|
from qutebrowser.config import configdata, config
|
||||||
|
|
||||||
|
|
||||||
_instances = {}
|
_instances = {}
|
||||||
@ -155,6 +155,12 @@ def update(completions):
|
|||||||
did_run.append(func)
|
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():
|
def init():
|
||||||
"""Initialize completions. Note this only connects signals."""
|
"""Initialize completions. Note this only connects signals."""
|
||||||
quickmark_manager = objreg.get('quickmark-manager')
|
quickmark_manager = objreg.get('quickmark-manager')
|
||||||
@ -176,3 +182,5 @@ def init():
|
|||||||
keyconf = objreg.get('key-config')
|
keyconf = objreg.get('key-config')
|
||||||
keyconf.changed.connect(
|
keyconf.changed.connect(
|
||||||
functools.partial(update, [usertypes.Completion.command]))
|
functools.partial(update, [usertypes.Completion.command]))
|
||||||
|
|
||||||
|
objreg.get('config').changed.connect(_update_aliases)
|
||||||
|
@ -36,7 +36,7 @@ import collections.abc
|
|||||||
from PyQt5.QtCore import pyqtSignal, QObject, QUrl, QSettings
|
from PyQt5.QtCore import pyqtSignal, QObject, QUrl, QSettings
|
||||||
|
|
||||||
from qutebrowser.config import configdata, configexc, textwrapper
|
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.commands import cmdexc, cmdutils
|
||||||
from qutebrowser.utils import (message, objreg, utils, standarddir, log,
|
from qutebrowser.utils import (message, objreg, utils, standarddir, log,
|
||||||
qtutils, error, usertypes)
|
qtutils, error, usertypes)
|
||||||
@ -178,6 +178,7 @@ def _init_key_config(parent):
|
|||||||
Args:
|
Args:
|
||||||
parent: The parent to use for the KeyConfigParser.
|
parent: The parent to use for the KeyConfigParser.
|
||||||
"""
|
"""
|
||||||
|
from qutebrowser.config.parsers import keyconf
|
||||||
args = objreg.get('args')
|
args = objreg.get('args')
|
||||||
try:
|
try:
|
||||||
key_config = keyconf.KeyConfigParser(standarddir.config(), 'keys.conf',
|
key_config = keyconf.KeyConfigParser(standarddir.config(), 'keys.conf',
|
||||||
|
@ -25,7 +25,7 @@ import itertools
|
|||||||
|
|
||||||
from PyQt5.QtCore import pyqtSignal, QObject
|
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.commands import cmdutils, cmdexc
|
||||||
from qutebrowser.utils import log, utils, qtutils, message, usertypes
|
from qutebrowser.utils import log, utils, qtutils, message, usertypes
|
||||||
|
|
||||||
@ -352,7 +352,8 @@ class KeyConfigParser(QObject):
|
|||||||
line))
|
line))
|
||||||
commands = [c.split(maxsplit=1)[0].strip() for c in commands]
|
commands = [c.split(maxsplit=1)[0].strip() for c in commands]
|
||||||
for cmd 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))
|
raise KeyConfigError("Invalid command '{}'!".format(cmd))
|
||||||
|
|
||||||
def _read_command(self, line):
|
def _read_command(self, line):
|
||||||
|
@ -61,6 +61,18 @@ Feature: Keyboard input
|
|||||||
And I run :bind <ctrl-test23>
|
And I run :bind <ctrl-test23>
|
||||||
Then the message "<ctrl-test23> is bound to 'message-info bar' in normal mode" should be shown
|
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
|
# :unbind
|
||||||
|
|
||||||
Scenario: Binding and unbinding a keychain
|
Scenario: Binding and unbinding a keychain
|
||||||
|
@ -214,7 +214,7 @@ class TestKeyConfigParser:
|
|||||||
|
|
||||||
"""Test config.parsers.keyconf.KeyConfigParser."""
|
"""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.
|
"""Test various command bindings.
|
||||||
|
|
||||||
See https://github.com/The-Compiler/qutebrowser/issues/615
|
See https://github.com/The-Compiler/qutebrowser/issues/615
|
||||||
@ -222,6 +222,7 @@ class TestKeyConfigParser:
|
|||||||
Args:
|
Args:
|
||||||
cmdline_test: A pytest fixture which provides testcases.
|
cmdline_test: A pytest fixture which provides testcases.
|
||||||
"""
|
"""
|
||||||
|
config_stub.data = {'aliases': []}
|
||||||
kcp = keyconf.KeyConfigParser(None, None)
|
kcp = keyconf.KeyConfigParser(None, None)
|
||||||
kcp._cur_section = 'normal'
|
kcp._cur_section = 'normal'
|
||||||
if cmdline_test.valid:
|
if cmdline_test.valid:
|
||||||
|
Loading…
Reference in New Issue
Block a user