Anonymous avatar Anonymous committed 107e15b

Added rope-lucky-assist

Comments (0)

Files changed (4)

 project.
 
 
+Code-Assist
+-----------
+
+``rope-code-assist`` (``M-/`` by default) function will let you select
+from a list of completions.  By giving this function an argument, you
+can select which proposal to use without prompting; ``C-u 1 M-/`` uses
+the second, for instance.
+
+The ``rope-lucky-assist`` (``M-?``) is exactly like ``C-u 0 M-/``.  It
+applies the first completion without asking.
+
+
+
 Keybinding
 ----------
 
 C-c C-d         rope-show-doc
 C-c i o         rope-organize-imports
 C-c f           rope-find-occurrences
+M-?             rope-lucky-assist
 
 C-c n v         rope-generate-variable
 C-c n f         rope-generate-function
  Done
 ======
 
+- lucky-assist; ``M-?`` : November 29, 2007
 - find occurrences; ``C-c f`` : November 29, 2007
 - edit project config; ``C-x p c`` : November 28, 2007
 

ropemacs/__init__.py

 from rope.contrib import codeassist
 
 from ropemacs import refactor, lisputils
-from ropemacs.lisputils import lispfunction, interactive, prefixed
+from ropemacs.lisputils import lispfunction, interactive, prefixed, rawprefixed
 
 
 VERSION = '0.3'
 
         self.local_keys = [
             ('M-/', lisp.rope_code_assist),
+            ('M-?', lisp.rope_lucky_assist),
             ('C-c g', lisp.rope_goto_definition),
             ('C-c C-d', lisp.rope_show_doc),
             ('C-c f', lisp.rope_find_occurrences)]
     def occurrences_quit(self):
         lisputils.hide_buffer('*rope-occurrences*')
 
+    @rawprefixed
+    def code_assist(self, prefix):
+        arg = None
+        if prefix is not None:
+            arg = lisp.prefix_numeric_value(prefix)
+        self._code_assist(arg)
+
     @interactive
-    def code_assist(self):
+    def lucky_assist(self):
+        self.code_assist(0)
+
+    def _code_assist(self, index):
         self._check_project()
         resource, offset = self._get_location()
         source = lisp.buffer_string()
         starting_offset = codeassist.starting_offset(source, offset)
         names = [proposal.name for proposal in proposals]
         starting = source[starting_offset:offset]
-        prompt = 'Completion for %s: ' % starting
-        result = lisputils.ask_values(prompt, names,
-                                      starting=starting, exact=None)
+        if index is not None:
+            if 0 <= index < len(names):
+                result = names[index]
+            else:
+                lisputils.message('Not enough proposals!')
+                return
+        else:
+            prompt = 'Completion for %s: ' % starting
+            result = lisputils.ask_values(prompt, names,
+                                          starting=starting, exact=None)
         lisp.delete_region(starting_offset + 1, offset + 1)
         lisp.insert(result)
 

ropemacs/lisputils.py

 def prefixed(func):
     func.interaction = 'p'
     return func
+
+def rawprefixed(func):
+    func.interaction = 'P'
+    return func
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.