QScintilla/TypingCompleters/CompleterPython.py

changeset 3011
18292228c724
parent 2965
d133c7edd88a
child 3034
7ce719013078
child 3057
10516539f238
equal deleted inserted replaced
3010:befeff46ec0f 3011:18292228c724
56 56
57 def readSettings(self): 57 def readSettings(self):
58 """ 58 """
59 Public slot called to reread the configuration parameters. 59 Public slot called to reread the configuration parameters.
60 """ 60 """
61 self.setEnabled(Preferences.getEditorTyping("Python/EnabledTypingAids")) 61 self.setEnabled(
62 Preferences.getEditorTyping("Python/EnabledTypingAids"))
62 self.__insertClosingBrace = \ 63 self.__insertClosingBrace = \
63 Preferences.getEditorTyping("Python/InsertClosingBrace") 64 Preferences.getEditorTyping("Python/InsertClosingBrace")
64 self.__indentBrace = \ 65 self.__indentBrace = \
65 Preferences.getEditorTyping("Python/IndentBrace") 66 Preferences.getEditorTyping("Python/IndentBrace")
66 self.__skipBrace = \ 67 self.__skipBrace = \
89 Public slot called to handle the user entering a character. 90 Public slot called to handle the user entering a character.
90 91
91 @param charNumber value of the character entered (integer) 92 @param charNumber value of the character entered (integer)
92 """ 93 """
93 char = chr(charNumber) 94 char = chr(charNumber)
94 if char not in ['(', ')', '{', '}', '[', ']', ' ', ',', "'", '"', '\n', ':']: 95 if char not in ['(', ')', '{', '}', '[', ']', ' ', ',', "'", '"',
96 '\n', ':']:
95 return # take the short route 97 return # take the short route
96 98
97 line, col = self.editor.getCursorPosition() 99 line, col = self.editor.getCursorPosition()
98 100
99 if self.__inComment(line, col) or \ 101 if self.__inComment(line, col) or \
133 if self.__skipBrace: 135 if self.__skipBrace:
134 self.editor.setSelection(line, col, line, col + 1) 136 self.editor.setSelection(line, col, line, col + 1)
135 self.editor.removeSelectedText() 137 self.editor.removeSelectedText()
136 138
137 # space 139 # space
138 # insert import, dedent to if for elif, dedent to try for except, dedent def 140 # insert import, dedent to if for elif, dedent to try for except,
141 # dedent def
139 elif char == ' ': 142 elif char == ' ':
140 txt = self.editor.text(line)[:col] 143 txt = self.editor.text(line)[:col]
141 if self.__insertImport and self.__importRX.exactMatch(txt): 144 if self.__insertImport and self.__importRX.exactMatch(txt):
142 self.editor.insert('import ') 145 self.editor.insert('import ')
143 self.editor.setCursorPosition(line, col + 7) 146 self.editor.setCursorPosition(line, col + 7)
215 openCount = len(re.findall("[({[]", txt2)) 218 openCount = len(re.findall("[({[]", txt2))
216 closeCount = len(re.findall("[)}\]]", txt2)) 219 closeCount = len(re.findall("[)}\]]", txt2))
217 index -= 1 220 index -= 1
218 if openCount > closeCount and lastOpenIndex > col: 221 if openCount > closeCount and lastOpenIndex > col:
219 self.editor.insert(' ' * (lastOpenIndex - col + 1)) 222 self.editor.insert(' ' * (lastOpenIndex - col + 1))
220 self.editor.setCursorPosition(line, lastOpenIndex + 1) 223 self.editor.setCursorPosition(
224 line, lastOpenIndex + 1)
221 225
222 def __dedentToIf(self): 226 def __dedentToIf(self):
223 """ 227 """
224 Private method to dedent the last line to the last if statement with 228 Private method to dedent the last line to the last if statement with
225 less (or equal) indentation. 229 less (or equal) indentation.
303 txt = self.editor.text(tryLine) 307 txt = self.editor.text(tryLine)
304 edInd = self.editor.indentation(tryLine) 308 edInd = self.editor.indentation(tryLine)
305 if self.__py24StyleTry: 309 if self.__py24StyleTry:
306 if (self.__exceptcRX.indexIn(txt) == 0 or \ 310 if (self.__exceptcRX.indexIn(txt) == 0 or \
307 self.__exceptRX.indexIn(txt) == 0 or \ 311 self.__exceptRX.indexIn(txt) == 0 or \
308 self.__finallyRX.indexIn(txt) == 0) and edInd <= indentation: 312 self.__finallyRX.indexIn(txt) == 0) and \
313 edInd <= indentation:
309 indentation = edInd - 1 314 indentation = edInd - 1
310 elif self.__tryRX.indexIn(txt) == 0 and edInd <= indentation: 315 elif self.__tryRX.indexIn(txt) == 0 and edInd <= indentation:
311 self.editor.cancelList() 316 self.editor.cancelList()
312 self.editor.setIndentation(line, edInd) 317 self.editor.setIndentation(line, edInd)
313 break 318 break
314 else: 319 else:
315 if self.__finallyRX.indexIn(txt) == 0 and edInd <= indentation: 320 if self.__finallyRX.indexIn(txt) == 0 and edInd <= indentation:
316 indentation = edInd - 1 321 indentation = edInd - 1
317 elif (self.__tryRX.indexIn(txt) == 0 or \ 322 elif (self.__tryRX.indexIn(txt) == 0 or \
318 self.__exceptcRX.indexIn(txt) == 0 or \ 323 self.__exceptcRX.indexIn(txt) == 0 or \
319 self.__exceptRX.indexIn(txt) == 0) and edInd <= indentation: 324 self.__exceptRX.indexIn(txt) == 0) and \
325 edInd <= indentation:
320 self.editor.cancelList() 326 self.editor.cancelList()
321 self.editor.setIndentation(line, edInd) 327 self.editor.setIndentation(line, edInd)
322 break 328 break
323 tryLine -= 1 329 tryLine -= 1
324 330
325 def __dedentDefStatement(self): 331 def __dedentDefStatement(self):
326 """ 332 """
327 Private method to dedent the line of the def statement to a previous def 333 Private method to dedent the line of the def statement to a previous
328 statement or class statement. 334 def statement or class statement.
329 """ 335 """
330 line, col = self.editor.getCursorPosition() 336 line, col = self.editor.getCursorPosition()
331 indentation = self.editor.indentation(line) 337 indentation = self.editor.indentation(line)
332 tryLine = line - 1 338 tryLine = line - 1
333 while tryLine >= 0: 339 while tryLine >= 0:
416 col -= 1 422 col -= 1
417 return False 423 return False
418 424
419 def __inDoubleQuotedString(self): 425 def __inDoubleQuotedString(self):
420 """ 426 """
421 Private method to check, if the cursor is within a double quoted string. 427 Private method to check, if the cursor is within a double quoted
428 string.
422 429
423 @return flag indicating, if the cursor is inside a double 430 @return flag indicating, if the cursor is inside a double
424 quoted string (boolean) 431 quoted string (boolean)
425 """ 432 """
426 return self.editor.currentStyle() == QsciLexerPython.DoubleQuotedString 433 return self.editor.currentStyle() == QsciLexerPython.DoubleQuotedString
427 434
428 def __inTripleDoubleQuotedString(self): 435 def __inTripleDoubleQuotedString(self):
429 """ 436 """
430 Private method to check, if the cursor is within a triple double quoted string. 437 Private method to check, if the cursor is within a triple double
438 quoted string.
431 439
432 @return flag indicating, if the cursor is inside a triple double 440 @return flag indicating, if the cursor is inside a triple double
433 quoted string (boolean) 441 quoted string (boolean)
434 """ 442 """
435 return self.editor.currentStyle() == QsciLexerPython.TripleDoubleQuotedString 443 return self.editor.currentStyle() == \
444 QsciLexerPython.TripleDoubleQuotedString
436 445
437 def __inSingleQuotedString(self): 446 def __inSingleQuotedString(self):
438 """ 447 """
439 Private method to check, if the cursor is within a single quoted string. 448 Private method to check, if the cursor is within a single quoted
449 string.
440 450
441 @return flag indicating, if the cursor is inside a single 451 @return flag indicating, if the cursor is inside a single
442 quoted string (boolean) 452 quoted string (boolean)
443 """ 453 """
444 return self.editor.currentStyle() == QsciLexerPython.SingleQuotedString 454 return self.editor.currentStyle() == QsciLexerPython.SingleQuotedString
445 455
446 def __inTripleSingleQuotedString(self): 456 def __inTripleSingleQuotedString(self):
447 """ 457 """
448 Private method to check, if the cursor is within a triple single quoted string. 458 Private method to check, if the cursor is within a triple single
459 quoted string.
449 460
450 @return flag indicating, if the cursor is inside a triple single 461 @return flag indicating, if the cursor is inside a triple single
451 quoted string (boolean) 462 quoted string (boolean)
452 """ 463 """
453 return self.editor.currentStyle() == QsciLexerPython.TripleSingleQuotedString 464 return self.editor.currentStyle() == \
465 QsciLexerPython.TripleSingleQuotedString

eric ide

mercurial