Commits

Ali Gholami Rudi  committed 36941fb

ropemacs: undoing and redoing refactorings

  • Participants
  • Parent commits a8c564c

Comments (0)

Files changed (3)

File docs/dev/workingon.txt

-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

         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:
         self._move_front(dependencies)
         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:
             self.redo_list.append(self.undo_list.pop())
 
     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]
         finally:
             self.current_change = None
         self.undo_list.append(self.redo_list.pop())
+        return self.undo_list[-1:]
 
     def contents_before_current_change(self, file):
         if self.current_change is None:

File rope/contrib/ropemacs.py

                       lisp.rope_after_save_actions)
         lisp.add_hook(lisp.kill_emacs_hook,
                       lisp.rope_exiting_actions)
+
+        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)
             self.close_project()
 
     @interactive('DRope Project Root Folder: ')
-    def set_project(self, root):
+    def open_project(self, root):
         if self.project is not None:
             self.close_project()
         self.project = project.Project(root)
         if definition[1]:
             lisp.goto_line(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