Fix remaining :bind/:unbind issues

This commit is contained in:
Florian Bruhin 2017-06-19 18:30:24 +02:00
parent f434f955c2
commit 23d30d4fc0
2 changed files with 26 additions and 23 deletions

View File

@ -143,8 +143,7 @@ class NewKeyConfig:
def _prepare(self, key, mode): def _prepare(self, key, mode):
"""Make sure the given mode exists and normalize the key.""" """Make sure the given mode exists and normalize the key."""
if mode not in val.bindings.commands: if mode not in val.bindings.commands:
raise configexc.KeybindingError( raise configexc.KeybindingError("Invalid mode {}!".format(mode))
"Invalid mode {} while binding {}!".format(mode, key))
if utils.is_special_key(key): if utils.is_special_key(key):
# <Ctrl-t>, <ctrl-T>, and <ctrl-t> should be considered equivalent # <Ctrl-t>, <ctrl-T>, and <ctrl-t> should be considered equivalent
return utils.normalize_keystr(key) return utils.normalize_keystr(key)
@ -158,14 +157,12 @@ class NewKeyConfig:
try: try:
results = parser.parse_all(command) results = parser.parse_all(command)
except cmdexc.Error as e: except cmdexc.Error as e:
# FIXME: conf good message?
raise configexc.KeybindingError("Invalid command: {}".format(e)) raise configexc.KeybindingError("Invalid command: {}".format(e))
for result in results: for result in results:
try: try:
result.cmd.validate_mode(usertypes.KeyMode[mode]) result.cmd.validate_mode(usertypes.KeyMode[mode])
except cmdexc.PrerequisitesError as e: except cmdexc.PrerequisitesError as e:
# FIXME: conf good message?
raise configexc.KeybindingError(str(e)) raise configexc.KeybindingError(str(e))
bindings = val.bindings.commands bindings = val.bindings.commands
@ -180,11 +177,13 @@ class NewKeyConfig:
def unbind(self, key, *, mode='normal'): def unbind(self, key, *, mode='normal'):
"""Unbind the given key in the given mode.""" """Unbind the given key in the given mode."""
key = self._prepare(key, mode) key = self._prepare(key, mode)
bindings = val.bindings.commands
try: try:
del val.bindings.commands[mode][key] del bindings[mode][key]
except KeyError: except KeyError:
raise configexc.KeybindingError("Unknown binding {}".format(key)) raise configexc.KeybindingError("Can't find binding '{}' in section '{}'!"
val.bindings.commands = val.bindings.commands # FIXME:conf .format(key, mode))
val.bindings.commands = bindings # FIXME:conf
def get_command(self, key, mode): def get_command(self, key, mode):
"""Get the command for a given key (or None).""" """Get the command for a given key (or None)."""

View File

@ -14,7 +14,7 @@ Feature: Keyboard input
Scenario: Binding an invalid command Scenario: Binding an invalid command
When I run :bind test02 abcd When I run :bind test02 abcd
Then the error "Invalid command 'abcd'!" should be shown Then the error "abcd: no such command" should be shown
Scenario: Binding with invalid mode. Scenario: Binding with invalid mode.
When I run :bind --mode abcd test03 message-info test03 When I run :bind --mode abcd test03 message-info test03
@ -24,7 +24,7 @@ Feature: Keyboard input
When I run :bind test04 message-info test04 When I run :bind test04 message-info test04
And I run :bind test04 message-info test04-2 And I run :bind test04 message-info test04-2
And I press the keys "test04" And I press the keys "test04"
Then the error "Duplicate keychain test04 - use --force to override!" should be shown Then the error "Duplicate key test04 - use --force to override!" should be shown
And the message "test04" should be shown And the message "test04" should be shown
Scenario: Double-binding with --force Scenario: Double-binding with --force
@ -50,30 +50,32 @@ Feature: Keyboard input
Scenario: Binding special keys with differing case (issue 1544) Scenario: Binding special keys with differing case (issue 1544)
When I run :bind <ctrl-test21> message-info test01 When I run :bind <ctrl-test21> message-info test01
And I run :bind <Ctrl-Test21> message-info test01 And I run :bind <Ctrl-Test21> message-info test01
Then the error "Duplicate keychain <ctrl-test21> - use --force to override!" should be shown Then the error "Duplicate key <ctrl+test21> - use --force to override!" should be shown
Scenario: Print a special binding with differing case (issue 1544) Scenario: Print a special binding with differing case (issue 1544)
When I run :bind <Ctrl-Test22> message-info foo When I run :bind <Ctrl-Test22> message-info foo
And I run :bind <ctrl-test22> And I run :bind <ctrl-test22>
Then the message "<ctrl-test22> is bound to 'message-info foo' in normal mode" should be shown Then the message "<ctrl+test22> is bound to 'message-info foo' in normal mode" should be shown
Scenario: Overriding a special binding with differing case (issue 816) Scenario: Overriding a special binding with differing case (issue 816)
When I run :bind <ctrl-test23> message-info foo When I run :bind <ctrl-test23> message-info foo
And I run :bind --force <Ctrl-Test23> message-info bar And I run :bind --force <Ctrl-Test23> message-info bar
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 ## FIXME:conf
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 # Scenario: Binding to an alias
When I run :set aliases 'mib' 'message-info baz' # When I run :set aliases 'mib' 'message-info baz'
And I run :bind <test26> mib # And I run :bind test25 mib
And I run :bind <test26> # And I press the keys "test25"
Then the message "<test26> is bound to 'mib' in normal mode" should be shown # 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
Scenario: Binding with an unsupported mode Scenario: Binding with an unsupported mode
When I run :bind --mode=caret test27 rl-unix-filename-rubout When I run :bind --mode=caret test27 rl-unix-filename-rubout
@ -83,7 +85,9 @@ Feature: Keyboard input
Scenario: Binding and unbinding a keychain Scenario: Binding and unbinding a keychain
When I run :bind test09 message-error test09 When I run :bind test09 message-error test09
And I wait for "Config option changed: *" in the log
And I run :unbind test09 And I run :unbind test09
And I wait for "Config option changed: *" in the log
And I press the keys "test09" And I press the keys "test09"
Then "test09" should not be logged Then "test09" should not be logged
@ -105,7 +109,7 @@ Feature: Keyboard input
When I run :bind <ctrl-test24> message-error test09 When I run :bind <ctrl-test24> message-error test09
And I run :unbind <Ctrl-Test24> And I run :unbind <Ctrl-Test24>
When I run :bind <ctrl-test24> When I run :bind <ctrl-test24>
Then the message "<ctrl-test24> is unbound in normal mode" should be shown Then the message "<ctrl+test24> is unbound in normal mode" should be shown
# :clear-keychain # :clear-keychain