mirror of
https://github.com/davidhalter/jedi-vim.git
synced 2025-12-07 03:04:30 +08:00
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:
@@ -35,6 +35,7 @@ Stephen J. Fuhry (@fuhrysteve) <fuhrysteve@gmail.com>
|
|||||||
Sheng Yun (@ShengYun) <uewing@gmail.com>
|
Sheng Yun (@ShengYun) <uewing@gmail.com>
|
||||||
Yann Thomas-Gérard (@inside) <inside@gmail.com>
|
Yann Thomas-Gérard (@inside) <inside@gmail.com>
|
||||||
Colin Su (@littleq0903) <littleq0903@gmail.com>
|
Colin Su (@littleq0903) <littleq0903@gmail.com>
|
||||||
|
Arthur Jaron (@eyetracker)
|
||||||
|
|
||||||
|
|
||||||
@something are github user names.
|
@something are github user names.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
" ------------------------------------------------------------------------
|
" ------------------------------------------------------------------------
|
||||||
" functions that call python code
|
" functions that call python code
|
||||||
" ------------------------------------------------------------------------
|
" ------------------------------------------------------------------------
|
||||||
function! jedi#goto_assignments()
|
function! jedi#goto_assignments()
|
||||||
@@ -193,6 +193,23 @@ function! jedi#complete_opened()
|
|||||||
endfunction
|
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
|
" deprecations
|
||||||
@@ -207,18 +224,9 @@ let s:deprecations = {
|
|||||||
\ 'show_function_definition': 'show_call_signatures',
|
\ '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
|
" defaults for jedi-vim
|
||||||
" ------------------------------------------------------------------------
|
" ------------------------------------------------------------------------
|
||||||
|
|
||||||
let s:settings = {
|
let s:settings = {
|
||||||
\ 'use_tabs_not_buffers': 1,
|
\ 'use_tabs_not_buffers': 1,
|
||||||
\ 'use_splits_not_buffers': 1,
|
\ 'use_splits_not_buffers': 1,
|
||||||
@@ -237,15 +245,29 @@ let s:settings = {
|
|||||||
\ 'auto_close_doc': 1,
|
\ 'auto_close_doc': 1,
|
||||||
\ 'popup_select_first': 1,
|
\ 'popup_select_first': 1,
|
||||||
\ 'quickfix_window_height': 10,
|
\ '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
|
" Python initialization
|
||||||
@@ -262,27 +284,19 @@ else
|
|||||||
finish
|
finish
|
||||||
end
|
end
|
||||||
|
|
||||||
Python << PYTHONEOF
|
if has('python') && has('python3')
|
||||||
""" here we initialize the jedi stuff """
|
call jedi#force_pycmd(g:jedi#force_pycmd)
|
||||||
import vim
|
endif
|
||||||
|
|
||||||
# update the system path, to include the jedi path
|
" jedi_vim.py has to be imported for 'python' and 'python3' each
|
||||||
import sys
|
if has('python')
|
||||||
import os
|
execute 'pyfile '.fnameescape(expand('<sfile>:p:h:h')).'/initialize.py'
|
||||||
sys.path.insert(0, os.path.join(vim.eval('expand("<sfile>:p:h:h")'), 'jedi'))
|
endif
|
||||||
|
|
||||||
# to display errors correctly
|
if has('python3')
|
||||||
import traceback
|
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, speed=True, warnings=False, notices=False)
|
||||||
"Python jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout)
|
"Python jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout)
|
||||||
|
|
||||||
|
|||||||
@@ -38,11 +38,11 @@ Contents *jedi-vim-contents*
|
|||||||
6.8. squelch_py_warning |g:jedi#squelch_py_warning|
|
6.8. squelch_py_warning |g:jedi#squelch_py_warning|
|
||||||
6.9. completions_enable |g:jedi#completions_enable|
|
6.9. completions_enable |g:jedi#completions_enable|
|
||||||
6.10. use_splits_not_buffers |g:jedi#use_splits_not_buffers|
|
6.10. use_splits_not_buffers |g:jedi#use_splits_not_buffers|
|
||||||
|
6.11. force_pycmd |g:jedi#force_pycmd|
|
||||||
7. Testing |jedi-vim-testing|
|
7. Testing |jedi-vim-testing|
|
||||||
8. Contributing |jedi-vim-contributing|
|
8. Contributing |jedi-vim-contributing|
|
||||||
9. License |jedi-vim-license|
|
9. License |jedi-vim-license|
|
||||||
|
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
1. Introduction *jedi-vim-introduction*
|
1. Introduction *jedi-vim-introduction*
|
||||||
|
|
||||||
@@ -404,6 +404,25 @@ direction which you want to open a split with.
|
|||||||
Options: top, left, right or bottom
|
Options: top, left, right or bottom
|
||||||
Default: "" (not enabled by default)
|
Default: "" (not enabled by default)
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
6.11. `g:jedi#force_pycmd` *g:jedi#force_pycmd*
|
||||||
|
|
||||||
|
If you have installed both python 2 and python 3, you can force which one jedi
|
||||||
|
should use by setting this variable. It forces the internal Vim command, which
|
||||||
|
will be used for every jedi call to the respective python interpreter.
|
||||||
|
The variable can be set in the .vimrc like this:
|
||||||
|
|
||||||
|
let g:jedi#force_pycmd = 'python3'
|
||||||
|
|
||||||
|
This variable can be switched during runtime using the following function:
|
||||||
|
Function: `jedi#force_pycmd_switch()`
|
||||||
|
|
||||||
|
or set directly using this function, which has the same name as the variable:
|
||||||
|
Function: `jedi#force_pycmd(pycmd)`
|
||||||
|
|
||||||
|
Options: 'python' or 'python3'
|
||||||
|
Default: 'python'
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
7. Testing *jedi-vim-testing*
|
7. Testing *jedi-vim-testing*
|
||||||
|
|
||||||
|
|||||||
25
initialize.py
Normal file
25
initialize.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
''' ------------------------------------------------------------------------
|
||||||
|
Python initialization
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
here we initialize the jedi stuff '''
|
||||||
|
|
||||||
|
import vim
|
||||||
|
|
||||||
|
# update the system path, to include the jedi path
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
# vim.command('echom expand("<sfile>:p:h:h")')
|
||||||
|
sys.path.insert(0, os.path.join(vim.eval('expand("<sfile>:p:h:h")'), 'jedi'))
|
||||||
|
|
||||||
|
# to display errors correctly
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
||||||
Reference in New Issue
Block a user