##// END OF EJS Templates
Tidier way of returning enterted command to the prompt when doing
Thomas Kluyver -
Show More
@@ -672,15 +672,18 b' def transform_ipy_prompt(line):'
672 672 return line
673 673
674 674
675 def _make_help_call(target, esc, lspace):
675 def _make_help_call(target, esc, lspace, next_input=None):
676 676 """Prepares a pinfo(2)/psearch call from a target name and the escape
677 677 (i.e. ? or ??)"""
678 678 method = 'pinfo2' if esc == '??' \
679 679 else 'psearch' if '*' in target \
680 680 else 'pinfo'
681 681
682 tpl = '%sget_ipython().magic(u"%s %s")'
683 return tpl % (lspace, method, target)
682 if next_input:
683 tpl = '%sget_ipython().magic(u"%s %s", next_input=%s)'
684 return tpl % (lspace, method, target, make_quoted_expr(next_input))
685 else:
686 return '%sget_ipython().magic(u"%s %s")' % (lspace, method, target)
684 687
685 688 _initial_space_re = re.compile(r'\s*')
686 689 _help_end_re = re.compile(r"""(%?
@@ -700,11 +703,9 b' def transform_help_end(line):'
700 703 newline = _make_help_call(target, esc, lspace)
701 704
702 705 # If we're mid-command, put it back on the next prompt for the user.
703 if line.strip() != m.group(0):
704 newline += "; get_ipython().set_next_input(%s)" % \
705 make_quoted_expr(line.rstrip('?'))
706 next_input = line.rstrip('?') if line.strip() != m.group(0) else None
706 707
707 return newline
708 return _make_help_call(target, esc, lspace, next_input)
708 709
709 710
710 711 class EscapedTransformer(object):
@@ -1703,7 +1703,8 b' class InteractiveShell(SingletonConfigurable, Magic):'
1703 1703 [D:\ipython]|1> _ip.set_next_input("Hello Word")
1704 1704 [D:\ipython]|2> Hello Word_ # cursor is here
1705 1705 """
1706
1706 if isinstance(s, unicode):
1707 s = s.encode(self.stdin_encoding)
1707 1708 self.rl_next_input = s
1708 1709
1709 1710 # Maybe move this to the terminal subclass?
@@ -1841,7 +1842,7 b' class InteractiveShell(SingletonConfigurable, Magic):'
1841 1842 from . import history
1842 1843 history.init_ipython(self)
1843 1844
1844 def magic(self,arg_s):
1845 def magic(self, arg_s, next_input=None):
1845 1846 """Call a magic function by name.
1846 1847
1847 1848 Input: a string containing the name of the magic function to call and
@@ -1858,6 +1859,11 b' class InteractiveShell(SingletonConfigurable, Magic):'
1858 1859 valid Python code you can type at the interpreter, including loops and
1859 1860 compound statements.
1860 1861 """
1862 # Allow setting the next input - this is used if the user does `a=abs?`.
1863 # We do this first so that magic functions can override it.
1864 if next_input:
1865 self.set_next_input(next_input)
1866
1861 1867 args = arg_s.split(' ',1)
1862 1868 magic_name = args[0]
1863 1869 magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
@@ -454,9 +454,9 b' syntax = \\'
454 454 ('%hist?', 'get_ipython().magic(u"pinfo %hist")'),
455 455 ('f*?', 'get_ipython().magic(u"psearch f*")'),
456 456 ('ax.*aspe*?', 'get_ipython().magic(u"psearch ax.*aspe*")'),
457 ('a = abc?', 'get_ipython().magic(u"pinfo abc"); get_ipython().set_next_input(u"a = abc")'),
458 ('a = abc.qe??', 'get_ipython().magic(u"pinfo2 abc.qe"); get_ipython().set_next_input(u"a = abc.qe")'),
459 ('a = *.items?', 'get_ipython().magic(u"psearch *.items"); get_ipython().set_next_input(u"a = *.items")'),
457 ('a = abc?', 'get_ipython().magic(u"pinfo abc", next_input=u"a = abc")'),
458 ('a = abc.qe??', 'get_ipython().magic(u"pinfo2 abc.qe", next_input=u"a = abc.qe")'),
459 ('a = *.items?', 'get_ipython().magic(u"psearch *.items", next_input=u"a = *.items")'),
460 460 ('a*2 #comment?', 'a*2 #comment?'),
461 461 ],
462 462
General Comments 0
You need to be logged in to leave comments. Login now