eric6/QScintilla/TypingCompleters/CompleterRuby.py

changeset 7775
4a1db75550bd
parent 7360
9190402e4505
child 7923
91e843545d9a
equal deleted inserted replaced
7774:9eed155411f0 7775:4a1db75550bd
5 5
6 """ 6 """
7 Module implementing a typing completer for Ruby. 7 Module implementing a typing completer for Ruby.
8 """ 8 """
9 9
10
11 import re 10 import re
12 11
13 from PyQt5.QtCore import QRegExp
14 from PyQt5.Qsci import QsciLexerRuby, QsciScintilla 12 from PyQt5.Qsci import QsciLexerRuby, QsciScintilla
15 13
16 from .CompleterBase import CompleterBase 14 from .CompleterBase import CompleterBase
17 15
18 import Preferences 16 import Preferences
29 @param editor reference to the editor object (QScintilla.Editor) 27 @param editor reference to the editor object (QScintilla.Editor)
30 @param parent reference to the parent object (QObject) 28 @param parent reference to the parent object (QObject)
31 """ 29 """
32 super(CompleterRuby, self).__init__(editor, parent) 30 super(CompleterRuby, self).__init__(editor, parent)
33 31
34 self.__beginRX = QRegExp(r"""^=begin """) 32 self.__beginRX = re.compile(r"""^=begin """)
35 self.__beginNlRX = QRegExp(r"""^=begin\r?\n""") 33 self.__beginNlRX = re.compile(r"""^=begin\r?\n""")
36 self.__hereRX = QRegExp(r"""<<-?['"]?(\w*)['"]?\r?\n""") 34 self.__hereRX = re.compile(r"""<<-?['"]?(\w*)['"]?\r?\n""")
37 35
38 self.readSettings() 36 self.readSettings()
39 37
40 def readSettings(self): 38 def readSettings(self):
41 """ 39 """
97 95
98 # space 96 # space
99 # complete inline documentation 97 # complete inline documentation
100 elif char == ' ': 98 elif char == ' ':
101 txt = self.editor.text(line)[:col] 99 txt = self.editor.text(line)[:col]
102 if self.__insertInlineDoc and self.__beginRX.exactMatch(txt): 100 if self.__insertInlineDoc and self.__beginRX.fullmatch(txt):
103 self.editor.insert('=end') 101 self.editor.insert('=end')
104 102
105 # comma 103 # comma
106 # insert blank 104 # insert blank
107 elif char == ',': 105 elif char == ',':
135 133
136 # new line 134 # new line
137 # indent to opening brace, complete inline documentation 135 # indent to opening brace, complete inline documentation
138 elif char == '\n': 136 elif char == '\n':
139 txt = self.editor.text(line - 1) 137 txt = self.editor.text(line - 1)
140 if self.__insertInlineDoc and self.__beginNlRX.exactMatch(txt): 138 if self.__insertInlineDoc and self.__beginNlRX.fullmatch(txt):
141 self.editor.insert('=end') 139 self.editor.insert('=end')
142 elif self.__insertHereDoc and self.__hereRX.exactMatch(txt): 140 elif self.__insertHereDoc and self.__hereRX.fullmatch(txt):
143 self.editor.insert(self.__hereRX.cap(1)) 141 self.editor.insert(self.__hereRX.fullmatch(txt).group(1))
144 elif self.__indentBrace and re.search(":\r?\n", txt) is None: 142 elif self.__indentBrace and re.search(":\r?\n", txt) is None:
145 stxt = txt.strip() 143 stxt = txt.strip()
146 if stxt and stxt[-1] in ("(", "[", "{"): 144 if stxt and stxt[-1] in ("(", "[", "{"):
147 # indent one more level 145 # indent one more level
148 self.editor.indent(line) 146 self.editor.indent(line)

eric ide

mercurial