mirror of
https://github.com/davidhalter/jedi-vim.git
synced 2025-12-07 19:24:36 +08:00
Load only default/forced py_version, changed names and variable type
1. Changed pycmd: renamed to py_version, changed type, resulting in ...#force_py_version = <int> (2 or 3) 2. Changed structure of initialization, changes broke functionality (<sfile> behaviour changes inside a function) 3. Cleaned up.
This commit is contained in:
@@ -193,20 +193,23 @@ function! jedi#complete_opened()
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
function! jedi#force_pycmd(pycmd)
|
function! jedi#force_py_version(py_version)
|
||||||
let g:jedi#force_pycmd = a:pycmd
|
let g:jedi#force_py_version = a:py_version
|
||||||
exec("command! -nargs=1 Python ".a:pycmd." <args>")
|
if g:jedi#force_py_version == 2
|
||||||
|
command! -nargs=1 Python python <args>
|
||||||
|
execute 'pyfile '.s:script_path.'/initialize.py'
|
||||||
|
elseif g:jedi#force_py_version == 3
|
||||||
|
command! -nargs=1 Python python3 <args>
|
||||||
|
execute 'py3file '.s:script_path.'/initialize.py'
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
function! jedi#force_pycmd_switch()
|
function! jedi#force_py_version_switch()
|
||||||
if g:jedi#force_pycmd == 'python'
|
if g:jedi#force_py_version == 2
|
||||||
call jedi#force_pycmd('python3')
|
call jedi#force_py_version(3)
|
||||||
elseif g:jedi#force_pycmd == 'python3'
|
elseif g:jedi#force_py_version == 3
|
||||||
call jedi#force_pycmd('python')
|
call jedi#force_py_version(2)
|
||||||
else
|
|
||||||
" to be able switch from custom pycmd's
|
|
||||||
call jedi#force_pycmd('python')
|
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@@ -246,7 +249,7 @@ let s:settings = {
|
|||||||
\ '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'"
|
\ 'force_py_version': 2
|
||||||
\ }
|
\ }
|
||||||
|
|
||||||
|
|
||||||
@@ -273,10 +276,16 @@ call s:init()
|
|||||||
" Python initialization
|
" Python initialization
|
||||||
" ------------------------------------------------------------------------
|
" ------------------------------------------------------------------------
|
||||||
|
|
||||||
if has('python')
|
let s:script_path = fnameescape(expand('<sfile>:p:h:h'))
|
||||||
|
|
||||||
|
if has('python') && has('python3')
|
||||||
|
call jedi#force_py_version(g:jedi#force_py_version)
|
||||||
|
elseif has('python')
|
||||||
command! -nargs=1 Python python <args>
|
command! -nargs=1 Python python <args>
|
||||||
|
execute 'pyfile '.s:script_path.'/initialize.py'
|
||||||
elseif has('python3')
|
elseif has('python3')
|
||||||
command! -nargs=1 Python python3 <args>
|
command! -nargs=1 Python python3 <args>
|
||||||
|
execute 'py3file '.s:script_path.'/initialize.py'
|
||||||
else
|
else
|
||||||
if !exists("g:jedi#squelch_py_warning")
|
if !exists("g:jedi#squelch_py_warning")
|
||||||
echomsg "Error: jedi-vim requires vim compiled with +python"
|
echomsg "Error: jedi-vim requires vim compiled with +python"
|
||||||
@@ -284,18 +293,6 @@ else
|
|||||||
finish
|
finish
|
||||||
end
|
end
|
||||||
|
|
||||||
if has('python') && has('python3')
|
|
||||||
call jedi#force_pycmd(g:jedi#force_pycmd)
|
|
||||||
endif
|
|
||||||
|
|
||||||
" 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
|
|
||||||
|
|
||||||
if has('python3')
|
|
||||||
execute 'py3file '.fnameescape(expand('<sfile>:p:h:h')).'/initialize.py'
|
|
||||||
endif
|
|
||||||
|
|
||||||
"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,7 +38,7 @@ 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|
|
6.11. force_py_version |g:jedi#force_py_version|
|
||||||
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|
|
||||||
@@ -405,23 +405,23 @@ 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*
|
6.11. `g:jedi#force_py_version` *g:jedi#force_py_version*
|
||||||
|
|
||||||
If you have installed both python 2 and python 3, you can force which one jedi
|
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
|
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.
|
will be used for every jedi call to the respective python interpreter.
|
||||||
The variable can be set in the .vimrc like this:
|
The variable can be set in the .vimrc like this to force python 3:
|
||||||
|
|
||||||
let g:jedi#force_pycmd = 'python3'
|
let g:jedi#force_py_version = 3
|
||||||
|
|
||||||
This variable can be switched during runtime using the following function:
|
This variable can be switched during runtime using the following function:
|
||||||
Function: `jedi#force_pycmd_switch()`
|
Function: `jedi#force_py_version_switch()`
|
||||||
|
|
||||||
or set directly using this function, which has the same name as the variable:
|
or set directly using this function, which has the same name as the variable:
|
||||||
Function: `jedi#force_pycmd(pycmd)`
|
Function: `jedi#force_py_version(py_version)`
|
||||||
|
|
||||||
Options: 'python' or 'python3'
|
Options: 2 or 3
|
||||||
Default: 'python'
|
Default: 2
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
7. Testing *jedi-vim-testing*
|
7. Testing *jedi-vim-testing*
|
||||||
|
|||||||
@@ -9,14 +9,15 @@ import vim
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
# vim.command('echom expand("<sfile>:p:h:h")')
|
# vim.command('echom expand("<sfile>:p:h:h")') # broken, <sfile> inside function
|
||||||
sys.path.insert(0, os.path.join(vim.eval('expand("<sfile>:p:h:h")'), 'jedi'))
|
# sys.path.insert(0, os.path.join(vim.eval('expand("<sfile>:p:h:h")'), 'jedi'))
|
||||||
|
sys.path.insert(0, os.path.join(vim.eval('s:script_path'), 'jedi'))
|
||||||
|
|
||||||
# to display errors correctly
|
# to display errors correctly
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
# update the sys path to include the jedi_vim script
|
# update the sys path to include the jedi_vim script
|
||||||
sys.path.insert(1, vim.eval('expand("<sfile>:p:h:h")'))
|
sys.path.insert(0, vim.eval('s:script_path'))
|
||||||
try:
|
try:
|
||||||
import jedi_vim
|
import jedi_vim
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
|||||||
Reference in New Issue
Block a user