Show
Ignore:
Timestamp:
03/13/08 22:04:55 (8 months ago)
Author:
rob
Message:

Added CStyleAutoindent
* forces an unindent when it sees a line starting with the } character

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/peppy/lib/autoindent.py

    r1166 r1168  
    188188 
    189189 
     190class 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 
    190224class RegexAutoindent(BasicAutoindent): 
    191225    """Regex based autoindenter 
     
    199233    entry<http://www.alweb.dk/blog/anders/autoindentation>} describing his 
    200234    thinking that led up to the creation of the code. 
     235     
     236    The source code for the autoindenting part of Kate is actually in the 
     237    L{kpart<http://websvn.kde.org/branches/KDE/3.5/kdelibs/kate/part/kateautoindent.cpp?revision=620408&view=markup>} 
     238    section of KDE, not with the main Kate application. 
    201239    """ 
    202240