Python alias works now

This commit is contained in:
David Halter
2013-01-07 00:28:37 +01:00
parent 7b60d00dbc
commit 3c55a4bed6
3 changed files with 25 additions and 24 deletions

View File

@@ -46,28 +46,7 @@ endfunction
" show_pydoc
" ------------------------------------------------------------------------
function! jedi#show_pydoc()
Python << PYTHONEOF
if 1:
script = jedi_vim.get_script()
try:
definitions = script.get_definition()
except jedi_vim.jedi.NotFoundError:
definitions = []
except Exception:
# print to stdout, will be in :messages
definitions = []
print("Exception, this shouldn't happen.")
print(traceback.format_exc())
if not definitions:
vim.command('return')
else:
docs = ['Docstring for %s\n%s\n%s' % (d.desc_with_module, '='*40, d.doc) if d.doc
else '|No Docstring for %s|' % d for d in definitions]
text = ('\n' + '-' * 79 + '\n').join(docs)
vim.command('let l:doc = %s' % repr(jedi_vim.PythonToVimStr(text)))
vim.command('let l:doc_lines = %s' % len(text.split('\n')))
PYTHONEOF
Python jedi_vim.show_pydoc()
if bufnr("__doc__") > 0
" If the __doc__ buffer is open in the current window, jump to it
silent execute "sbuffer ".bufnr("__doc__")

View File

@@ -52,9 +52,9 @@ if g:jedi#auto_initialization
endif
if has('python')
command! Python python
command! -nargs=1 Python python <args>
else
command! Python python3
command! -nargs=1 Python python3 <args>
end
" vim: set et ts=4:

View File

@@ -154,6 +154,28 @@ def goto(is_definition=False, is_related_name=False, no_output=False):
return definitions
def show_pydoc():
script = get_script()
try:
definitions = script.get_definition()
except jedi.NotFoundError:
definitions = []
except Exception:
# print to stdout, will be in :messages
definitions = []
print("Exception, this shouldn't happen.")
print(traceback.format_exc())
if not definitions:
vim.command('return')
else:
docs = ['Docstring for %s\n%s\n%s' % (d.desc_with_module, '='*40, d.doc) if d.doc
else '|No Docstring for %s|' % d for d in definitions]
text = ('\n' + '-' * 79 + '\n').join(docs)
vim.command('let l:doc = %s' % repr(PythonToVimStr(text)))
vim.command('let l:doc_lines = %s' % len(text.split('\n')))
def clear_func_def():
cursor = vim.current.window.cursor
e = vim.eval('g:jedi#function_definition_escape')