[Python-checkins] CVS: python/dist/src/Tools/idle AutoIndent.py

Guido van Rossum guido@cnri.reston.va.us
Tue, 1 Jun 1999 15:52:34 -0400 (EDT)

Update of /projects/cvsroot/python/dist/src/Tools/idle
In directory eric:/projects/python/develop/guido/src/Tools/idle

Modified Files:
Log Message:
Tim Peters again:

[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
                                     ^ 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.