VIM and [Python] block jumping
C. Laurence Gonsalves
clgonsal at kami.com
Tue Jul 13 17:53:23 EDT 1999
Tim Peters wrote:
>
> [C. Laurence Gonsalves]
> > ...
> > The blockMotion function doesn't account for lines that are
> > continuations of other lines. That means that triple-quoted string
> > literals, lines with more {[('s that }])'s, and lines joined with \ can
> > screw it up. Are there any other situations?
>
> No, those are the only ways a line can get continued in Python. Note that
> there are subtleties, like that a backslash preceding a newline doesn't
> *always* mean continuation (it doesn't at the tail end of a comment!).
I was meaning to test some of those weird cases.
> Also single-quoted strings continued via backslash. Strings are the real
> headache, because the special characters you're looking for lose their magic
> when they're inside a string.
Yup, but I'd thought of a simple way to determine if I'm in a string
though...
> The current CVS version of IDLE has a new module PyParse.py, which does the
> minimum necessary to determine whether a line is part of a continuation, and
> if so why. It can do this 100x faster than tokenize, even in
> non-pathological programs. The next version of IDLE uses this to do Emacs
> pymode-like "very smart" indentation, and the next version of Mark Hammond's
> PythonWin also uses this module.
>
> It's GUI-independent (straight self-contained Python), but as called from
> AutoIndent.py (also shared between IDLE and PythonWin) takes major advantage
> of the host system's colorization, to get a fast answer to the question "is
> this random character in a string?". The colorizer generally knows this
> already, for every character in the program, and AutoIdent/PyParse use that
> to find a good (close) place to begin reparsing the file.
That's exactly what I was thinking of doing. It's possible to ask Vim
what syntax highlighting a character is getting. That would make it easy
to determine if a \ is in a string, for example.
Is PyParse available any way other than from IDLE CVS?
Thanks.
--
C. Laurence Gonsalves clgonsal at kami.com
http://www.cryogen.com/clgonsal/
"Any sufficiently advanced technology is indistinguishable from
magic."
-- Arthur C.
Clarke
More information about the Python-list
mailing list