Make nerdtree segment use bufvar_exists

This commit is contained in:
ZyX 2014-01-11 11:51:41 +04:00
parent 64a32a910b
commit e8b2054868
2 changed files with 15 additions and 4 deletions

View File

@ -66,6 +66,18 @@ else:
else:
raise KeyError(varname)
if hasattr(vim, 'vars') and vim.vvars['version'] > 703:
def bufvar_exists(buffer, varname):
buffer = buffer or vim.current.buffer
return varname in buffer.vars
else:
def bufvar_exists(buffer, varname): # NOQA
if not buffer or buffer.number == vim.current.buffer.number:
return vim.eval('exists("b:{0}")'.format(varname))
else:
return vim.eval('has_key(getbufvar({0}, ""), {1})'
.format(buffer.number, varname))
if hasattr(vim, 'options'):
def vim_getbufoption(info, option):
return info['buffer'].options[option]

View File

@ -5,7 +5,7 @@ try:
except ImportError:
vim = object() # NOQA
from powerline.bindings.vim import getbufvar
from powerline.bindings.vim import bufvar_exists
from powerline.segments.vim import window_cached
@ -15,9 +15,8 @@ def nerdtree(pl):
Highlight groups used: ``nerdtree.path`` or ``file_name``.
'''
ntr = getbufvar('%', 'NERDTreeRoot')
if not ntr:
return
if not bufvar_exists(None, 'NERDTreeRoot'):
return None
path_str = vim.eval('getbufvar("%", "NERDTreeRoot").path.str()')
return [{
'contents': path_str,