From 3c79979c50d4cc1cdfcaaae18289cbbd567818fe Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 15 Apr 2015 15:06:57 +0200 Subject: [PATCH] Move functions used by jedi#init_python before it --- autoload/jedi.vim | 187 ++++++++++++++++++++++------------------------ 1 file changed, 89 insertions(+), 98 deletions(-) diff --git a/autoload/jedi.vim b/autoload/jedi.vim index 9fce4c9..553bef6 100644 --- a/autoload/jedi.vim +++ b/autoload/jedi.vim @@ -1,9 +1,56 @@ scriptencoding utf-8 +" ------------------------------------------------------------------------ +" Settings initialization +" ------------------------------------------------------------------------ +let s:deprecations = { + \ 'get_definition_command': 'goto_definitions_command', + \ 'goto_command': 'goto_assignments_command', + \ 'pydoc': 'documentation_command', + \ 'related_names_command': 'usages_command', + \ 'autocompletion_command': 'completions_command', + \ 'show_function_definition': 'show_call_signatures', +\ } + +let s:default_settings = { + \ 'use_tabs_not_buffers': 1, + \ 'use_splits_not_buffers': 1, + \ 'auto_initialization': 1, + \ 'auto_vim_configuration': 1, + \ 'goto_assignments_command': "'g'", + \ 'completions_command': "''", + \ 'goto_definitions_command': "'d'", + \ 'call_signatures_command': "'n'", + \ 'usages_command': "'n'", + \ 'rename_command': "'r'", + \ 'popup_on_dot': 1, + \ 'documentation_command': "'K'", + \ 'show_call_signatures': 1, + \ 'call_signature_escape': "'=`='", + \ 'auto_close_doc': 1, + \ 'popup_select_first': 1, + \ 'quickfix_window_height': 10, + \ 'completions_enabled': 1, + \ 'force_py_version': "'auto'" +\ } + +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 + endif +endfor + +for [key, val] in items(s:default_settings) + if !exists('g:jedi#'.key) + exe 'let g:jedi#'.key.' = '.val + endif +endfor + + " ------------------------------------------------------------------------ " Python initialization " ------------------------------------------------------------------------ - let s:script_path = fnameescape(expand(':p:h:h')) function! s:init_python() @@ -39,7 +86,7 @@ function! s:init_python() if !has('nvim') || has('python'.(s:def_py == 2 ? '' : s:def_py)) return jedi#force_py_version(s:def_py) endif - end + endif if has('python') call jedi#setup_py_version(2) @@ -47,7 +94,7 @@ function! s:init_python() call jedi#setup_py_version(3) else throw "jedi-vim requires Vim with support for Python 2 or 3." - end + endif return 1 endfunction @@ -68,6 +115,45 @@ function! jedi#init_python() return s:_init_python endfunction + +function! jedi#setup_py_version(py_version) + if a:py_version == 2 + let cmd_init = 'pyfile' + let cmd_exec = 'python' + elseif a:py_version == 3 + let cmd_init = 'py3file' + let cmd_exec = 'python3' + else + throw "jedi#setup_py_version: invalid py_version: ".a:py_version + endif + + try + execute cmd_init.' '.s:script_path.'/initialize.py' + execute 'command! -nargs=1 PythonJedi '.cmd_exec.' ' + return 1 + catch + throw "jedi#setup_py_version: ".v:exception + endtry +endfunction + + +function! jedi#force_py_version(py_version) + let g:jedi#force_py_version = a:py_version + return jedi#setup_py_version(a:py_version) +endfunction + + +function! jedi#force_py_version_switch() + if g:jedi#force_py_version == 2 + call jedi#force_py_version(3) + elseif g:jedi#force_py_version == 3 + call jedi#force_py_version(2) + else + throw "Don't know how to switch from ".g:jedi#force_py_version."!" + endif +endfunction + + if !jedi#init_python() " Do not define any functions when Python initialization failed. finish @@ -328,101 +414,6 @@ function! jedi#complete_opened() endfunction -function! jedi#setup_py_version(py_version) - if a:py_version == 2 - let cmd_init = 'pyfile' - let cmd_exec = 'python' - elseif a:py_version == 3 - let cmd_init = 'py3file' - let cmd_exec = 'python3' - else - throw "jedi#setup_py_version: invalid py_version: ".a:py_version - endif - - try - execute cmd_init.' '.s:script_path.'/initialize.py' - execute 'command! -nargs=1 PythonJedi '.cmd_exec.' ' - return 1 - catch - throw "jedi#setup_py_version: ".v:exception - endtry -endfunction - - -function! jedi#force_py_version(py_version) - let g:jedi#force_py_version = a:py_version - return jedi#setup_py_version(a:py_version) -endfunction - - -function! jedi#force_py_version_switch() - if g:jedi#force_py_version == 2 - call jedi#force_py_version(3) - elseif g:jedi#force_py_version == 3 - call jedi#force_py_version(2) - else - throw "Don't know how to switch from ".g:jedi#force_py_version."!" - endif -endfunction - - -" ------------------------------------------------------------------------ -" deprecations -" ------------------------------------------------------------------------ -let s:deprecations = { - \ 'get_definition_command': 'goto_definitions_command', - \ 'goto_command': 'goto_assignments_command', - \ 'pydoc': 'documentation_command', - \ 'related_names_command': 'usages_command', - \ 'autocompletion_command': 'completions_command', - \ 'show_function_definition': 'show_call_signatures', -\ } - -" ------------------------------------------------------------------------ -" defaults for jedi-vim -" ------------------------------------------------------------------------ -let s:settings = { - \ 'use_tabs_not_buffers': 1, - \ 'use_splits_not_buffers': 1, - \ 'auto_initialization': 1, - \ 'auto_vim_configuration': 1, - \ 'goto_assignments_command': "'g'", - \ 'completions_command': "''", - \ 'goto_definitions_command': "'d'", - \ 'call_signatures_command': "'n'", - \ 'usages_command': "'n'", - \ 'rename_command': "'r'", - \ 'popup_on_dot': 1, - \ 'documentation_command': "'K'", - \ 'show_call_signatures': 1, - \ 'call_signature_escape': "'=`='", - \ 'auto_close_doc': 1, - \ 'popup_select_first': 1, - \ 'quickfix_window_height': 10, - \ 'completions_enabled': 1, - \ 'force_py_version': "'auto'" -\ } - - -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 - endif - 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() - - "PythonJedi jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout, speed=True, warnings=False, notices=False) "PythonJedi jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout)