Betacantrips/ bits/ IDE Python Triple-Quote Shootout

It turns out that emacs's current python-mode (and xemacs too) doesn't handle certain triple-quoted strings properly. In fact, they don't handle them at all; they match single-quoted strings as follows:

"""Text"""
[][----][]

That is, the first pair of quotes is matched as an empty string, and the last pair is matched as an empty string, and anything in the middle is matched as in an ordinary string. Meaning that misparses can happen if you try:

"""This is a double quote: ". Still in the quote!"""
[][------------------------]                     [][

Of course, you can escape the quote, but that gets old fast:

"""This is a double quote: \". Still in the quote!"""
[][-----------------------------------------------][]

There is a patch in sourceforge. You might be overwhelmed by the complexity of the solution -- I was, and so I poked around the emacs documentation and came to the conclusion that the emacs syntax-highlighting engine is not designed for this sort of thing. The Emacs modify-syntax call appears to take a bunch of flags, which (taken together) allow comment delimiters of two characters but that's it. Every other syntax class begins and ends with a single character.

Spurred by a discussion on the Internet, I decided to see how some other editors fare on this problem.

First up is emacs/xemacs. (This is without python-mode from sourceforge.)

Both fail. (I think python-mode is shared across emacsen here.)

Next I decided to try the old rival, vim:

It passes.

I tried Kate:

KWrite is the same, only with a fixed-width font.

For fun I tried Python-specific IDEs Eric and Idle:

I don't use Eric much, or else I might go crazy -- man, what a busy interface!

Not surprisingly, both pass. I decided any Python-specific IDE probably would, so I switched back to generic IDEs.

Here's jed:

It fails. I decided to add another line of comment so it was clearer what went wrong. Note also the color of the period.

Here's something called fte that I turned up in aptitude:

It passes.

I finally figured out that an appropriate GNOME editor would be Gedit:

It also passes.

So, most editors with special Python modes handle this case correctly. Those that don't, handle it incorrectly in a particular way -- they fall back on single-quote-parsing to handle it, which means it can be interrupted by a single quote. Those editors are: jed and emacs.

Of course, this is a pretty minor acid-test for an editor. Unfortunately, I don't have the time to really use each of these editors and form a thorough, grounded opinion on them. Take this analysis, if you could even dignify it with that term, with a grain of salt, but enjoy the pretty pictures.

Blue Sky design by Jonas John.