Add support for unknown modes in Vim

Closes #1715
This commit is contained in:
Foo 2017-02-06 16:32:45 +03:00
parent 8e0bed9677
commit 19659189da
2 changed files with 17 additions and 6 deletions

View File

@ -87,18 +87,27 @@ def window_cached(func):
def mode(pl, segment_info, override=None):
'''Return the current vim mode.
If mode (returned by ``mode()`` VimL function, see ``:h mode()`` in Vim)
consists of multiple characters and necessary mode is not known to powerline
then it will fall back to mode with last character(s) ignored.
:param dict override:
dict for overriding default mode strings, e.g. ``{ 'n': 'NORM' }``
'''
mode = segment_info['mode']
if mode == 'nc':
return None
if not override:
return vim_modes[mode]
try:
return override[mode]
except KeyError:
return vim_modes[mode]
while mode:
try:
if not override:
return vim_modes[mode]
try:
return override[mode]
except KeyError:
return vim_modes[mode]
except KeyError:
mode = mode[:-1]
return 'BUG'
@window_cached

View File

@ -1159,6 +1159,8 @@ class TestVim(TestCase):
self.assertEqual(self.vim.mode(pl=pl, segment_info=segment_info, override={'n': 'NORM'}), 'NORM')
with vim_module._with('mode', 'i') as segment_info:
self.assertEqual(self.vim.mode(pl=pl, segment_info=segment_info), 'INSERT')
with vim_module._with('mode', 'i\0') as segment_info:
self.assertEqual(self.vim.mode(pl=pl, segment_info=segment_info), 'INSERT')
with vim_module._with('mode', chr(ord('V') - 0x40)) as segment_info:
self.assertEqual(self.vim.mode(pl=pl, segment_info=segment_info), 'V-BLCK')
self.assertEqual(self.vim.mode(pl=pl, segment_info=segment_info, override={'^V': 'VBLK'}), 'VBLK')