##// END OF EJS Templates
fix %edit foo for interactively defined variables...
MinRK -
Show More
@@ -17,6 +17,7 b' import inspect'
17 import io
17 import io
18 import json
18 import json
19 import os
19 import os
20 import re
20 import sys
21 import sys
21 from urllib2 import urlopen
22 from urllib2 import urlopen
22
23
@@ -39,6 +40,13 b' from IPython.utils.warn import warn'
39 # Used for exception handling in magic_edit
40 # Used for exception handling in magic_edit
40 class MacroToEdit(ValueError): pass
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 @magics_class
51 @magics_class
44 class CodeMagics(Magics):
52 class CodeMagics(Magics):
@@ -301,7 +309,11 b' class CodeMagics(Magics):'
301 # target instead
309 # target instead
302 data = attr
310 data = attr
303 break
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 datafile = 1
317 datafile = 1
306 if filename is None:
318 if filename is None:
307 filename = make_filename(args)
319 filename = make_filename(args)
@@ -491,6 +503,11 b' class CodeMagics(Magics):'
491 except MacroToEdit as e:
503 except MacroToEdit as e:
492 self._edit_macro(args, e.args[0])
504 self._edit_macro(args, e.args[0])
493 return
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 # do actual editing here
512 # do actual editing here
496 print 'Editing...',
513 print 'Editing...',
General Comments 0
You need to be logged in to leave comments. Login now