Anonymous avatar Anonymous committed bf7d203

interface: reducing _get_text calls

Comments (0)

Files changed (1)

ropemacs/interface.py

 
     @rawprefixed
     def code_assist(self, prefix):
-        starting_offset, names = self._calculate_proposals()
+        source = self._get_text()
+        starting_offset, names = self._calculate_proposals(source)
         if prefix is not None:
             arg = lisp.prefix_numeric_value(prefix)
             if arg == 0:
                 arg = len(names)
             common_start = self._calculate_prefix(names[:arg])
             lisp.insert(common_start[self._get_offset() - starting_offset:])
-        source = self._get_text()
         offset = self._get_offset()
         starting = source[starting_offset:offset]
         prompt = 'Completion for %s: ' % starting
 
     @rawprefixed
     def lucky_assist(self, prefix):
-        starting_offset, names = self._calculate_proposals()
         source = self._get_text()
+        starting_offset, names = self._calculate_proposals(source)
         offset = self._get_offset()
         starting = source[starting_offset:offset]
         selected = 0
             name, module = assist.rsplit(' : ', 1)
             lisp.delete_region(start + 1, offset + 1)
             lisp.insert(name)
-            self._insert_import(name, module)
+            self._insert_import(source, name, module)
         else:
             lisp.delete_region(start + 1, offset + 1)
             lisp.insert(assist)
 
-    def _calculate_proposals(self):
+    def _calculate_proposals(self, source):
         self._check_project()
         resource, offset = self._get_location()
-        source = self._get_text()
         maxfixes = lisp['ropemacs-codeassist-maxfixes'].value()
         proposals = codeassist.code_assist(self.project, source, offset,
                                            resource, maxfixes=maxfixes)
             else:
                 module = lisputils.ask_values(
                     'Which module to import: ', modules)
-            self._insert_import(name, module)
+            self._insert_import(source, name, module)
         else:
             lisputils.message('Global name %s not found!' % name)
 
             self.autoimport.generate_modules_cache(modules, task_handle=handle)
         lisputils.runtask(generate, 'Generate autoimport cache')
 
-    def _insert_import(self, name, module):
-        lineno = self.autoimport.find_insertion_line(self._get_text())
+    def _insert_import(self, source, name, module):
+        lineno = self.autoimport.find_insertion_line(source)
         current = lisp.point()
         lisp.goto_line(lineno)
         newimport = 'from %s import %s\n' % (module, 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.