def newfunc(*args, **kwds): try: func(*args, **kwds) except exceptions.RopeError, e: lisputils.message(str(traceback.format_exc())) if isinstance(e, input_exceptions): lisputils.message(_exception_message(e))
def _check_autoimport(self): self._check_project() if self.autoimport is None: lisputils.message('autoimport is disabled; ' 'see `ropemacs-enable-autoimport\' variable') return False return True
def project_config(self): self._check_project() if self.project.ropefolder is not None: config = self.project.ropefolder.get_child('config.py') lisp.find_file(config.real_path) else: lisputils.message('No rope project folder found')
def newfunc(*args, **kwds): try: func(*args, **kwds) except Exception, e: trace = str(traceback.format_exc()) lisputils.message( '%s\nIgnored an exception in ropemacs hook: %s' % (trace, _exception_message(e)))
def _ask_file(self, files): names = [] for file in files: names.append('<'.join(reversed(file.path.split('/')))) result = lisputils.ask_values('Rope Find File: ', names, exact=True) if result is not None: path = '/'.join(reversed(result.split('<'))) file = self.project.get_file(path) return file lisputils.message('No file selected')
def lucky_assist(self, prefix): names = self._calculate_proposals() selected = 0 if prefix is not None: selected = lisp.prefix_numeric_value(prefix) if 0 <= selected < len(names): result = names[selected] else: lisputils.message('Not enough proposals!') return self._apply_assist(result)
def goto_definition(self): self._check_project() resource, offset = self._get_location() maxfixes = lisp['ropemacs-codeassist-maxfixes'].value() definition = codeassist.get_definition_location( self.project, self._get_text(), offset, resource, maxfixes) if tuple(definition) != (None, None): lisp.push_mark() self._goto_location(definition[0], definition[1]) else: lisputils.message('Cannot find the definition!')
def redo(self): self._check_project() change = self.project.history.tobe_redone if change is None: lisputils.message('Nothing to redo!') return if lisp.y_or_n_p('Redo <%s>? ' % str(change)): def redo(handle): for changes in self.project.history.redo(task_handle=handle): self._reload_buffers(changes) lisputils.runtask(redo, 'Redo refactoring', interrupts=False)
def _perform(self, changes): if changes is None: lisputils.message("No changes!") return def perform(handle, self=self, changes=changes): self.project.do(changes, task_handle=handle) self.interface._reload_buffers(changes) self._done() lisputils.runtask(perform, "Making %s changes" % self.name, interrupts=False) lisputils.message(str(changes.description) + " finished")
def auto_import(self): if not self.interface._check_autoimport(): return 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) self._insert_import(name, module) else: lisputils.message('Global name %s not found!' % name)
def _base_show_doc(self, prefix, get_doc): maxfixes = lisp['ropemacs-codeassist-maxfixes'].value() text = self._get_text() offset = self._get_offset() docs = get_doc(self.project, text, offset, self._get_resource(), maxfixes) use_minibuffer = not prefix if lisp['ropemacs-separate-doc-buffer'].value(): use_minibuffer = not use_minibuffer if use_minibuffer and docs: docs = '\n'.join(docs.split('\n')[:7]) lisputils.message(docs) else: fit_lines = lisp["ropemacs-max-doc-buffer-height"].value() buffer = lisputils.make_buffer('*rope-pydoc*', docs, empty_goto=False, fit_lines=fit_lines) lisp.local_set_key('q', lisp.bury_buffer) if docs is None: lisputils.message('No docs avilable!')
def show(self, initial_asking=True): self.interface._check_project() self.interface._save_buffers(only_current=not self.saveall) self._create_refactoring() action, result = dialog.show_dialog( lisputils.askdata, ["perform", "preview", "cancel"], self._get_confs(), self._get_optionals(), initial_asking=initial_asking, ) if action == "cancel": lisputils.message("Cancelled!") return def calculate(handle): return self._calculate_changes(result, handle) name = "Calculating %s changes" % self.name changes = lisputils.runtask(calculate, name=name) if action == "perform": self._perform(changes) if action == "preview": if changes is not None: diffs = str(changes.get_description()) lisputils.make_buffer("*rope-preview*", diffs, switch=True, modes=["diff"], window="current") if lisputils.yes_or_no("Do the changes? "): self._perform(changes) else: lisputils.message("Thrown away!") lisputils.hide_buffer("*rope-preview*", delete=False) else: lisputils.message("No changes!")
def show_call_doc(self, prefix): self._check_project() lisputils.message('ropemacs: use `rope-show-calltip\' instead!')