From 2acefc9ac9aef84babc26580c389e371dc1ac94b Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 3 Aug 2014 12:18:52 +0400 Subject: [PATCH] Add tabbuflister and buflister listers --- .../config_files/themes/vim/tabline.json | 3 +- powerline/segments/vim.py | 47 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/powerline/config_files/themes/vim/tabline.json b/powerline/config_files/themes/vim/tabline.json index 7fbea655..28e67c1c 100644 --- a/powerline/config_files/themes/vim/tabline.json +++ b/powerline/config_files/themes/vim/tabline.json @@ -4,12 +4,13 @@ "left": [ { "type": "segment_list", - "name": "tablister", + "name": "tabbuflister", "segments": [ { "name": "tabnr", "after": " ", "draw_soft_divider": false, + "exclude_modes": ["tab", "buf"], "priority": 5 }, { diff --git a/powerline/segments/vim.py b/powerline/segments/vim.py index 538a4ac8..5a973ff1 100644 --- a/powerline/segments/vim.py +++ b/powerline/segments/vim.py @@ -548,3 +548,50 @@ def tablister(pl, segment_info): ) 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)