From fdf21feae1594ebf9e3c599c84429c38dfab0272 Mon Sep 17 00:00:00 2001 From: ZyX Date: Wed, 10 Sep 2014 08:33:39 +0400 Subject: [PATCH] Allow setting g:powerline_pyeval to PowerlinePyeval for testing --- powerline/vim.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/powerline/vim.py b/powerline/vim.py index d0123707..3c2ed492 100644 --- a/powerline/vim.py +++ b/powerline/vim.py @@ -2,6 +2,7 @@ from __future__ import (unicode_literals, division, absolute_import, print_function) import sys +import json from itertools import count @@ -11,9 +12,6 @@ from powerline.bindings.vim import vim_get_func, vim_getvar from powerline import Powerline, FailedUnicode from powerline.lib import mergedicts -if not hasattr(vim, 'bindeval'): - import json - def _override_from(config, override_varname): try: @@ -134,7 +132,7 @@ class VimPowerline(Powerline): set_pycmd(pycmd) # pyeval() and vim.bindeval were both introduced in one patch - if not hasattr(vim, 'bindeval') and can_replace_pyeval: + if (not hasattr(vim, 'bindeval') and can_replace_pyeval) or pyeval == 'PowerlinePyeval': vim.command((''' function! PowerlinePyeval(e) {pycmd} powerline.do_pyeval() @@ -245,14 +243,15 @@ class VimPowerline(Powerline): def new_window(self): return self.render(*self.win_idx(None)) - if not hasattr(vim, 'bindeval'): - # Method for PowerlinePyeval function. Is here to reduce the number of - # requirements to __main__ globals to just one powerline object - # (previously it required as well vim and json) - @staticmethod - def do_pyeval(): - import __main__ - vim.command('return ' + json.dumps(eval(vim.eval('a:e'), __main__.__dict__))) + @staticmethod + def do_pyeval(): + '''Evaluate python string passed to PowerlinePyeval + + Is here to reduce the number of requirements to __main__ globals to just + one powerline object (previously it required as well vim and json). + ''' + import __main__ + vim.command('return ' + json.dumps(eval(vim.eval('a:e'), __main__.__dict__))) def setup_components(self, components): if components is None: