Anonymous avatar Anonymous committed c541a82

ropemacs: added hooks for closing the project and performing SOI

Comments (0)

Files changed (2)

docs/dev/workingon.txt

 Emacs Minor Mode
 ================
 
-* Adding hooks for SOI when saving buffers
+- Closing the project when exiting emacs; kill-emacs-hook
+- Adding hooks for SOI when saving buffers; after-save-hook
+
 * Renaming modules and packages
-* Closing the project when exiting emacs
 * Specifying refactoring options
 * Add to docs

rope/contrib/ropemacs.py

 
     def __init__(self):
         self.project = None
+        self.old_content = None
 
     def init(self):
         """Initialize rope mode"""
         #lisp.global_set_key(lisp.kbd('C-c r r'), lisp.rope_rename)
+        lisp.add_hook(lisp.before_save_hook,
+                      lisp.rope_before_save_actions)
+        lisp.add_hook(lisp.after_save_hook,
+                      lisp.rope_after_save_actions)
+        lisp.add_hook(lisp.kill_emacs_hook,
+                      lisp.rope_exiting_actions)
+
+    def before_save_actions(self):
+        if self.project is not None:
+            resource = self._get_resource()
+            if resource is not None:
+                self.old_content = resource.read()
+            else:
+                self.old_content = ''
+
+    def after_save_actions(self):
+        if self.project is not None:
+            libutils.report_change(self.project, lisp.buffer_file_name(),
+                                   self.old_content)
+            self.old_content = None
+
+    def exiting_actions(self):
+        if self.project is not None:
+            self.close_project()
 
     @interactive('DRope Project Root Folder: ')
     def set_project(self, root):
 extract_method = interface.extract_method
 inline = interface.inline
 
+before_save_actions = interface.before_save_actions
+after_save_actions = interface.after_save_actions
+exiting_actions = interface.exiting_actions
+
 goto_definition = interface.goto_definition
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.