Implemented: force python 2 or 3 with ability to switch during runtime

Simultaneous python2 and python3 support, switchable during runtime
calling a function as well as setting a variable in .vimrc! Closes
issues #200 and #210 (which gave the idea for this commit, thank you
@Shtucer).
This commit is contained in:
Asa Jay
2013-12-13 20:51:24 +01:00
parent eceba1e675
commit 3ad63c9458
4 changed files with 94 additions and 35 deletions

View File

@@ -1,4 +1,4 @@
" ------------------------------------------------------------------------
" ------------------------------------------------------------------------
" functions that call python code
" ------------------------------------------------------------------------
function! jedi#goto_assignments()
@@ -193,6 +193,23 @@ function! jedi#complete_opened()
endfunction
function! jedi#force_pycmd(pycmd)
let g:jedi#force_pycmd = a:pycmd
exec("command! -nargs=1 Python ".a:pycmd." <args>")
endfunction
function! jedi#force_pycmd_switch()
if g:jedi#force_pycmd == 'python'
call jedi#force_pycmd('python3')
elseif g:jedi#force_pycmd == 'python3'
call jedi#force_pycmd('python')
else
" to be able switch from custom pycmd's
call jedi#force_pycmd('python')
endif
endfunction
" ------------------------------------------------------------------------
" deprecations
@@ -207,18 +224,9 @@ let s:deprecations = {
\ 'show_function_definition': 'show_call_signatures',
\ }
for [key, val] in items(s:deprecations)
if exists('g:jedi#'.key)
echom "'g:jedi#".key."' is deprecated. Please use 'g:jedi#".val."' instead. Sorry for the inconvenience."
exe 'let g:jedi#'.val.' = g:jedi#'.key
end
endfor
" ------------------------------------------------------------------------
" defaults for jedi-vim
" ------------------------------------------------------------------------
let s:settings = {
\ 'use_tabs_not_buffers': 1,
\ 'use_splits_not_buffers': 1,
@@ -237,15 +245,29 @@ let s:settings = {
\ 'auto_close_doc': 1,
\ 'popup_select_first': 1,
\ 'quickfix_window_height': 10,
\ 'completions_enabled': 1
\ 'completions_enabled': 1,
\ 'force_pycmd': "'python'"
\ }
for [key, val] in items(s:settings)
if !exists('g:jedi#'.key)
exe 'let g:jedi#'.key.' = '.val
endif
endfor
function! s:init()
for [key, val] in items(s:deprecations)
if exists('g:jedi#'.key)
echom "'g:jedi#".key."' is deprecated. Please use 'g:jedi#".val."' instead. Sorry for the inconvenience."
exe 'let g:jedi#'.val.' = g:jedi#'.key
end
endfor
for [key, val] in items(s:settings)
if !exists('g:jedi#'.key)
exe 'let g:jedi#'.key.' = '.val
endif
endfor
endfunction
call s:init()
" ------------------------------------------------------------------------
" Python initialization
@@ -262,27 +284,19 @@ else
finish
end
Python << PYTHONEOF
""" here we initialize the jedi stuff """
import vim
if has('python') && has('python3')
call jedi#force_pycmd(g:jedi#force_pycmd)
endif
# update the system path, to include the jedi path
import sys
import os
sys.path.insert(0, os.path.join(vim.eval('expand("<sfile>:p:h:h")'), 'jedi'))
" jedi_vim.py has to be imported for 'python' and 'python3' each
if has('python')
execute 'pyfile '.fnameescape(expand('<sfile>:p:h:h')).'/initialize.py'
endif
# to display errors correctly
import traceback
if has('python3')
execute 'py3file '.fnameescape(expand('<sfile>:p:h:h')).'/initialize.py'
endif
# update the sys path to include the jedi_vim script
sys.path.insert(1, vim.eval('expand("<sfile>:p:h:h")'))
try:
import jedi_vim
except ImportError:
vim.command('echoerr "Please install Jedi if you want to use jedi_vim."')
sys.path.pop(1)
PYTHONEOF
"Python jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout, speed=True, warnings=False, notices=False)
"Python jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout)