| | 190 | class CStyleAutoindent(BasicAutoindent): |
| | 191 | """Use the STC Folding to reindent a line in a C-like mode. |
| | 192 | |
| | 193 | This autoindenter uses the built-in Scintilla folding to determine the |
| | 194 | correct indent level for C-like modes (C, C++, Java, Javascript, etc.) |
| | 195 | plus a bunch of heuristics to handle things that Scintilla doesn't. |
| | 196 | """ |
| | 197 | debuglevel = 1 |
| | 198 | def findIndent(self, stc, linenum=None): |
| | 199 | """Reindent the specified line to the correct level. |
| | 200 | |
| | 201 | Given a line, use Scintilla's built-in folding to determine |
| | 202 | the indention level of the current line. |
| | 203 | """ |
| | 204 | if linenum is None: |
| | 205 | linenum = stc.GetCurrentLine() |
| | 206 | linestart = stc.PositionFromLine(linenum) |
| | 207 | |
| | 208 | # actual indention of current line |
| | 209 | col = stc.GetLineIndentation(linenum) # columns |
| | 210 | pos = stc.GetLineIndentPosition(linenum) # absolute character position |
| | 211 | |
| | 212 | # folding says this should be the current indention |
| | 213 | fold = stc.GetFoldLevel(linenum)&wx.stc.STC_FOLDLEVELNUMBERMASK - wx.stc.STC_FOLDLEVELBASE |
| | 214 | c = stc.GetCharAt(pos) |
| | 215 | self.dprint("col=%d (pos=%d), fold=%d char=%s" % (col, pos, fold, c)) |
| | 216 | if c == ord('}'): |
| | 217 | # Scintilla doesn't automatically dedent the closing brace, so we |
| | 218 | # force that here. |
| | 219 | fold -= 1 |
| | 220 | |
| | 221 | return fold * stc.GetIndent() |
| | 222 | |
| | 223 | |