Commits

Ali Gholami Rudi  committed 1e28967

added rope-auto-import

  • Participants
  • Parent commits 1cf1fa1

Comments (0)

Files changed (2)

File ropemacs/interface.py

 import rope.base.change
 from Pymacs import lisp
 from rope.base import libutils
-from rope.contrib import codeassist, generate
+from rope.contrib import codeassist, generate, autoimport
 
 import ropemacs
 from ropemacs import refactor, lisputils
             (lisp.kill_emacs_hook, lisp.rope_exiting_actions),
             (lisp.python_mode_hook, lisp.rope_register_local_keys))
         self._prepare_refactorings()
+        self.autoimport = None
 
     def init(self):
         """Initialize rope mode"""
             self.close_project()
         progress = lisputils.create_progress('Opening "%s" project' % root)
         self.project = rope.base.project.Project(root)
+        self.autoimport = autoimport.AutoImport(self.project)
         progress.done()
 
     @interactive
         lisp.delete_region(starting_offset + 1, offset + 1)
         lisp.insert(result)
 
+    @rawprefixed
+    def auto_import(self, prefix):
+        self._check_project()
+        name = lisp.current_word()
+        modules = self.autoimport.get_modules(name)
+        if modules:
+            if len(modules) == 1:
+                module = modules[0]
+            else:
+                module = lisputils.ask_values('Which module to import: ',
+                                              modules)
+            current = lisp.point()
+            lisp.goto_char(0)
+            newimport = 'from %s import %s\n' % (module, name)
+            lisp.insert(newimport)
+            lisp.goto_char(current + len(newimport))
+        else:
+            lisputils.message('Not found!')
+
     def _calculate_proposals(self):
         self._check_project()
         resource, offset = self._get_location()
         else:
             lisputils.message('No rope project folder found')
 
-
     @interactive
     def create_module(self):
         def callback(sourcefolder, name):

File ropemacs/refactor.py

 
 
 class MethodObject(Refactoring):
-    key = None
     saveall = False
     confs = {'classname': dialog.Data('New class name: ',
                                       default='_ExtractedClass')}