From cdaa417e8c24ca8d59bde11b27ff7c6859d71088 Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Fri, 31 Oct 2014 19:18:28 +0100 Subject: Fix python setup: Fix issue for users not using python. --- runtime/doc/nvim_python.txt | 2 +- runtime/plugin/python_setup.vim | 60 ----------------------------------------- runtime/python_setup.vim | 60 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 61 deletions(-) delete mode 100644 runtime/plugin/python_setup.vim create mode 100644 runtime/python_setup.vim diff --git a/runtime/doc/nvim_python.txt b/runtime/doc/nvim_python.txt index b618562900..9e6f408657 100644 --- a/runtime/doc/nvim_python.txt +++ b/runtime/doc/nvim_python.txt @@ -31,7 +31,7 @@ simple step-by-step: loaded: > if has('nvim') - runtime! plugin/python_setup.vim + runtime! python_setup.vim endif < Most python plugins created for Vim 7.3 should work after these steps. diff --git a/runtime/plugin/python_setup.vim b/runtime/plugin/python_setup.vim deleted file mode 100644 index 0070885958..0000000000 --- a/runtime/plugin/python_setup.vim +++ /dev/null @@ -1,60 +0,0 @@ -" Nvim plugin for loading python extensions via an external interpreter -if exists("did_python_setup") || &cp - finish -endif -let did_python_setup = 1 - -" Prefix for naming things and displaying output. -let s:plugin_name = 'Python setup' - -function! s:ShowError(message) - echohl ErrorMsg - echomsg s:plugin_name . ': ' . a:message . '.' - echohl None -endfunction - -let s:get_version = - \ ' -c "import sys; sys.stdout.write(str(sys.version_info[0]) + '. - \ '\".\" + str(sys.version_info[1]))"' - -let s:supported = ['2.6', '2.7'] - -" To load the python host a python 2 executable must be available -if exists('python_interpreter') - \ && executable(g:python_interpreter) - \ && index(s:supported, system(g:python_interpreter.s:get_version)) >= 0 - let s:python_interpreter = g:python_interpreter -elseif executable('python') - \ && index(s:supported, system('python'.s:get_version)) >= 0 - let s:python_interpreter = 'python' -elseif executable('python2') - \ && index(s:supported, system('python2'.s:get_version)) >= 0 - " In some distros, python3 is the default python - let s:python_interpreter = 'python2' -else - call s:ShowError('No python interpreter found') - finish -endif - -" Make sure we pick correct python version on path. -let s:python_interpreter_path = exepath(s:python_interpreter) -let s:python_version = systemlist(s:python_interpreter_path . ' --version')[0] - -" Execute python, import neovim and print a string. If import_result matches -" the printed string, we can probably start the host -let s:import_result = system(s:python_interpreter_path . - \ ' -c "import neovim, sys; sys.stdout.write(\"ok\")"') -if s:import_result != 'ok' - call s:ShowError('No neovim module found for ' . s:python_version) - finish -endif - -let s:pyhost_id = rpcstart(s:python_interpreter_path, - \ ['-c', 'import neovim; neovim.start_host()']) -" Evaluate an expression in the script host as an additional sanity check, and -" to block until all providers have been registered(or else some plugins loaded -" by the user's vimrc would not get has('python') == 1 -if rpcrequest(s:pyhost_id, 'python_eval', '"o"+"k"') != 'ok' || !has('python') - call s:ShowError('Something went wrong setting up ' . s:python_version) - call rpcstop(s:pyhost_id) -endif diff --git a/runtime/python_setup.vim b/runtime/python_setup.vim new file mode 100644 index 0000000000..0070885958 --- /dev/null +++ b/runtime/python_setup.vim @@ -0,0 +1,60 @@ +" Nvim plugin for loading python extensions via an external interpreter +if exists("did_python_setup") || &cp + finish +endif +let did_python_setup = 1 + +" Prefix for naming things and displaying output. +let s:plugin_name = 'Python setup' + +function! s:ShowError(message) + echohl ErrorMsg + echomsg s:plugin_name . ': ' . a:message . '.' + echohl None +endfunction + +let s:get_version = + \ ' -c "import sys; sys.stdout.write(str(sys.version_info[0]) + '. + \ '\".\" + str(sys.version_info[1]))"' + +let s:supported = ['2.6', '2.7'] + +" To load the python host a python 2 executable must be available +if exists('python_interpreter') + \ && executable(g:python_interpreter) + \ && index(s:supported, system(g:python_interpreter.s:get_version)) >= 0 + let s:python_interpreter = g:python_interpreter +elseif executable('python') + \ && index(s:supported, system('python'.s:get_version)) >= 0 + let s:python_interpreter = 'python' +elseif executable('python2') + \ && index(s:supported, system('python2'.s:get_version)) >= 0 + " In some distros, python3 is the default python + let s:python_interpreter = 'python2' +else + call s:ShowError('No python interpreter found') + finish +endif + +" Make sure we pick correct python version on path. +let s:python_interpreter_path = exepath(s:python_interpreter) +let s:python_version = systemlist(s:python_interpreter_path . ' --version')[0] + +" Execute python, import neovim and print a string. If import_result matches +" the printed string, we can probably start the host +let s:import_result = system(s:python_interpreter_path . + \ ' -c "import neovim, sys; sys.stdout.write(\"ok\")"') +if s:import_result != 'ok' + call s:ShowError('No neovim module found for ' . s:python_version) + finish +endif + +let s:pyhost_id = rpcstart(s:python_interpreter_path, + \ ['-c', 'import neovim; neovim.start_host()']) +" Evaluate an expression in the script host as an additional sanity check, and +" to block until all providers have been registered(or else some plugins loaded +" by the user's vimrc would not get has('python') == 1 +if rpcrequest(s:pyhost_id, 'python_eval', '"o"+"k"') != 'ok' || !has('python') + call s:ShowError('Something went wrong setting up ' . s:python_version) + call rpcstop(s:pyhost_id) +endif -- cgit