31 super().__init__(editor, parent) |
31 super().__init__(editor, parent) |
32 |
32 |
33 self.__beginRX = re.compile(r"""^=begin """) |
33 self.__beginRX = re.compile(r"""^=begin """) |
34 self.__beginNlRX = re.compile(r"""^=begin\r?\n""") |
34 self.__beginNlRX = re.compile(r"""^=begin\r?\n""") |
35 self.__hereRX = re.compile(r"""<<-?['"]?(\w*)['"]?\r?\n""") |
35 self.__hereRX = re.compile(r"""<<-?['"]?(\w*)['"]?\r?\n""") |
|
36 |
|
37 self.__trailingBlankRe = re.compile(r"(?:,)(\s*)\r?\n") |
36 |
38 |
37 self.readSettings() |
39 self.readSettings() |
38 |
40 |
39 def readSettings(self): |
41 def readSettings(self): |
40 """ |
42 """ |
71 or self.__inInlineDocument() |
73 or self.__inInlineDocument() |
72 ): |
74 ): |
73 return |
75 return |
74 |
76 |
75 # open parenthesis |
77 # open parenthesis |
76 # insert closing parenthesis and self |
78 # insert closing parenthesis |
77 if char == "(": |
79 if char == "(" and self.__insertClosingBrace: |
78 txt = self.editor.text(line)[:col] |
80 self.editor.insert(")") |
79 if self.__insertClosingBrace: |
81 |
80 self.editor.insert(")") |
82 # open curly bracket |
|
83 # insert closing bracket |
|
84 if char == "{" and self.__insertClosingBrace: |
|
85 self.editor.insert("}") |
|
86 |
|
87 # open bracket |
|
88 # insert closing bracket |
|
89 elif char == "[" and self.__insertClosingBrace: |
|
90 self.editor.insert("]") |
81 |
91 |
82 # closing parenthesis |
92 # closing parenthesis |
83 # skip matching closing parenthesis |
93 # skip matching closing parenthesis |
84 elif char in [")", "}", "]"]: |
94 elif char in [")", "}", "]"]: |
85 txt = self.editor.text(line) |
95 txt = self.editor.text(line) |
122 |
132 |
123 # new line |
133 # new line |
124 # indent to opening brace, complete inline documentation |
134 # indent to opening brace, complete inline documentation |
125 elif char == "\n": |
135 elif char == "\n": |
126 txt = self.editor.text(line - 1) |
136 txt = self.editor.text(line - 1) |
|
137 if self.__insertBlank and self.__trailingBlankRe.search(txt): |
|
138 match = self.__trailingBlankRe.search(txt) |
|
139 if match is not None: |
|
140 startBlanks = match.start(1) |
|
141 endBlanks = match.end(1) |
|
142 if startBlanks != -1 and startBlanks != endBlanks: |
|
143 # previous line ends with whitespace, e.g. caused by |
|
144 # blank insertion above |
|
145 self.editor.setSelection( |
|
146 line - 1, startBlanks, line - 1, endBlanks |
|
147 ) |
|
148 self.editor.removeSelectedText() |
|
149 # get the line again for next check |
|
150 txt = self.editor.text(line - 1) |
|
151 |
|
152 self.editor.setCursorPosition(line, 0) |
|
153 self.editor.editorCommand(QsciScintilla.SCI_VCHOME) |
|
154 |
127 if self.__insertInlineDoc and self.__beginNlRX.fullmatch(txt): |
155 if self.__insertInlineDoc and self.__beginNlRX.fullmatch(txt): |
128 self.editor.insert("=end") |
156 self.editor.insert("=end") |
129 elif self.__insertHereDoc and self.__hereRX.fullmatch(txt): |
157 elif self.__insertHereDoc and self.__hereRX.fullmatch(txt): |
130 self.editor.insert(self.__hereRX.fullmatch(txt).group(1)) |
158 self.editor.insert(self.__hereRX.fullmatch(txt).group(1)) |
131 elif self.__indentBrace and re.search(":\r?\n", txt) is None: |
159 elif self.__indentBrace and re.search(":\r?\n", txt) is None: |