QScintilla/TypingCompleters/CompleterPython.py

changeset 1222
161e4514253b
parent 945
8cd4d08fa9f6
child 1509
c0b5e693b0eb
equal deleted inserted replaced
1221:291dc0a51947 1222:161e4514253b
34 self.__defSelfRX = QRegExp(r"""^[ \t]*def \w+\([ \t]*self[ \t]*[,)]""") 34 self.__defSelfRX = QRegExp(r"""^[ \t]*def \w+\([ \t]*self[ \t]*[,)]""")
35 self.__defClsRX = QRegExp(r"""^[ \t]*def \w+\([ \t]*cls[ \t]*[,)]""") 35 self.__defClsRX = QRegExp(r"""^[ \t]*def \w+\([ \t]*cls[ \t]*[,)]""")
36 self.__classRX = QRegExp(r"""^[ \t]*class \w+\(""") 36 self.__classRX = QRegExp(r"""^[ \t]*class \w+\(""")
37 self.__importRX = QRegExp(r"""^[ \t]*from [\w.]+ """) 37 self.__importRX = QRegExp(r"""^[ \t]*from [\w.]+ """)
38 self.__classmethodRX = QRegExp(r"""^[ \t]*@classmethod""") 38 self.__classmethodRX = QRegExp(r"""^[ \t]*@classmethod""")
39 self.__staticmethodRX = QRegExp(r"""^[ \t]*@staticmethod""")
39 40
40 self.__defOnlyRX = QRegExp(r"""^[ \t]*def """) 41 self.__defOnlyRX = QRegExp(r"""^[ \t]*def """)
41 42
42 self.__ifRX = QRegExp(r"""^[ \t]*if """) 43 self.__ifRX = QRegExp(r"""^[ \t]*if """)
43 self.__elifRX = QRegExp(r"""^[ \t]*elif """) 44 self.__elifRX = QRegExp(r"""^[ \t]*elif """)
106 # insert closing parenthesis and self 107 # insert closing parenthesis and self
107 if char == '(': 108 if char == '(':
108 txt = self.editor.text(line)[:col] 109 txt = self.editor.text(line)[:col]
109 if self.__insertSelf and \ 110 if self.__insertSelf and \
110 self.__defRX.exactMatch(txt): 111 self.__defRX.exactMatch(txt):
111 if self.__isClassmethodDef(): 112 if self.__isClassMethodDef():
112 self.editor.insert('cls') 113 self.editor.insert('cls')
113 self.editor.setCursorPosition(line, col + 3) 114 self.editor.setCursorPosition(line, col + 3)
115 elif self.__isStaticMethodDef():
116 # nothing to insert
117 pass
114 elif self.__isClassMethod(): 118 elif self.__isClassMethod():
115 self.editor.insert('self') 119 self.editor.insert('self')
116 self.editor.setCursorPosition(line, col + 4) 120 self.editor.setCursorPosition(line, col + 4)
117 if self.__insertClosingBrace: 121 if self.__insertClosingBrace:
118 if self.__defRX.exactMatch(txt) or \ 122 if self.__defRX.exactMatch(txt) or \
363 self.editor.indentation(curLine) <= indentation: 367 self.editor.indentation(curLine) <= indentation:
364 return False 368 return False
365 curLine -= 1 369 curLine -= 1
366 return False 370 return False
367 371
368 def __isClassmethodDef(self): 372 def __isClassMethodDef(self):
369 """ 373 """
370 Private method to check, if the user is defing a classmethod 374 Private method to check, if the user is defing a class method
371 (@classmethod) method. 375 (@classmethod).
372 376
373 @return flag indicating the definition of a classmethod method (boolean) 377 @return flag indicating the definition of a class method (boolean)
374 """ 378 """
375 line, col = self.editor.getCursorPosition() 379 line, col = self.editor.getCursorPosition()
376 indentation = self.editor.indentation(line) 380 indentation = self.editor.indentation(line)
377 curLine = line - 1 381 curLine = line - 1
378 if self.__classmethodRX.indexIn(self.editor.text(curLine)) == 0 and \ 382 if self.__classmethodRX.indexIn(self.editor.text(curLine)) == 0 and \
383 self.editor.indentation(curLine) == indentation:
384 return True
385 return False
386
387 def __isStaticMethodDef(self):
388 """
389 Private method to check, if the user is defing a static method
390 (@staticmethod) method.
391
392 @return flag indicating the definition of a static method (boolean)
393 """
394 line, col = self.editor.getCursorPosition()
395 indentation = self.editor.indentation(line)
396 curLine = line - 1
397 if self.__staticmethodRX.indexIn(self.editor.text(curLine)) == 0 and \
379 self.editor.indentation(curLine) == indentation: 398 self.editor.indentation(curLine) == indentation:
380 return True 399 return True
381 return False 400 return False
382 401
383 def __inComment(self, line, col): 402 def __inComment(self, line, col):

eric ide

mercurial