improve indentation of #117

This commit is contained in:
David Halter
2013-05-18 21:53:44 +04:30
parent 34bf4479d8
commit e8e1cc7d47

View File

@@ -54,47 +54,50 @@ if g:jedi#auto_initialization
endif endif
fun! Pyedit(cmd, args) fun! Pyedit(cmd, args)
" args are the same as for the :edit command
" cmd: one of edit, split, vsplit, tabedit, ...
py << EOF py << EOF
import vim # args are the same as for the :edit command
import jedi # cmd: one of edit, split, vsplit, tabedit, ...
import os.path as osp if 1:
from shlex import split as shsplit import vim
import jedi
import os.path as osp
from shlex import split as shsplit
cmd = vim.eval('a:cmd') cmd = vim.eval('a:cmd')
args = shsplit(vim.eval('a:args')) args = shsplit(vim.eval('a:args'))
text = 'import %s' % args.pop() text = 'import %s' % args.pop()
scr = jedi.Script(text, 1, len(text), '') scr = jedi.Script(text, 1, len(text), '')
try: try:
path = scr.goto()[0].module_path path = scr.goto()[0].module_path
except IndexError: except IndexError:
path = None path = None
if path and osp.isfile(path): if path and osp.isfile(path):
cmd_args = ' '.join([a.replace(' ', '\\ ') for a in args]) cmd_args = ' '.join([a.replace(' ', '\\ ') for a in args])
vim.command('%s %s %s' % (cmd, cmd_args , path.replace(' ', '\ '))) vim.command('%s %s %s' % (cmd, cmd_args , path.replace(' ', '\ ')))
EOF EOF
endfun endfun
fun! Pyedit_comp(argl, cmdl, pos) fun! Pyedit_comp(argl, cmdl, pos)
py << EOF py << EOF
import vim if 1:
import re import vim
import json import re
argl = vim.eval('a:argl') import json
try: argl = vim.eval('a:argl')
import jedi try:
except ImportError as err: import jedi
print('Pyedit completion requires jedi module: https://github.com/davidhalter/jedi') except ImportError as err:
comps = [] print('Pyedit completion requires jedi module: https://github.com/davidhalter/jedi')
else: comps = []
text = 'import %s' % argl else:
script=jedi.Script(text, 1, len(text), '') text = 'import %s' % argl
comps = [ '%s%s' % (argl, c.complete) for c in script.complete()] script=jedi.Script(text, 1, len(text), '')
vim.command("let comps = '%s'" % '\n'.join(comps)) comps = [ '%s%s' % (argl, c.complete) for c in script.complete()]
vim.command("let comps = '%s'" % '\n'.join(comps))
EOF EOF
return comps return comps
endfun endfun
command! -nargs=1 -complete=custom,Pyedit_comp Pyedit :call Pyedit('edit', <q-args>) 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 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 Pyvsplit :call Pyedit('vsplit', <q-args>)