Merge pull request #1491 from johnmiked15/feature/tabline_updates

Tabline and bufferlister updates
This commit is contained in:
Nikolai Aleksandrovich Pavlov 2015-11-15 06:30:11 +03:00
commit 649757af1b
5 changed files with 55 additions and 25 deletions

View File

@ -23,16 +23,25 @@
"csv:column_number": "line_current",
"csv:column_name": "line_current_symbol",
"tab:background": "background",
"tab:divider": "background:divider",
"tab_nc:modified_indicator": "modified_indicator",
"tab_nc:file_directory": "information:unimportant",
"tab_nc:file_name": "tab_nc:file_directory",
"tab_nc:tabnr": "tab_nc:file_directory",
"buf_nc:file_directory": "tab_nc:file_directory",
"buf_nc:file_name": "tab_nc:file_name",
"buf_nc:bufnr": "tab_nc:tabnr",
"buf_nc:file_name": "buf_nc:file_directory",
"buf_nc:bufnr": "buf_nc:file_directory",
"buf_nc:modified_indicator": "tab_nc:modified_indicator",
"buf_nc_mod:file_directory": "tab_nc:file_directory",
"buf_nc_mod:file_name": "buf_nc_mod:file_directory",
"buf_nc_mod:bufnr": "buf_nc_mod:file_directory",
"buf_nc_mod:modified_indicator": "tab_nc:modified_indicator",
"commandt:label": "file_name",
"commandt:background": "background",
"commandt:finder": "file_name",

View File

@ -67,7 +67,7 @@
},
{
"type": "string",
"highlight_groups": ["background"],
"highlight_groups": ["tab:background"],
"draw_soft_divider": false,
"draw_hard_divider": false,
"width": "auto"

View File

@ -2,7 +2,7 @@
from __future__ import (unicode_literals, division, absolute_import, print_function)
from powerline.theme import requires_segment_info
from powerline.bindings.vim import (current_tabpage, list_tabpages, vim_getbufoption)
from powerline.bindings.vim import (current_tabpage, list_tabpages)
try:
import vim
@ -49,7 +49,10 @@ def tablister(pl, segment_info, **kwargs):
return (
(lambda tabpage, prefix: (
tabpage_updated_segment_info(segment_info, tabpage),
add_multiplier(tabpage, {'highlight_group_prefix': prefix})
add_multiplier(tabpage, {
'highlight_group_prefix': prefix,
'divider_highlight_group': 'tab:divider'
})
))(tabpage, 'tab' if tabpage == cur_tabpage else 'tab_nc')
for tabpage in list_tabpages()
)
@ -75,7 +78,8 @@ def bufferlister(pl, segment_info, show_unlisted=False, **kwargs):
and ``bufnr`` keys set to buffer-specific ones, ``window``, ``winnr`` and
``window_id`` keys set to None.
Adds either ``buf:`` or ``buf_nc:`` prefix to all segment highlight groups.
Adds one of ``buf:``, ``buf_nc:``, ``buf_mod:``, or ``buf_nc_mod``
prefix to all segment highlight groups.
:param bool show_unlisted:
True if unlisted buffers should be shown as well. Current buffer is
@ -89,22 +93,31 @@ def bufferlister(pl, segment_info, show_unlisted=False, **kwargs):
return dct
return (
(
buf_segment_info,
add_multiplier(buf_segment_info['buffer'], {'highlight_group_prefix': prefix})
(lambda buffer, current, modified: (
buffer_updated_segment_info(segment_info, buffer),
add_multiplier(buffer, {
'highlight_group_prefix': '{0}{1}'.format(current, modified),
'divider_highlight_group': 'tab:divider'
})
))(
buffer,
'buf' if buffer is cur_buffer else 'buf_nc',
'_mod' if int(vim.eval('getbufvar({0}, \'&modified\')'.format(buffer.number))) > 0 else ''
)
for buf_segment_info, prefix in (
(
buffer_updated_segment_info(
segment_info,
buffer
),
('buf' if buffer is cur_buffer else 'buf_nc')
)
for buffer in vim.buffers
) if (
buf_segment_info['buffer'] is cur_buffer
for buffer in vim.buffers if (
buffer is cur_buffer
or show_unlisted
or int(vim_getbufoption(buf_segment_info, 'buflisted'))
# We can't use vim_getbufoption(segment_info, 'buflisted')
# here for performance reasons. Querying the buffer options
# through the vim python module's option attribute caused
# vim to think it needed to update the tabline for every
# keystroke after any event that changed the buffer's
# options.
#
# Using the vim module's eval method to directly use the
# buflisted(nr) vim method instead does not cause vim to
# update the tabline after every keystroke, but rather after
# events that would change that status. Fixes #1281
or int(vim.eval('buflisted(%s)' % buffer.number)) > 0
)
)

View File

@ -16,7 +16,7 @@ catch
cquit
endtry
if result isnot# '%1T%#Pl_247_10395294_236_3158064_NONE# 1 ./abc  %2T2 ./def %#Pl_236_3158064_240_5789784_NONE# %3T%#Pl_250_12369084_240_5789784_NONE#3 ./%#Pl_231_16777215_240_5789784_bold#ghi %#Pl_240_5789784_236_3158064_NONE# %T%#Pl_231_16777215_236_3158064_NONE#                                         %#Pl_252_13684944_236_3158064_NONE# %#Pl_235_2500134_252_13684944_bold# Tabs '
if result isnot# '%1T%#Pl_247_10395294_236_3158064_NONE# 1 ./abc %#Pl_244_8421504_236_3158064_NONE# %2T%#Pl_247_10395294_236_3158064_NONE#2 ./def %#Pl_236_3158064_240_5789784_NONE# %3T%#Pl_250_12369084_240_5789784_NONE#3 ./%#Pl_231_16777215_240_5789784_bold#ghi %#Pl_240_5789784_236_3158064_NONE# %T%#Pl_231_16777215_236_3158064_NONE#                                         %#Pl_252_13684944_236_3158064_NONE# %#Pl_235_2500134_252_13684944_bold# Tabs '
call writefile(['Unexpected tabline', result], 'message.fail')
cquit
endif
@ -30,7 +30,7 @@ catch
cquit
endtry
if result isnot# '%T%#Pl_247_10395294_236_3158064_NONE# 1 ./abc  2 ./def %#Pl_236_3158064_240_5789784_NONE# %#Pl_250_12369084_240_5789784_NONE#3 ./%#Pl_231_16777215_240_5789784_bold#ghi %#Pl_240_5789784_236_3158064_NONE# %#Pl_231_16777215_236_3158064_NONE#                                         %#Pl_252_13684944_236_3158064_NONE# %#Pl_235_2500134_252_13684944_bold# Bufs '
if result isnot# '%T%#Pl_247_10395294_236_3158064_NONE# 1 ./abc %#Pl_244_8421504_236_3158064_NONE# %#Pl_247_10395294_236_3158064_NONE#2 ./def %#Pl_236_3158064_240_5789784_NONE# %#Pl_250_12369084_240_5789784_NONE#3 ./%#Pl_231_16777215_240_5789784_bold#ghi %#Pl_240_5789784_236_3158064_NONE# %#Pl_231_16777215_236_3158064_NONE#                                         %#Pl_252_13684944_236_3158064_NONE# %#Pl_235_2500134_252_13684944_bold# Bufs '
call writefile(['Unexpected tabline (2)', result], 'message.fail')
cquit
endif
@ -42,7 +42,7 @@ catch
call writefile(['Exception while evaluating &tabline (3)', v:exception], 'message.fail')
endtry
if result isnot# '%T%#Pl_247_10395294_236_3158064_NONE# 1 ./abc  2 ./def %#Pl_236_3158064_240_5789784_NONE# %#Pl_250_12369084_240_5789784_NONE#3 ./%#Pl_231_16777215_240_5789784_bold#ghi %#Pl_240_5789784_236_3158064_NONE# %#Pl_231_16777215_236_3158064_NONE#                                         %#Pl_252_13684944_236_3158064_NONE# %#Pl_235_2500134_252_13684944_bold# Bufs '
if result isnot# '%T%#Pl_247_10395294_236_3158064_NONE# 1 ./abc %#Pl_244_8421504_236_3158064_NONE# %#Pl_247_10395294_236_3158064_NONE#2 ./def %#Pl_236_3158064_240_5789784_NONE# %#Pl_250_12369084_240_5789784_NONE#3 ./%#Pl_231_16777215_240_5789784_bold#ghi %#Pl_240_5789784_236_3158064_NONE# %#Pl_231_16777215_236_3158064_NONE#                                         %#Pl_252_13684944_236_3158064_NONE# %#Pl_235_2500134_252_13684944_bold# Bufs '
call writefile(['Unexpected tabline (3)', result], 'message.fail')
cquit
endif

View File

@ -265,6 +265,14 @@ def eval(expr):
import os
assert os.path.basename(current.buffer.name).startswith('NERD_tree_')
return '/usr/include'
elif expr.startswith('getbufvar('):
import re
match = re.match(r'^getbufvar\((\d+), ["\'](.+)["\']\)$', expr)
if not match:
raise NotImplementedError(expr)
bufnr = int(match.group(1))
varname = match.group(2)
return _emul_getbufvar(bufnr, varname)
elif expr == 'tabpagenr()':
return current.tabpage.number
elif expr == 'tabpagenr("$")':