Anonymous avatar Anonymous committed 1265439

interface: using local_command decorator for refactorings

Comments (0)

Files changed (2)


 def _lisp_name(func):
-    return 'rope-' + refactor.refactoring_name(func).replace('_', '-')
+    return 'rope-' + func.__name__.replace('_', '-')
-def global_command(key=None, lisper=lisputils.interactive):
+def global_command(key=None, interaction=''):
     def decorator(func):
-        func = lisper(func)
+        if interaction is not None:
+            func.interaction = interaction
         if key:
             global_keys.append((key, _lisp_name(func)))
         return func
     return decorator
-def local_command(key=None, lisper=lisputils.interactive, shortcut=None):
-    def decorator(func):
-        func = lisper(func)
+def local_command(key=None, interaction='', shortcut=None, name=None):
+    def decorator(func, name=name):
+        if name is None:
+            name = _lisp_name(func)
+        if interaction is not None:
+            func.interaction = interaction
         if key:
-            local_keys.append((key, _lisp_name(func)))
+            local_keys.append((key, name))
         if shortcut:
-            shortcuts.append((shortcut, _lisp_name(func)))
+            shortcuts.append((shortcut, name))
         return func
     return decorator
                 attr = getattr(refactor, name)
                 if isinstance(attr, type) and \
                    issubclass(attr, refactor.Refactoring):
-                    @lisputils.rawprefixed
+                    ref_name = self._refactoring_name(attr)
+                    lisp_name = 'rope-' + ref_name.replace('_', '-')
+                    @local_command(attr.key, 'P', None, lisp_name)
                     def do_refactor(prefix, self=self, refactoring=attr):
                         initial_asking = prefix is None
-                    name = self._refactoring_name(attr)
-                    setattr(self, name, do_refactor)
-                    name = 'rope-' + name.replace('_', '-')
-                    if attr.key is not None:
-                        local_keys.append((attr.key, name))
+                    setattr(self, ref_name, do_refactor)
     def _refactoring_name(self, refactoring):
         return refactor.refactoring_name(refactoring)
-    @local_command('a d', lisputils.rawprefixed, 'C-c d')
+    @local_command('a d', 'P', 'C-c d')
     def show_doc(self, prefix):
-    @local_command(lisper=lisputils.rawprefixed)
+    @local_command(interaction='P')
     def show_call_doc(self, prefix):
         offset = self._get_offset()
     def occurrences_quit(self):
-    @local_command('a /', lisputils.rawprefixed, 'M-/')
+    @local_command('a /', 'P', 'M-/')
     def code_assist(self, prefix):
-    @local_command('a ?', lisputils.rawprefixed, 'M-?')
+    @local_command('a ?', 'P', 'M-?')
     def lucky_assist(self, prefix):
             self.autoimport.generate_modules_cache(modules, task_handle=handle)
         lisputils.runtask(generate, 'Generate autoimport cache')
-    @global_command('f', lisputils.rawprefixed)
+    @global_command('f', 'P')
     def find_file(self, prefix):
         file = self._base_find_file(prefix)
         if file is not None:
-    @global_command('4 f', lisputils.rawprefixed)
+    @global_command('4 f', 'P')
     def find_file_other_window(self, prefix):
         file = self._base_find_file(prefix)
         if file is not None:


     func.lisp = None
     return func
 def interactive(func):
     func.interaction = ''
     return func
-def prefixed(func):
-    func.interaction = 'p'
-    return func
-def rawprefixed(func):
-    func.interaction = 'P'
-    return func
 def lisphook(func):
     def newfunc(*args, **kwds):
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
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.