Merge pull request #950 from ZyX-I/bufwinnr-segments

Add buffer and window number segments
This commit is contained in:
Nikolai Aleksandrovich Pavlov 2014-08-03 13:38:45 +04:00
commit 3983e9f711
3 changed files with 38 additions and 0 deletions

View File

@ -14,6 +14,8 @@
"position": "information:additional",
"single_tab": "line_current",
"many_tabs": "line_current",
"bufnr": "information:unimportant",
"winnr": "information:unimportant",
"tabnr": "file_directory"
}
}

View File

@ -504,6 +504,30 @@ def tabnr(pl, segment_info, show_current=False):
return str(tabnr)
@requires_segment_info
def bufnr(pl, segment_info, show_current=False):
'''Show buffer number
:param bool show_current:
If False do not show current window number.
'''
bufnr = segment_info['bufnr']
if show_current or bufnr != vim.current.buffer.number:
return str(bufnr)
@requires_segment_info
def winnr(pl, segment_info, show_current=False):
'''Show window number
:param bool show_current:
If False do not show current window number.
'''
winnr = segment_info['winnr']
if show_current or winnr != vim.current.window.number:
return str(winnr)
def single_tab(pl, single_text='Bufs', multiple_text='Tabs'):
'''Show one text if there is only one tab and another if there are many

View File

@ -793,6 +793,18 @@ class TestVim(TestCase):
self.assertEqual(vim.tabnr(pl=pl, segment_info=segment_info, show_current=True), '1')
self.assertEqual(vim.tabnr(pl=pl, segment_info=segment_info, show_current=False), None)
def test_bufnr(self):
pl = Pl()
segment_info = vim_module._get_segment_info()
self.assertEqual(vim.bufnr(pl=pl, segment_info=segment_info, show_current=True), str(segment_info['bufnr']))
self.assertEqual(vim.bufnr(pl=pl, segment_info=segment_info, show_current=False), None)
def test_winnr(self):
pl = Pl()
segment_info = vim_module._get_segment_info()
self.assertEqual(vim.winnr(pl=pl, segment_info=segment_info, show_current=True), str(segment_info['winnr']))
self.assertEqual(vim.winnr(pl=pl, segment_info=segment_info, show_current=False), None)
def test_single_tab(self):
pl = Pl()
single_tab = partial(vim.single_tab, pl=pl)