From c45747a3b859fc24232175fe4448b989206a38a5 Mon Sep 17 00:00:00 2001
From: ZyX <kp-pav@ya.ru>
Date: Fri, 15 Feb 2013 21:06:08 +0400
Subject: [PATCH] Ease E858/E860 errors debugging

E858: Eval did not return a valid python object
E860: Eval did not return a valid python 3 object
---
 .../source/installation/troubleshooting-common.rst | 14 ++++++++++++++
 powerline/bindings/vim/plugin/powerline.vim        |  8 ++++----
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/docs/source/installation/troubleshooting-common.rst b/docs/source/installation/troubleshooting-common.rst
index 5570bfc3..80c95a3c 100644
--- a/docs/source/installation/troubleshooting-common.rst
+++ b/docs/source/installation/troubleshooting-common.rst
@@ -30,3 +30,17 @@ My vim statusline is hidden/only appears in split windows!
 ----------------------------------------------------------
 
 * Make sure that you have ``set laststatus=2`` in your :file:`vimrc`.
+
+I get E858/E860 error in vim (Eval did not return a valid python object)
+--------------------------------------------------------------------------
+
+* You need to make ``pyeval()`` display python stack trace. There is currently 
+  a patch for this, but it was not merged into main vim tree, thus you will have 
+  to use different approach: reproduce the error with
+
+    .. code-block:: sh
+
+       vim --cmd "let g:powerline_debugging_pyeval=1" ...
+
+  and then use the stack trace to search for existing issues or to create a new 
+  one.
diff --git a/powerline/bindings/vim/plugin/powerline.vim b/powerline/bindings/vim/plugin/powerline.vim
index 8cf4c32c..82dd082f 100644
--- a/powerline/bindings/vim/plugin/powerline.vim
+++ b/powerline/bindings/vim/plugin/powerline.vim
@@ -38,13 +38,13 @@ catch
 endtry
 exec s:powerline_pycmd 'powerline = Powerline("vim", segment_info={})'
 
-if exists('*'. s:powerline_pyeval)
+if !get(g:, 'powerline_debugging_pyeval') && exists('*'. s:powerline_pyeval)
 	let s:pyeval = function(s:powerline_pyeval)
 else
 	exec s:powerline_pycmd 'import json, vim'
-	function! s:pyeval(e)
-		exec s:powerline_pycmd 'vim.command("return " + json.dumps(eval(vim.eval("a:e"))))'
-	endfunction
+	exec "function! s:pyeval(e)\n".
+		\	s:powerline_pycmd." vim.command('return ' + json.dumps(eval(vim.eval('a:e'))))\n".
+		\"endfunction"
 endif
 
 function! Powerline(winnr, current)