Show default keybinding in :bind completion

This commit is contained in:
Panagiotis Ktistakis 2017-11-26 13:34:18 +02:00
parent 03a9cbdfb4
commit e05dabefdf
2 changed files with 18 additions and 6 deletions

View File

@ -77,17 +77,26 @@ def bind(key, *, info):
key: the key being bound. key: the key being bound.
""" """
model = completionmodel.CompletionModel(column_widths=(20, 60, 20)) model = completionmodel.CompletionModel(column_widths=(20, 60, 20))
cmd_text = info.keyconf.get_command(key, 'normal') data = []
cmd_text = info.keyconf.get_command(key, 'normal')
if cmd_text: if cmd_text:
parser = runners.CommandParser() parser = runners.CommandParser()
try: try:
cmd = parser.parse(cmd_text).cmd cmd = parser.parse(cmd_text).cmd
except cmdexc.NoSuchCommandError: except cmdexc.NoSuchCommandError:
data = [(cmd_text, 'Invalid command!', key)] data.append((cmd_text, '(Current) Invalid command!', key))
else: else:
data = [(cmd_text, cmd.desc, key)] data.append((cmd_text, '(Current) {}'.format(cmd.desc), key))
model.add_category(listcategory.ListCategory("Current", data))
cmd_text = info.keyconf.get_command(key, 'normal', default=True)
if cmd_text:
parser = runners.CommandParser()
cmd = parser.parse(cmd_text).cmd
data.append((cmd_text, '(Default) {}'.format(cmd.desc), key))
if data:
model.add_category(listcategory.ListCategory("Current/Default", data))
cmdlist = util.get_cmd_completions(info, include_hidden=True, cmdlist = util.get_cmd_completions(info, include_hidden=True,
include_aliases=True) include_aliases=True)

View File

@ -162,10 +162,13 @@ class KeyConfig:
cmd_to_keys[cmd].insert(0, key) cmd_to_keys[cmd].insert(0, key)
return cmd_to_keys return cmd_to_keys
def get_command(self, key, mode): def get_command(self, key, mode, default=False):
"""Get the command for a given key (or None).""" """Get the command for a given key (or None)."""
key = self._prepare(key, mode) key = self._prepare(key, mode)
bindings = self.get_bindings_for(mode) if default:
bindings = dict(val.bindings.default[mode])
else:
bindings = self.get_bindings_for(mode)
return bindings.get(key, None) return bindings.get(key, None)
def bind(self, key, command, *, mode, save_yaml=False): def bind(self, key, command, *, mode, save_yaml=False):