Anonymous avatar Anonymous committed b02c5c3

Added rope-find-occurrences

Comments (0)

Files changed (5)

 C-c g           rope-goto-definition
 C-c C-d         rope-show-doc
 C-c i o         rope-organize-imports
+C-c f           rope-find-occurrences
 
 C-c n v         rope-generate-variable
 C-c n f         rope-generate-function
  Done
 ======
 
+- find occurrences; ``C-c f`` : November 29, 2007
 - edit project config; ``C-x p c`` : November 28, 2007
 
 > Public Release 0.2 : November 28, 2007
 
 > Public Release 0.3
 
-* find occurrences
 * new file/directory/module/package; C-x p n [fdmp]
 * showing proposal type in code-assist

ropemacs/__init__.py

         self.local_keys = [
             ('M-/', lisp.rope_code_assist),
             ('C-c g', lisp.rope_goto_definition),
-            ('C-c C-d', lisp.rope_show_doc)]
+            ('C-c C-d', lisp.rope_show_doc),
+            ('C-c f', lisp.rope_find_occurrences)]
 
         self._register_refactorings()
 
         lisputils.make_buffer('*rope-pydoc*', docs, empty_goto=False)
 
     @interactive
+    def find_occurrences(self):
+        self._check_project()
+        self._save_buffers()
+        resource, offset = self._get_location()
+        def calculate(handle):
+            return codeassist.find_occurrences(
+                self.project, resource, offset,
+                unsure=True, task_handle=handle)
+        result = lisputils.RunTask(calculate, 'Find Occurrences')()
+        text = []
+        for occurrence in result:
+            line = '%s : %s' % (occurrence.resource.path, occurrence.offset)
+            if occurrence.unsure:
+                line += ' ?'
+            text.append(line)
+        text = '\n'.join(text) + '\n'
+        buffer = lisputils.make_buffer('*rope-occurrences*',
+                                       text, switch=True)
+        lisp.set_buffer(buffer)
+        lisp.local_set_key('\r', lisp.rope_occurrences_goto_occurrence)
+
+    @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])
+            lisp.find_file_other_window(resource.real_path)
+            lisp.goto_char(offset)
+            lisp.switch_to_buffer_other_window('*rope-occurrences*')
+
+    @interactive
     def code_assist(self):
         self._check_project()
         resource, offset = self._get_location()
         starting = source[starting_offset:offset]
         prompt = 'Completion for %s: ' % starting
         result = lisputils.ask_values(prompt, names,
-                                       starting=starting, exact=None)
+                                      starting=starting, exact=None)
         lisp.delete_region(starting_offset + 1, offset + 1)
         lisp.insert(result)
 

ropemacs/lisputils.py

     return lisp.yes_or_no_p(prompt)
 
 
-def make_buffer(name, contents, empty_goto=True, modes=[]):
+def make_buffer(name, contents, empty_goto=True, switch=False, modes=[]):
     new_buffer = lisp.get_buffer_create(name)
     lisp.set_buffer(new_buffer)
     lisp.toggle_read_only(-1)
         lisp.display_buffer(new_buffer)
         lisp.buffer_disable_undo(new_buffer)
         lisp.toggle_read_only(1)
+        if switch:
+            lisp.switch_to_buffer_other_window(new_buffer)
         lisp.goto_line(1)
+    return new_buffer
 
 
 def hide_buffer(name):
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.