Commits

Anonymous committed 000b01e

ropemacs: added LispUtils.show_occurrences()

Comments (0)

Files changed (2)

ropecommon/interface.py

                 return do_find(self.project, resource, offset,
                                resources=resources, task_handle=handle, **kwds)
             result = self.env.runtask(calculate, 'Find Occurrences')
-            text = []
+            locations = []
             for occurrence in result:
-                line = '%s : %s' % (occurrence.resource.path, occurrence.offset)
+                note = ''
                 if occurrence.unsure:
-                    line += ' ?'
-                text.append(line)
-            text = '\n'.join(text) + '\n'
-            buffer = self.env.make_buffer('*rope-occurrences*',
-                                          text, switch=True)
-            lisp.set_buffer(buffer)
-            lisp.local_set_key('\r', lisp.rope_occurrences_goto_occurrence)
-            lisp.local_set_key('q', lisp.rope_occurrences_quit)
+                    note = '?'
+                locations.append((occurrence.resource.path,
+                                  occurrence.offset, note))
+            self.env.show_occurrences(locations)
 
     @decorators.local_command('a f', shortcut='C-c f')
     def find_occurrences(self):
             return {}
         self._base_findit(findit.find_implementations, optionals, get_kwds)
 
-    @decorators.interactive
-    def occurrences_goto_occurrence(self):
-        self._check_project()
-        start = lisp.line_beginning_position()
-        end = lisp.line_end_position()
-        line = lisp.buffer_substring_no_properties(start, end)
-        tokens = line.split()
-        if tokens:
-            resource = self.project.get_resource(tokens[0])
-            offset = int(tokens[2])
-            self.env.find_file(resource.real_path, other=True)
-            lisp.goto_char(offset + 1)
-            lisp.switch_to_buffer_other_window('*rope-occurrences*')
-
-    @decorators.interactive
-    def occurrences_quit(self):
-        self.env.hide_buffer('*rope-occurrences*')
-
     @decorators.local_command('a /', 'P', 'M-/')
     def code_assist(self, prefix):
         _CodeAssist(self, self.env).code_assist(prefix)
 
     def find_file(self, filename, readonly=False, other=False):
         if other:
-            self.find_file_other_window(filename)
+            lisp.find_file_other_window(filename)
         elif not readonly:
             lisp.find_file(filename)
         else:
             progress = _OldProgress(name)
         return progress
 
+    def show_occurrences(self, locations):
+        text = []
+        for filename, offset, note in locations:
+            line = '%s : %s %s' % (filename, offset, note)
+            text.append(line)
+        text = '\n'.join(text) + '\n'
+        buffer = self.make_buffer('*rope-occurrences*', text, switch=True)
+        lisp.set_buffer(buffer)
+        lisp.local_set_key('\r', lisp.rope_occurrences_goto_occurrence)
+        lisp.local_set_key('q', lisp.delete_window)
+
 
 class _LispProgress(object):
 
         return result
 
 
+def occurrences_goto_occurrence():
+    start = lisp.line_beginning_position()
+    end = lisp.line_end_position()
+    line = lisp.buffer_substring_no_properties(start, end)
+    tokens = line.split()
+    if tokens:
+        filename = tokens[0]
+        offset = int(tokens[2])
+        resource = _interface._get_resource(filename)
+        LispUtils().find_file(resource.real_path, other=True)
+        lisp.goto_char(offset + 1)
+        lisp.switch_to_buffer_other_window('*rope-occurrences*')
+occurrences_goto_occurrence.interaction = ''
+
+
 def _register_functions(interface):
     for attrname in dir(interface):
         attr = getattr(interface, attrname)
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.