Merge pull request #938 from ZyX-I/noloadpython

Do not let powerline trigger loading wrong python
This commit is contained in:
Nikolai Aleksandrovich Pavlov 2014-07-29 16:14:38 +04:00
commit 074e118d70
3 changed files with 61 additions and 9 deletions

View File

@ -127,8 +127,24 @@ hand: ``powerline`` is installed and run just like any other plugin using
call vam#ActivateAddons(['powerline']) call vam#ActivateAddons(['powerline'])
Note: when using Gentoo ebuild you need to specify ``USE=vim`` to enable .. note::
powerline. If you use supplied :file:`powerline.vim` file to load powerline there are
additional configuration variables available: ``g:powerline_pycmd`` and
``g:powerline_pyeval``. First sets command used to load powerline: expected
values are ``"py"`` and ``"py3"``. Second sets function used in statusline,
expected values are ``"pyeval"`` and ``"py3eval"``.
If ``g:powerline_pycmd`` is set to the one of the expected values then
``g:powerline_pyeval`` will be set accordingly. If it is set to some other
value then you must also set ``g:powerline_pyeval``. Powerline will not
check that Vim is compiled with Python support if you set
``g:powerline_pycmd`` to an unexpected value.
These values are to be used to specify the only Python that is to be loaded
if you have both versions: Vim may disable loading one python version if
other was already loaded. They should also be used if you have two python
versions able to load simultaneously, but with powerline installed only for
python-3 version.
Shell prompts Shell prompts
------------- -------------

View File

@ -3,7 +3,41 @@ if exists('g:powerline_loaded')
endif endif
let g:powerline_loaded = 1 let g:powerline_loaded = 1
if !has('python') && !has('python3') if exists('g:powerline_pycmd')
let s:pycmd = substitute(g:powerline_pycmd, '\v\C^(py)%[thon](3?)$', '\1\2', '')
if s:pycmd is# 'py'
let s:has_python = has('python')
let s:pyeval = get(g:, 'powerline_pyeval', 'pyeval')
elseif s:pycmd is# 'py3'
let s:has_python = has('python3')
let s:pyeval = 'py3eval'
let s:pyeval = get(g:, 'powerline_pyeval', 'py3eval')
else
if !exists('g:powerline_pyeval')
echohl ErrorMsg
echomsg 'g:powerline_pycmd was set to an unknown values, but g:powerline_pyeval'
echomsg 'was not set. You should either set g:powerline_pycmd to "py3" or "py",'
echomsg 'specify g:powerline_pyeval explicitly or unset both and let powerline'
echomsg 'figure them out.'
echohl None
finish
endif
let s:pyeval = g:powerline_pyeval
let s:has_python = 1
endif
elseif has('python')
let s:has_python = 1
let s:pycmd = 'py'
let s:pyeval = get(g:, 'powerline_pyeval', 'pyeval')
elseif has('python3')
let s:has_python = 1
let s:pycmd = 'py3'
let s:pyeval = get(g:, 'powerline_pyeval', 'py3eval')
else
let s:has_python = 0
endif
if !s:has_python
if !exists('g:powerline_no_python_error') if !exists('g:powerline_no_python_error')
echohl ErrorMsg echohl ErrorMsg
echomsg 'You need vim compiled with Python 2.6, 2.7 or 3.2 and later support' echomsg 'You need vim compiled with Python 2.6, 2.7 or 3.2 and later support'
@ -13,9 +47,7 @@ if !has('python') && !has('python3')
endif endif
finish finish
endif endif
unlet s:has_python
let s:pycmd = substitute(get(g:, 'powerline_pycmd', has('python') ? 'py' : 'py3'), '\v^(py)%[thon](3?)$', '\1\2', '')
let s:pyeval = get(g:, 'powerline_pyeval', s:pycmd.'eval')
let s:import_cmd = 'from powerline.vim import setup as powerline_setup' let s:import_cmd = 'from powerline.vim import setup as powerline_setup'
try try
@ -81,9 +113,12 @@ finally
endif endif
endtry endtry
let s:can_replace_pyeval = !exists('g:powerline_pyeval')
execute s:pycmd 'import vim' execute s:pycmd 'import vim'
execute s:pycmd 'powerline_setup(pyeval=vim.eval("s:pyeval"), pycmd=vim.eval("s:pycmd"))' execute s:pycmd 'powerline_setup(pyeval=vim.eval("s:pyeval"), pycmd=vim.eval("s:pycmd"), can_replace_pyeval=int(vim.eval("s:can_replace_pyeval")))'
execute s:pycmd 'del powerline_setup' execute s:pycmd 'del powerline_setup'
unlet s:can_replace_pyeval
unlet s:pycmd unlet s:pycmd
unlet s:pyeval unlet s:pyeval

View File

@ -155,16 +155,17 @@ class VimPowerline(Powerline):
__main__.__dict__))) __main__.__dict__)))
def setup(pyeval=None, pycmd=None): def setup(pyeval=None, pycmd=None, can_replace_pyeval=True):
import sys import sys
import __main__ import __main__
if not pyeval: if not pyeval:
pyeval = 'pyeval' if sys.version_info < (3,) else 'py3eval' pyeval = 'pyeval' if sys.version_info < (3,) else 'py3eval'
can_replace_pyeval = True
if not pycmd: if not pycmd:
pycmd = 'python' if sys.version_info < (3,) else 'python3' pycmd = 'python' if sys.version_info < (3,) else 'python3'
# pyeval() and vim.bindeval were both introduced in one patch # pyeval() and vim.bindeval were both introduced in one patch
if not hasattr(vim, 'bindeval'): if not hasattr(vim, 'bindeval') and can_replace_pyeval:
vim.command((''' vim.command(('''
function! PowerlinePyeval(e) function! PowerlinePyeval(e)
{pycmd} powerline.pyeval() {pycmd} powerline.pyeval()