1. Takafumi Arakaki
  2. rope


Ali Gholami Rudi  committed 36941fb

ropemacs: undoing and redoing refactorings

  • Participants
  • Parent commits a8c564c
  • Branches trunk

Comments (0)

Files changed (3)

File docs/dev/workingon.txt

View file
-Emacs Minor Mode
+ropemacs Mode
 * Only activating the keybinding in python files
-* Renaming current modules
 * Specifying refactoring options
-* Add to docs
+* Updating docs

File rope/base/history.py

View file
         return False
     def undo(self, change=None, task_handle=taskhandle.NullTaskHandle()):
+        """Returns the list of undone changes"""
         if not self._undo_list:
             raise exceptions.HistoryError('Undo list is empty')
         if change is None:
         index = self.undo_list.index(change)
         self._perform_undos(len(self.undo_list) - index, task_handle)
+        return self.redo_list[index - len(self.undo_list):]
     def _move_front(self, changes):
         for change in changes:
     def redo(self, task_handle=taskhandle.NullTaskHandle()):
+        """Return the list of undone changes"""
         if not self.redo_list:
             raise exceptions.HistoryError('Redo list is empty')
         self.current_change = self.redo_list[-1]
             self.current_change = None
+        return self.undo_list[-1:]
     def contents_before_current_change(self, file):
         if self.current_change is None:

File rope/contrib/ropemacs.py

View file
+        lisp.global_set_key('\x03po', lisp.rope_open_project)
+        lisp.global_set_key('\x03pk', lisp.rope_close_project)
+        lisp.global_set_key('\x03pu', lisp.rope_undo_refactoring)
+        lisp.global_set_key('\x03pr', lisp.rope_redo_refactoring)
         lisp.global_set_key('\x03g', lisp.rope_goto_definition)
         lisp.global_set_key('\x03rr', lisp.rope_rename)
         lisp.global_set_key('\x03r1r', lisp.rope_rename_current_module)
     @interactive('DRope Project Root Folder: ')
-    def set_project(self, root):
+    def open_project(self, root):
         if self.project is not None:
         self.project = project.Project(root)
         if definition[1]:
+    @interactive('cUndo refactoring might change many files; proceed? (y)')
+    def undo_refactoring(self, confirm):
+        if chr(confirm) in ('\r', '\n', 'y'):
+            self._check_project()
+            for changes in self.project.history.undo():
+                self._reload_buffers(changes.get_changed_resources())
+    @interactive('cRedo refactoring might change many files; proceed? (y)')
+    def redo_refactoring(self, confirm):
+        if chr(confirm) in ('\r', '\n', 'y'):
+            self._check_project()
+            for changes in self.project.history.redo():
+                self._reload_buffers(changes.get_changed_resources())
     def _get_location(self):
         resource = self._get_resource()
         offset = self._get_offset()
     def _check_project(self):
         if self.project is None:
-            lisp.call_interactively(lisp.rope_set_project)
+            lisp.call_interactively(lisp.rope_open_project)
     def _reload_buffers(self, changed_resources):
         for resource in changed_resources:
 interface = RopeInterface()
 init = interface.init
-set_project = interface.set_project
+open_project = interface.open_project
 close_project = interface.close_project
+undo_refactoring = interface.undo_refactoring
+redo_refactoring = interface.redo_refactoring
 rename = interface.rename
 rename_current_module = interface.rename_current_module