@@ -311,7 +311,15 @@ def disconnect():
311311def get_doc (word , level = 0 ):
312312 if kc is None :
313313 return ["Not connected to IPython, cannot query: %s" % word ]
314- msg_id = object_info (word , detail_level = level )
314+ if word .startswith ('%' ): # request for magic documentation
315+ request = ('_doc = get_ipython().object_inspect("{0}", '
316+ 'detail_level={1})' ).format (word , level )
317+ try :
318+ msg_id = send (request , silent = True , user_variables = ['_doc' ])
319+ except TypeError : # change in IPython 3.0+
320+ msg_id = send (request , silent = True , user_expressions = {'_doc' :'_doc' })
321+ else :
322+ msg_id = object_info (word , detail_level = level )
315323 doc = get_doc_msg (msg_id )
316324 # get around unicode problems when interfacing with vim
317325 return [d .encode (vim_encoding ) for d in doc ]
@@ -331,6 +339,18 @@ def get_doc_msg(msg_id):
331339 # timeout occurred
332340 return ["no reply from IPython kernel" ]
333341
342+ if 'evalue' in content :
343+ return b
344+
345+ doc = None
346+ if 'user_variables' in content :
347+ doc = content ['user_variables' ]['_doc' ]
348+ elif 'user_expressions' in content :
349+ doc = content ['user_expressions' ]['_doc' ]
350+ if doc :
351+ import ast
352+ content = ast .literal_eval (doc ['data' ]['text/plain' ])
353+
334354 if not content ['found' ]:
335355 return b
336356
@@ -370,7 +390,7 @@ def get_doc_buffer(level=0, word=None):
370390 echo (repr (word )+ " not found" ,"Error" )
371391 return
372392 # documentation buffer name is same as the query made to ipython
373- vim .command ('new ' + word )
393+ vim .command ('new ' + word . lstrip ( '%' ) )
374394 vim .command ('setlocal modifiable noro' )
375395 # doc window quick quit keys: 'q' and 'escape'
376396 vim .command ('nnoremap <buffer> q :q<CR>' )
0 commit comments