Commits

valloric  committed 6049a87

Fix bug with python3 support crashing Gundo

The recent change that introduced python3 support also made it the default
python version used for Gundo. This caused a problem with certain versions of
vim where upon toggling the Gundo window, we would be greeted with an error
message: "This Vim cannot execute :py3 after using :python"

This commit adds a g:gundo_prefer_python3 variable (default 0) that can be used
to set a preference for python3. By default, python2 will be used.

This also required moving the variable initialization code to the top, since
just evaluating `has('python3')` seems to trigger the vim error.

  • Participants
  • Parent commits 9524242

Comments (0)

Files changed (1)

File autoload/gundo.vim

     finish
 endif"}}}
 
-if has('python3')"{{{
-    let s:has_supported_python = 2
-elseif has('python')
-    let s:has_supported_python = 1
-else
-    let s:has_supported_python = 0
-endif
-
-if !s:has_supported_python
-    function! s:GundoDidNotLoad()
-        echohl WarningMsg|echomsg "Gundo requires Vim to be compiled with Python 2.4+"|echohl None
-    endfunction
-    command! -nargs=0 GundoToggle call s:GundoDidNotLoad()
-    finish
-endif"}}}
-
-let s:plugin_path = escape(expand('<sfile>:p:h'), '\')
-
 if !exists('g:gundo_width')"{{{
     let g:gundo_width = 45
 endif"}}}
 if !exists("g:gundo_close_on_revert")"{{{
     let g:gundo_close_on_revert = 0
 endif"}}}
+if !exists("g:gundo_prefer_python3")"{{{
+    let g:gundo_prefer_python3 = 0
+endif"}}}
 
+if has('python')"{{{
+    let s:has_supported_python = 1
+elseif g:gundo_prefer_python3 && has('python3')
+    let s:has_supported_python = 2
+else
+    let s:has_supported_python = 0
+endif
+
+if !s:has_supported_python
+    function! s:GundoDidNotLoad()
+        echohl WarningMsg|echomsg "Gundo requires Vim to be compiled with Python 2.4+"|echohl None
+    endfunction
+    command! -nargs=0 GundoToggle call s:GundoDidNotLoad()
+    finish
+endif"}}}
+
+let s:plugin_path = escape(expand('<sfile>:p:h'), '\')
 "}}}
 
 "{{{ Gundo utility functions
 
 function! s:GundoOpen()"{{{
     if !exists('g:gundo_py_loaded')
-	if s:has_supported_python == 2
+	if s:has_supported_python == 2 && g:gundo_prefer_python3
 	  exe 'py3file ' . s:plugin_path . '/gundo.py'
 	  python3 initPythonModule()
 	else
 "{{{ Gundo rendering
 
 function! s:GundoRenderGraph()"{{{
-    if s:has_supported_python == 2
+    if s:has_supported_python == 2 && g:gundo_prefer_python3
 	python3 GundoRenderGraph()
     else
 	python GundoRenderGraph()
 endfunction"}}}
 
 function! s:GundoRenderPreview()"{{{
-    if s:has_supported_python == 2
+    if s:has_supported_python == 2 && g:gundo_prefer_python3
 	python3 GundoRenderPreview()
     else
 	python GundoRenderPreview()
 endfunction"}}}
 
 function! s:GundoRenderChangePreview()"{{{
-    if s:has_supported_python == 2
+    if s:has_supported_python == 2 && g:gundo_prefer_python3
 	python3 GundoRenderChangePreview()
     else
 	python GundoRenderChangePreview()
 "{{{ Gundo undo/redo
 
 function! s:GundoRevert()"{{{
-    if s:has_supported_python == 2
+    if s:has_supported_python == 2 && g:gundo_prefer_python3
 	python3 GundoRevert()
     else
 	python GundoRevert()
 endfunction"}}}
 
 function! s:GundoPlayTo()"{{{
-    if s:has_supported_python == 2
+    if s:has_supported_python == 2 && g:gundo_prefer_python3
 	python3 GundoPlayTo()
     else
 	python GundoPlayTo()