From e8e1cc7d47e4fef092e902c98f7feda4291c16d2 Mon Sep 17 00:00:00 2001 From: David Halter Date: Sat, 18 May 2013 21:53:44 +0430 Subject: [PATCH] improve indentation of #117 --- plugin/jedi.vim | 67 ++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/plugin/jedi.vim b/plugin/jedi.vim index 75d0a8d..b891c8c 100644 --- a/plugin/jedi.vim +++ b/plugin/jedi.vim @@ -54,47 +54,50 @@ if g:jedi#auto_initialization 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 + # args are the same as for the :edit command + # cmd: one of edit, split, vsplit, tabedit, ... +if 1: + 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(' ', '\ '))) + 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)) +if 1: + 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 + return comps endfun + command! -nargs=1 -complete=custom,Pyedit_comp Pyedit :call Pyedit('edit', ) " command! -nargs=1 -complete=custom,Pyedit_comp Pysplit :call Pyedit('split', ) " command! -nargs=1 -complete=custom,Pyedit_comp Pyvsplit :call Pyedit('vsplit', )