##// END OF EJS Templates
fix %edit foo for interactively defined variables...
MinRK -
Show More
@@ -17,6 +17,7 b' import inspect'
17 17 import io
18 18 import json
19 19 import os
20 import re
20 21 import sys
21 22 from urllib2 import urlopen
22 23
@@ -39,6 +40,13 b' from IPython.utils.warn import warn'
39 40 # Used for exception handling in magic_edit
40 41 class MacroToEdit(ValueError): pass
41 42
43 ipython_input_pat = re.compile(r"<ipython\-input\-(\d+)-[a-z\d]+>$")
44
45 class InteractivelyDefined(Exception):
46 """Exception for interactively defined variable in magic_edit"""
47 def __init__(self, index):
48 self.index = index
49
42 50
43 51 @magics_class
44 52 class CodeMagics(Magics):
@@ -302,6 +310,10 b' class CodeMagics(Magics):'
302 310 data = attr
303 311 break
304 312
313 m = ipython_input_pat.match(os.path.basename(filename))
314 if m:
315 raise InteractivelyDefined(int(m.groups()[0]))
316
305 317 datafile = 1
306 318 if filename is None:
307 319 filename = make_filename(args)
@@ -491,6 +503,11 b' class CodeMagics(Magics):'
491 503 except MacroToEdit as e:
492 504 self._edit_macro(args, e.args[0])
493 505 return
506 except InteractivelyDefined as e:
507 print "Editing In[%i]" % e.index
508 args = str(e.index)
509 filename, lineno, is_temp = self._find_edit_target(self.shell,
510 args, opts, last_call)
494 511
495 512 # do actual editing here
496 513 print 'Editing...',
General Comments 0
You need to be logged in to leave comments. Login now