--- a/eric6/QScintilla/TypingCompleters/CompleterPython.py Sat May 04 14:01:19 2019 +0200 +++ b/eric6/QScintilla/TypingCompleters/CompleterPython.py Sat May 04 14:34:51 2019 +0200 @@ -16,7 +16,7 @@ import re from PyQt5.QtCore import QRegExp -from PyQt5.Qsci import QsciLexerPython +from PyQt5.Qsci import QsciLexerPython, QsciScintilla from .CompleterBase import CompleterBase @@ -78,10 +78,10 @@ Preferences.getEditorTyping("Python/DedentElse") self.__dedentExcept = \ Preferences.getEditorTyping("Python/DedentExcept") - self.__py24StyleTry = \ - Preferences.getEditorTyping("Python/Py24StyleTry") self.__insertImport = \ Preferences.getEditorTyping("Python/InsertImport") + self.__importBraceType = \ + Preferences.getEditorTyping("Python/ImportBraceType") self.__insertSelf = \ Preferences.getEditorTyping("Python/InsertSelf") self.__insertBlank = \ @@ -148,8 +148,12 @@ elif char == ' ': txt = self.editor.text(line)[:col] if self.__insertImport and self.__importRX.exactMatch(txt): - self.editor.insert('import ') - self.editor.setCursorPosition(line, col + 7) + if self.__importBraceType: + self.editor.insert('import ()') + self.editor.setCursorPosition(line, col + 8) + else: + self.editor.insert('import ') + self.editor.setCursorPosition(line, col + 7) elif self.__dedentElse and self.__elifRX.exactMatch(txt): self.__dedentToIf() elif self.__dedentExcept and self.__exceptRX.exactMatch(txt): @@ -211,23 +215,31 @@ if self.__indentBrace: txt = self.editor.text(line - 1) if re.search(":\r?\n", txt) is None: - openCount = len(re.findall("[({[]", txt)) - closeCount = len(re.findall(r"[)}\]]", txt)) - if openCount > closeCount: - openCount = 0 - closeCount = 0 - openList = list(re.finditer("[({[]", txt)) - index = len(openList) - 1 - while index > -1 and openCount == closeCount: - lastOpenIndex = openList[index].start() - txt2 = txt[lastOpenIndex:] - openCount = len(re.findall("[({[]", txt2)) - closeCount = len(re.findall(r"[)}\]]", txt2)) - index -= 1 - if openCount > closeCount and lastOpenIndex > col: - self.editor.insert(' ' * (lastOpenIndex - col + 1)) - self.editor.setCursorPosition( - line, lastOpenIndex + 1) + stxt = txt.strip() + if stxt and stxt[-1] in ("(", "[", "{"): + # indent one more level + self.editor.indent(line) + self.editor.editorCommand(QsciScintilla.SCI_VCHOME) + else: + # indent to the level of the opening brace + openCount = len(re.findall("[({[]", txt)) + closeCount = len(re.findall(r"[)}\]]", txt)) + if openCount > closeCount: + openCount = 0 + closeCount = 0 + openList = list(re.finditer("[({[]", txt)) + index = len(openList) - 1 + while index > -1 and openCount == closeCount: + lastOpenIndex = openList[index].start() + txt2 = txt[lastOpenIndex:] + openCount = len(re.findall("[({[]", txt2)) + closeCount = len(re.findall(r"[)}\]]", txt2)) + index -= 1 + if openCount > closeCount and lastOpenIndex > col: + self.editor.insert( + ' ' * (lastOpenIndex - col + 1)) + self.editor.setCursorPosition( + line, lastOpenIndex + 1) def __dedentToIf(self): """ @@ -313,26 +325,15 @@ while tryLine >= 0: txt = self.editor.text(tryLine) edInd = self.editor.indentation(tryLine) - if self.__py24StyleTry: - if (self.__exceptcRX.indexIn(txt) == 0 or - self.__exceptRX.indexIn(txt) == 0 or - self.__finallyRX.indexIn(txt) == 0) and \ - edInd <= indentation: - indentation = edInd - 1 - elif self.__tryRX.indexIn(txt) == 0 and edInd <= indentation: - self.editor.cancelList() - self.editor.setIndentation(line, edInd) - break - else: - if self.__finallyRX.indexIn(txt) == 0 and edInd <= indentation: - indentation = edInd - 1 - elif (self.__tryRX.indexIn(txt) == 0 or - self.__exceptcRX.indexIn(txt) == 0 or - self.__exceptRX.indexIn(txt) == 0) and \ - edInd <= indentation: - self.editor.cancelList() - self.editor.setIndentation(line, edInd) - break + if self.__finallyRX.indexIn(txt) == 0 and edInd <= indentation: + indentation = edInd - 1 + elif (self.__tryRX.indexIn(txt) == 0 or + self.__exceptcRX.indexIn(txt) == 0 or + self.__exceptRX.indexIn(txt) == 0) and \ + edInd <= indentation: + self.editor.cancelList() + self.editor.setIndentation(line, edInd) + break tryLine -= 1 def __dedentDefStatement(self):