def __retreat_to_keywords(self, event): previous_text = unicode(self.textCursor().block().previous().text()) current_text = unicode(self.textCursor().block().text()) previous_spaces = helpers.get_indentation(previous_text) current_spaces = helpers.get_indentation(current_text) if len(previous_spaces) != len(current_spaces): last_word = helpers.get_first_keyword(current_text) if last_word in self.allows_less_indentation: helpers.clean_line(self) spaces_diff = len(current_spaces) - len(previous_spaces) self.textCursor().insertText(current_text[spaces_diff:])
def __retreat_to_keywords(self, event): """Unindent some kind of blocks if needed.""" previous_text = unicode(self.textCursor().block().previous().text()) current_text = unicode(self.textCursor().block().text()) previous_spaces = helpers.get_indentation(previous_text) current_spaces = helpers.get_indentation(current_text) if len(previous_spaces) < len(current_spaces): last_word = helpers.get_first_keyword(current_text) if last_word in self.allows_less_indentation: helpers.clean_line(self) spaces_diff = len(current_spaces) - len(previous_spaces) self.textCursor().insertText(current_text[spaces_diff:])
def analyze_file(self, path, source=None, indent=settings.INDENT, useTabs=settings.USE_TABS): if source is None: with open(path) as f: source = f.read() split_last_lines = source.rsplit('\n', 2) if len(split_last_lines) > 1 and \ split_last_lines[-2].endswith(':') and split_last_lines[-1] == '': indent = helpers.get_indentation(split_last_lines[-2], indent, useTabs) source += '%spass;' % indent self.module_id = path if not self.cdaemon.daemon.is_alive(): completion_daemon.shutdown_daemon() del self.cdaemon self.cdaemon = completion_daemon.CompletionDaemon() # Set modules reference to model model.MODULES = self.cdaemon.modules module = self.cdaemon.get_module(self.module_id) module = self.analyzer.analyze(source, module) self.cdaemon.inspect_module(self.module_id, module)
def __auto_indent(self, event): text = unicode(self.textCursor().block().previous().text()) spaces = helpers.get_indentation(text) self.textCursor().insertText(spaces) if text != '' and text == ' ' * len(text): self.moveCursor(QTextCursor.Up) self.moveCursor(QTextCursor.EndOfLine, QTextCursor.KeepAnchor) self.textCursor().removeSelectedText() self.moveCursor(QTextCursor.Down) else: helpers.check_for_assistance_completion(self, text)
def __auto_indent(self, event): text = unicode(self.textCursor().block().previous().text()) spaces = helpers.get_indentation(text) self.textCursor().insertText(spaces) if text != '' and text == ' ' * len(text): self.moveCursor(QTextCursor.Up) self.moveCursor(QTextCursor.EndOfLine, QTextCursor.KeepAnchor) self.textCursor().removeSelectedText() self.moveCursor(QTextCursor.Down) else: helpers.check_for_assistance_completion(self, text)
def __auto_indent(self, event): text = self.textCursor().block().previous().text() spaces = helpers.get_indentation(text, self.indent, self.useTabs) self.textCursor().insertText(spaces) if text != '' and text == ' ' * len(text): self.moveCursor(QTextCursor.Up) self.moveCursor(QTextCursor.EndOfLine, QTextCursor.KeepAnchor) self.textCursor().removeSelectedText() self.moveCursor(QTextCursor.Down) elif settings.COMPLETE_DECLARATIONS: helpers.check_for_assistance_completion(self, text) cursor = self.textCursor() cursor.setPosition(cursor.position()) self.setTextCursor(cursor)
def __auto_indent(self, event): text = unicode(self.textCursor().block().previous().text()) spaces = helpers.get_indentation(text) self.textCursor().insertText(spaces) if text != '' and text == ' ' * len(text): self.moveCursor(QTextCursor.Up) self.moveCursor(QTextCursor.EndOfLine, QTextCursor.KeepAnchor) self.textCursor().removeSelectedText() self.moveCursor(QTextCursor.Down) elif settings.COMPLETE_DECLARATIONS: helpers.check_for_assistance_completion(self, text) cursor = self.textCursor() cursor.setPosition(cursor.position()) self.setTextCursor(cursor)
def analyze_file(self, path, source=None): if source is None: with open(path) as f: source = f.read() split_last_lines = source.rsplit('\n', 2) if len(split_last_lines) > 1 and \ split_last_lines[-2].endswith(':') and split_last_lines[-1] == '': indent = helpers.get_indentation(split_last_lines[-2]) source += '%spass;' % indent self.module_id = path if not self.cdaemon.daemon.is_alive(): completion_daemon.shutdown_daemon() del self.cdaemon self.cdaemon = completion_daemon.CompletionDaemon() # Set modules reference to model model.MODULES = self.cdaemon.modules module = self.cdaemon.get_module(self.module_id) module = self.analyzer.analyze(source, module) self.cdaemon.inspect_module(self.module_id, module)