Skip to content

Commit

Permalink
Merge pull request #11 from infokiller/master
Browse files Browse the repository at this point in the history
Make the plugin work in neovim.
  • Loading branch information
wmvanvliet authored Dec 16, 2018
2 parents 3072915 + 396ef2d commit 66d9935
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
26 changes: 18 additions & 8 deletions autoload/jupyter.vim
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
"=============================================================================
" Python Initialization:
"-----------------------------------------------------------------------------
" Neovim doesn't have the pythonx command, so we define a new command Pythonx
" that works for both vim and neovim.
if has('pythonx')
command! -nargs=+ Pythonx pythonx <args>
elseif has('python3')
command! -nargs=+ Pythonx python3 <args>
elseif has('python')
command! -nargs=+ Pythonx python <args>
endif

" See ~/.vim/bundle/jedi-vim/autoload/jedi.vim for initialization routine
function! s:init_python() abort
let s:init_outcome = 0
Expand All @@ -23,7 +33,7 @@ function! s:init_python() abort

" Try running lines via python, which will set script variable
try
execute 'pythonx exec('''.escape(join(init_lines, '\n'), "'").''')'
execute 'Pythonx exec('''.escape(join(init_lines, '\n'), "'").''')'
catch
throw printf('[jupyter-vim] s:init_python: failed to run Python for initialization: %s.', v:exception)
endtry
Expand Down Expand Up @@ -56,7 +66,7 @@ endfunction
" Vim -> Python Public Functions:
"-----------------------------------------------------------------------------
function! jupyter#Connect() abort
pythonx jupyter_vim.connect_to_kernel()
Pythonx jupyter_vim.connect_to_kernel()
endfunction

function! jupyter#JupyterCd(...) abort
Expand All @@ -69,21 +79,21 @@ function! jupyter#RunFile(...) abort
" filename is the last argument on the command line
let l:flags = (a:0 > 1) ? join(a:000[:-2], ' ') : ''
let l:filename = a:0 ? a:000[-1] : expand("%:p")
pythonx jupyter_vim.run_file(flags=vim.eval('l:flags'),
Pythonx jupyter_vim.run_file(flags=vim.eval('l:flags'),
\ filename=vim.eval('l:filename'))
endfunction

function! jupyter#SendCell() abort
pythonx jupyter_vim.run_cell()
Pythonx jupyter_vim.run_cell()
endfunction

function! jupyter#SendCode(code) abort
" NOTE: 'run_command' gives more checks than just raw 'send'
pythonx jupyter_vim.run_command(vim.eval('a:code'))
Pythonx jupyter_vim.run_command(vim.eval('a:code'))
endfunction

function! jupyter#SendRange() range abort
execute a:firstline . ',' . a:lastline . 'pythonx jupyter_vim.send_range()'
execute a:firstline . ',' . a:lastline . 'Pythonx jupyter_vim.send_range()'
endfunction

function! jupyter#SendCount(count) abort
Expand Down Expand Up @@ -113,11 +123,11 @@ function! jupyter#TerminateKernel(kill, ...) abort
let l:sig='SIGTERM'
endif
" Check signal here?
execute 'pythonx jupyter_vim.signal_kernel(jupyter_vim.signal.'.l:sig.')'
execute 'Pythonx jupyter_vim.signal_kernel(jupyter_vim.signal.'.l:sig.')'
endfunction

function! jupyter#UpdateShell() abort
pythonx jupyter_vim.update_console_msgs()
Pythonx jupyter_vim.update_console_msgs()
endfunction

"-----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion plugin/jupyter.vim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"
"=============================================================================

if !has('pythonx') || &cp
if !(has('pythonx') || has('python') || has('python3')) || &cp
finish
endif

Expand Down

0 comments on commit 66d9935

Please sign in to comment.