mirror of
https://github.com/davidhalter/jedi-vim.git
synced 2025-12-08 03:24:47 +08:00
Merge branch 'master' of git://github.com/coot/jedi-vim into pyedit
This commit is contained in:
@@ -104,7 +104,7 @@ endfunction
|
|||||||
function! jedi#add_goto_window()
|
function! jedi#add_goto_window()
|
||||||
set lazyredraw
|
set lazyredraw
|
||||||
cclose
|
cclose
|
||||||
execute 'belowright copen 3'
|
execute 'belowright copen '.g:jedi#quickfix_window_height
|
||||||
set nolazyredraw
|
set nolazyredraw
|
||||||
if g:jedi#use_tabs_not_buffers == 1
|
if g:jedi#use_tabs_not_buffers == 1
|
||||||
map <buffer> <CR> :call jedi#goto_window_on_enter()<CR>
|
map <buffer> <CR> :call jedi#goto_window_on_enter()<CR>
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ let s:settings = {
|
|||||||
\ 'show_function_definition': 1,
|
\ 'show_function_definition': 1,
|
||||||
\ 'function_definition_escape': "'≡'",
|
\ 'function_definition_escape': "'≡'",
|
||||||
\ 'auto_close_doc': 1,
|
\ 'auto_close_doc': 1,
|
||||||
\ 'popup_select_first': 1
|
\ 'popup_select_first': 1,
|
||||||
|
\ 'quickfix_window_height': 10
|
||||||
\ }
|
\ }
|
||||||
|
|
||||||
for [key, val] in items(s:settings)
|
for [key, val] in items(s:settings)
|
||||||
@@ -51,4 +52,51 @@ if g:jedi#auto_initialization
|
|||||||
" order of invocation.
|
" order of invocation.
|
||||||
autocmd FileType Python setlocal omnifunc=jedi#complete switchbuf=useopen " needed for pydoc
|
autocmd FileType Python setlocal omnifunc=jedi#complete switchbuf=useopen " needed for pydoc
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
fun! Pyedit(cmd, args)
|
||||||
|
" args are the same as for the :edit command
|
||||||
|
" cmd: one of edit, split, vsplit, tabedit, ...
|
||||||
|
py << EOF
|
||||||
|
import vim
|
||||||
|
import jedi
|
||||||
|
import os.path as osp
|
||||||
|
from shlex import split as shsplit
|
||||||
|
|
||||||
|
cmd = vim.eval('a:cmd')
|
||||||
|
args = shsplit(vim.eval('a:args'))
|
||||||
|
text = 'import %s' % args.pop()
|
||||||
|
scr = jedi.Script(text, 1, len(text), '')
|
||||||
|
try:
|
||||||
|
path = scr.goto()[0].module_path
|
||||||
|
except IndexError:
|
||||||
|
path = None
|
||||||
|
if path and osp.isfile(path):
|
||||||
|
cmd_args = ' '.join([a.replace(' ', '\\ ') for a in args])
|
||||||
|
vim.command('%s %s %s' % (cmd, cmd_args , path.replace(' ', '\ ')))
|
||||||
|
EOF
|
||||||
|
endfun
|
||||||
|
|
||||||
|
fun! Pyedit_comp(argl, cmdl, pos)
|
||||||
|
py << EOF
|
||||||
|
import vim
|
||||||
|
import re
|
||||||
|
import json
|
||||||
|
argl = vim.eval('a:argl')
|
||||||
|
try:
|
||||||
|
import jedi
|
||||||
|
except ImportError as err:
|
||||||
|
print('Pyedit completion requires jedi module: https://github.com/davidhalter/jedi')
|
||||||
|
comps = []
|
||||||
|
else:
|
||||||
|
text = 'import %s' % argl
|
||||||
|
script=jedi.Script(text, 1, len(text), '')
|
||||||
|
comps = [ '%s%s' % (argl, c.complete) for c in script.complete()]
|
||||||
|
vim.command("let comps = '%s'" % '\n'.join(comps))
|
||||||
|
EOF
|
||||||
|
return comps
|
||||||
|
endfun
|
||||||
|
command! -nargs=1 -complete=custom,Pyedit_comp Pyedit :call Pyedit('edit', <q-args>)
|
||||||
|
" command! -nargs=1 -complete=custom,Pyedit_comp Pysplit :call Pyedit('split', <q-args>)
|
||||||
|
" command! -nargs=1 -complete=custom,Pyedit_comp Pyvsplit :call Pyedit('vsplit', <q-args>)
|
||||||
|
" command! -nargs=1 -complete=custom,Pyedit_comp Pytabe :call Pyedit('tabe', <q-args>)
|
||||||
" vim: set et ts=4:
|
" vim: set et ts=4:
|
||||||
|
|||||||
Reference in New Issue
Block a user