From e8b2054868a9ef80183c217e71f933c56c8cf617 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 11 Jan 2014 11:51:41 +0400 Subject: [PATCH] Make nerdtree segment use bufvar_exists --- powerline/bindings/vim/__init__.py | 12 ++++++++++++ powerline/segments/plugin/nerdtree.py | 7 +++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/powerline/bindings/vim/__init__.py b/powerline/bindings/vim/__init__.py index 6705222d..ef8643ff 100644 --- a/powerline/bindings/vim/__init__.py +++ b/powerline/bindings/vim/__init__.py @@ -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] diff --git a/powerline/segments/plugin/nerdtree.py b/powerline/segments/plugin/nerdtree.py index 39eb5aec..a8e6ad85 100644 --- a/powerline/segments/plugin/nerdtree.py +++ b/powerline/segments/plugin/nerdtree.py @@ -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,