--- a/stmts.py Fri Jul 01 12:08:52 2011 +0200
+++ b/stmts.py Fri Jul 01 15:30:06 2011 +0200
@@ -48,6 +48,13 @@
raise AssertionError('vref %r is not referenced (%r)' % (vref, vref.stmt))
return True
+class undo_modification(object):
+ def __init__(self, select):
+ self.select = select
+ def __enter__(self):
+ self.select.save_state()
+ def __exit__(self):
+ self.select.recover()
class ScopeNode(BaseNode):
solutions = () # list of possibles solutions for used variables
@@ -355,6 +362,9 @@
def should_register_op(self):
return self.memorizing and not self.undoing
+ def undo_modification(self):
+ return undo_modification(self)
+
def save_state(self):
"""save the current tree"""
self.undo_manager.push_state()