• Guido van Rossum's avatar
    Tim Peters again: · a6be3870
    Guido van Rossum authored
    [Tim, after adding some bracket smarts to AutoIndent.py]
    > ...
    > What it can't possibly do without reparsing large gobs of text is
    > suggest a reasonable indent level after you've *closed* a bracket
    > left open on some previous line.
    > ...
    
    The attached can, and actually fast enough to use -- most of the time.  The
    code is tricky beyond belief to achieve that, but it works so far; e.g.,
    
            return len(string.expandtabs(str[self.stmt_start :
                                             ^ indents to caret
                                             i],
                                         ^ indents to caret
                                         self.tabwidth)) + 1
        ^ indents to caret
    
    It's about as smart as pymode now, wrt both bracket and backslash
    continuation rules.  It does require reparsing large gobs of text, and if it
    happens to find something that looks like a "def" or "class" or sys.ps1
    buried in a multiline string, but didn't suck up enough preceding text to
    see the start of the string, it's completely hosed.  I can't repair that --
    it's just too slow to reparse from the start of the file all the time.
    
    AutoIndent has grown a new num_context_lines tuple attribute that controls
    how far to look back, and-- like other params --this could/should be made
    user-overridable at startup and per-file on the fly.
    a6be3870
AutoIndent.py 19.2 KB