Add tabbuflister and buflister listers

This commit is contained in:
ZyX 2014-08-03 12:18:52 +04:00
parent 85f252652e
commit 2acefc9ac9
2 changed files with 49 additions and 1 deletions

View File

@ -4,12 +4,13 @@
"left": [ "left": [
{ {
"type": "segment_list", "type": "segment_list",
"name": "tablister", "name": "tabbuflister",
"segments": [ "segments": [
{ {
"name": "tabnr", "name": "tabnr",
"after": " ", "after": " ",
"draw_soft_divider": false, "draw_soft_divider": false,
"exclude_modes": ["tab", "buf"],
"priority": 5 "priority": 5
}, },
{ {

View File

@ -548,3 +548,50 @@ def tablister(pl, segment_info):
) )
for tabpage in list_tabpages() for tabpage in list_tabpages()
] ]
def buffer_updated_segment_info(segment_info, buffer):
segment_info = segment_info.copy()
segment_info.update(
window=None,
winnr=None,
window_id=None,
buffer=buffer,
bufnr=buffer.number,
)
return segment_info
@requires_segment_info
def bufferlister(pl, segment_info):
'''List all buffers in segment_info format
Specifically generates a list of segment info dictionaries with ``buffer``
and ``bufnr`` keys set to buffer-specific ones, ``window``, ``winnr`` and
``window_id`` keys unset.
Sets segment ``mode`` to either ``buf`` (for current buffer) or ``nc``
(for all other buffers).
'''
cur_buffer = vim.current.buffer
cur_bufnr = cur_buffer.number
def add_multiplier(buffer, dct):
dct['priority_multiplier'] = 1 + (0.001 * abs(buffer.number - cur_bufnr))
return dct
return [
(
buffer_updated_segment_info(segment_info, buffer),
add_multiplier(buffer, {'mode': ('tab' if buffer == cur_buffer else 'nc')})
)
for buffer in vim.buffers
]
@requires_segment_info
def tabbuflister(*args, **kwargs):
if len(list_tabpages()) == 1:
return bufferlister(*args, **kwargs)
else:
return tablister(*args, **kwargs)