eric6/QScintilla/TypingCompleters/CompleterRuby.py

changeset 6997
24eabcea4c59
parent 6942
2602857055c5
child 7229
53054eb5b15a
equal deleted inserted replaced
6996:7d5a103bdb76 6997:24eabcea4c59
10 from __future__ import unicode_literals 10 from __future__ import unicode_literals
11 11
12 import re 12 import re
13 13
14 from PyQt5.QtCore import QRegExp 14 from PyQt5.QtCore import QRegExp
15 from PyQt5.Qsci import QsciLexerRuby 15 from PyQt5.Qsci import QsciLexerRuby, QsciScintilla
16 16
17 from .CompleterBase import CompleterBase 17 from .CompleterBase import CompleterBase
18 18
19 import Preferences 19 import Preferences
20 20
139 if self.__insertInlineDoc and self.__beginNlRX.exactMatch(txt): 139 if self.__insertInlineDoc and self.__beginNlRX.exactMatch(txt):
140 self.editor.insert('=end') 140 self.editor.insert('=end')
141 elif self.__insertHereDoc and self.__hereRX.exactMatch(txt): 141 elif self.__insertHereDoc and self.__hereRX.exactMatch(txt):
142 self.editor.insert(self.__hereRX.cap(1)) 142 self.editor.insert(self.__hereRX.cap(1))
143 elif self.__indentBrace and re.search(":\r?\n", txt) is None: 143 elif self.__indentBrace and re.search(":\r?\n", txt) is None:
144 openCount = len(re.findall("[({[]", txt)) 144 stxt = txt.strip()
145 closeCount = len(re.findall(r"[)}\]]", txt)) 145 if stxt and stxt[-1] in ("(", "[", "{"):
146 if openCount > closeCount: 146 # indent one more level
147 openCount = 0 147 self.editor.indent(line)
148 closeCount = 0 148 self.editor.editorCommand(QsciScintilla.SCI_VCHOME)
149 openList = list(re.finditer("[({[]", txt)) 149 else:
150 index = len(openList) - 1 150 # indent to the level of the opening brace
151 while index > -1 and openCount == closeCount: 151 openCount = len(re.findall("[({[]", txt))
152 lastOpenIndex = openList[index].start() 152 closeCount = len(re.findall(r"[)}\]]", txt))
153 txt2 = txt[lastOpenIndex:] 153 if openCount > closeCount:
154 openCount = len(re.findall("[({[]", txt2)) 154 openCount = 0
155 closeCount = len(re.findall(r"[)}\]]", txt2)) 155 closeCount = 0
156 index -= 1 156 openList = list(re.finditer("[({[]", txt))
157 if openCount > closeCount and lastOpenIndex > col: 157 index = len(openList) - 1
158 self.editor.insert(' ' * (lastOpenIndex - col + 1)) 158 while index > -1 and openCount == closeCount:
159 self.editor.setCursorPosition(line, lastOpenIndex + 1) 159 lastOpenIndex = openList[index].start()
160 txt2 = txt[lastOpenIndex:]
161 openCount = len(re.findall("[({[]", txt2))
162 closeCount = len(re.findall(r"[)}\]]", txt2))
163 index -= 1
164 if openCount > closeCount and lastOpenIndex > col:
165 self.editor.insert(' ' * (lastOpenIndex - col + 1))
166 self.editor.setCursorPosition(line,
167 lastOpenIndex + 1)
160 168
161 def __inComment(self, line, col): 169 def __inComment(self, line, col):
162 """ 170 """
163 Private method to check, if the cursor is inside a comment. 171 Private method to check, if the cursor is inside a comment.
164 172

eric ide

mercurial