Commits

Anonymous committed cc8a7d3

ropemacs: moved saving files to ropemacs

Comments (0)

Files changed (2)

ropecommon/interface.py

     @decorators.rope_hook('before-save-hook')
     def before_save_actions(self):
         if self.project is not None:
-            if not self._is_python_file(lisp.buffer_file_name()):
+            if not self._is_python_file(self.env.filename()):
                 return
             resource = self._get_resource()
             if resource.exists():
     @decorators.rope_hook('after-save-hook')
     def after_save_actions(self):
         if self.project is not None and self.old_content is not None:
-            libutils.report_change(self.project, lisp.buffer_file_name(),
+            libutils.report_change(self.project, self.env.filename(),
                                    self.old_content)
             self.old_content = None
 
 
     def _get_resource(self, filename=None):
         if filename is None:
-            filename = lisp.buffer_file_name()
+            filename = self.env.filename()
         if filename is None:
             return
         resource = libutils.path_to_resource(self.project, filename, 'file')
 
     def _save_buffers(self, only_current=False):
         ask = self.env.get('ropemacs-confirm-saving')
-        initial = lisp.current_buffer()
-        current_buffer = lisp.current_buffer()
         if only_current:
-            buffers = [current_buffer]
+            filenames = self.env.filename()
         else:
-            buffers = lisp.buffer_list()
-        for buffer in buffers:
-            filename = lisp.buffer_file_name(buffer)
-            if filename:
-                if self._is_python_file(filename) and \
-                   lisp.buffer_modified_p(buffer):
-                    if not ask or lisp.y_or_n_p('Save %s buffer?' % filename):
-                        lisp.set_buffer(buffer)
-                        lisp.save_buffer()
-        lisp.set_buffer(initial)
+            filenames = self.env.filenames()
+        pythons = []
+        for filename in filenames:
+            if self._is_python_file(filename):
+                pythons.append(filename)
+        self.env.save_files(pythons, ask)
 
     def _is_python_file(self, path):
         resource = self._get_resource(path)
             if narrowed:
                 lisp.narrow_to_region(old_min, old_max)
 
+    def filename(self):
+        return lisp.buffer_file_name()
+
+    def filenames(self):
+        result = []
+        for buffer in lisp.buffer_list():
+            filename = lisp.buffer_file_name(buffer)
+            if filename:
+                result.append(filename)
+        return result
+
+    def save_files(self, filenames, ask=False):
+        initial = lisp.current_buffer()
+        for filename in filenames:
+            buffer = lisp.find_buffer_visiting(filename)
+            if buffer:
+                if lisp.buffer_modified_p(buffer):
+                    if not ask or lisp.y_or_n_p('Save %s buffer?' % filename):
+                        lisp.set_buffer(buffer)
+                        lisp.save_buffer()
+        lisp.set_buffer(initial)
+
     def make_buffer(self, name, contents, empty_goto=True, switch=False,
                     window='other', modes=[], fit_lines=None):
         """Make an emacs buffer
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.