From f332431ef2e26155a092fc68a39bfa94fc41c9e0 2011-05-20 23:01:17 From: Thomas Kluyver Date: 2011-05-20 23:01:17 Subject: [PATCH] Fix up magic_edit functions so they work again. --- diff --git a/IPython/core/magic.py b/IPython/core/magic.py index 32dcd96..d3a8b28 100644 --- a/IPython/core/magic.py +++ b/IPython/core/magic.py @@ -2245,7 +2245,7 @@ Currently the magic system has the following functions:\n""" filename = self.shell.mktempfile(data) print 'IPython will make a temporary file named:',filename - return filename + return filename, lineno, use_temp def _edit_macro(self,mname,macro): """open an editor with the macro data in a file""" @@ -2407,7 +2407,7 @@ Currently the magic system has the following functions:\n""" opts,args = self.parse_options(parameter_s,'prxn:') try: - filename = self._find_edit_target(args, opts, last_call) + filename, lineno, is_temp = self._find_edit_target(args, opts, last_call) except MacroToEdit as e: self._edit_macro(args, e.args[0]) return @@ -2433,15 +2433,14 @@ Currently the magic system has the following functions:\n""" print else: print 'done. Executing edited code...' - if opts_raw: + if 'r' in opts: # Untranslated IPython code self.shell.run_cell(file_read(filename), store_history=False) else: self.shell.safe_execfile(filename,self.shell.user_ns, self.shell.user_ns) - - if use_temp: + if is_temp: try: return open(filename).read() except IOError,msg: diff --git a/IPython/zmq/zmqshell.py b/IPython/zmq/zmqshell.py index dc7d166..21f9d86 100644 --- a/IPython/zmq/zmqshell.py +++ b/IPython/zmq/zmqshell.py @@ -29,6 +29,7 @@ from IPython.core.autocall import ZMQExitAutocall from IPython.core.displayhook import DisplayHook from IPython.core.displaypub import DisplayPublisher from IPython.core.macro import Macro +from IPython.core.magic import MacroToEdit from IPython.core.payloadpage import install_payload_page from IPython.utils import io from IPython.utils.path import get_py_filename @@ -398,11 +399,14 @@ class ZMQInteractiveShell(InteractiveShell): starting example for further modifications. That file also has general instructions on how to set a new hook for use once you've defined it.""" + + opts,args = self.parse_options(parameter_s,'prn:') + try: - filename = self._find_edit_target(args, opts, last_call) + filename, lineno, _ = self._find_edit_target(args, opts, last_call) except MacroToEdit as e: # TODO: Implement macro editing over 2 processes. - print "Macro editing not yet implemented in 2-process model." + print("Macro editing not yet implemented in 2-process model.") return # Make sure we send to the client an absolute path, in case the working