diff --git a/IPython/core/inputtransformer.py b/IPython/core/inputtransformer.py index 3fdc641..fb71e6c 100644 --- a/IPython/core/inputtransformer.py +++ b/IPython/core/inputtransformer.py @@ -225,11 +225,14 @@ def _tr_help(line_info): def _tr_magic(line_info): "Translate lines escaped with: %" - tpl = '%sget_ipython().magic(%r)' + tpl = '%sget_ipython().run_line_magic(%r, %r)' if line_info.line.startswith(ESC_MAGIC2): return line_info.line cmd = ' '.join([line_info.ifun, line_info.the_rest]).strip() - return tpl % (line_info.pre, cmd) + #Prepare arguments for get_ipython().run_line_magic(magic_name, magic_args) + t_magic_name, _, t_magic_arg_s = cmd.partition(' ') + t_magic_name = t_magic_name.lstrip(ESC_MAGIC) + return tpl % (line_info.pre, t_magic_name, t_magic_arg_s) def _tr_quote(line_info): "Translate lines escaped with: ," @@ -514,12 +517,15 @@ def assign_from_system(line): return assign_system_template % m.group('lhs', 'cmd') assign_magic_re = re.compile(r'{}%\s*(?P.*)'.format(_assign_pat), re.VERBOSE) -assign_magic_template = '%s = get_ipython().magic(%r)' +assign_magic_template = '%s = get_ipython().run_line_magic(%r, %r)' @StatelessInputTransformer.wrap def assign_from_magic(line): """Transform assignment from magic commands (e.g. a = %who_ls)""" m = assign_magic_re.match(line) if m is None: return line - - return assign_magic_template % m.group('lhs', 'cmd') + #Prepare arguments for get_ipython().run_line_magic(magic_name, magic_args) + m_lhs, m_cmd = m.group('lhs', 'cmd') + t_magic_name, _, t_magic_arg_s = cmd.partition(' ') + t_magic_name = t_magic_name.lstrip(ESC_MAGIC) + return assign_magic_template % (m_lhs, t_magic_name, t_magic_arg_s) diff --git a/IPython/core/magics/history.py b/IPython/core/magics/history.py index 3a3c5c8..6f2138f 100644 --- a/IPython/core/magics/history.py +++ b/IPython/core/magics/history.py @@ -61,7 +61,7 @@ class HistoryMagics(Magics): source before executing it (things like magics or aliases are turned into function calls, for example). With this option, you'll see the native history instead of the user-entered version: '%%cd /' will be - seen as 'get_ipython().magic("%%cd /")' instead of '%%cd /'. + seen as 'get_ipython().run_line_magic("cd", "/")' instead of '%%cd /'. """) @argument( '-f', dest='filename', diff --git a/IPython/core/prefilter.py b/IPython/core/prefilter.py index 50ee071..c3109c7 100644 --- a/IPython/core/prefilter.py +++ b/IPython/core/prefilter.py @@ -589,8 +589,11 @@ class MagicHandler(PrefilterHandler): """Execute magic functions.""" ifun = line_info.ifun the_rest = line_info.the_rest - cmd = '%sget_ipython().magic(%r)' % (line_info.pre_whitespace, - (ifun + " " + the_rest)) + #Prepare arguments for get_ipython().run_line_magic(magic_name, magic_args) + t_arg_s = ifun + " " + the_rest + t_magic_name, _, t_magic_arg_s = t_arg_s.partition(' ') + t_magic_name = t_magic_name.lstrip(ESC_MAGIC) + cmd = '%sget_ipython().run_line_magic(%r, %r)' % (line_info.pre_whitespace, t_magic_name, t_magic_arg_s) return cmd