Handle triple-quoted strings correctly: take 2

Bug #328841 reported by Edloper
2
Affects Status Importance Assigned to Milestone
python-mode.el
Fix Released
Medium
Andreas Roehler

Bug Description

This patch uses font-lock-mode's syntactic keyword feature to ensure that
triple quoted strings are displayed correctly. In particular, it defines a
font-lock-syntactic-keywords table that finds any quote marks that should
not be considered string delimiters because they occur inside triple-quoted
strings, and sets their syntactic designation to "normal punctuation" (the
same designation used for e.g. operators).

This is a more principled approach than my previous attempt to fix
python-mode's handling of triple-quoted strings [1], and as a result the
patch is about a third as big, and should never incur any serious
overhead.

This patch has been tested successfully on the following emacs variants:

XEmacs 21.4 (patch 13) (i386-redhat-linux)
XEmacs 21.4 (patch 17) (i386-debian-linux)
GNU Emacs 21.3.1 (i386-wingw-nt5.1.2600)
GNU Emacs 21.3.1 (i386-redhat-linux-gnu)
GNU Emacs 22.0.50.1 (powerpc-apple-darwin8.3.0)

I am also including the file test-triple-strings.py, which contains a bunch
of test cases to make sure the mode is working correctly. This file is
*not* intended to be run -- it is intended to be opened in python-mode, and
examined by hand to verify that the correct faces are used. I included
test cases for every corner case that I thought of (e.g. interactions
between backslashes and quotes, and cases with more than 3 quotes in a
row).

The new behavior can be turned off using the customization constant
"py-syntactic-triple-quoted-strings" (default=t), but I don't expect that
to ever be necessary.

I am retiring my previous patch with the same goal [1] -- this patch
supsercedes it.

If this patch looks acceptable, let me know, and I can commit it. (Or feel
free to commit it yourself.) It might be good to include the test file,
possibly in a "tests/" subdirectory.

[1]
http://sourceforge.net/tracker/index.php?func=detail&aid=1023335&group_id=8
6916&atid=581351

[http://sourceforge.net/tracker/index.php?func=detail&aid=1770556&group_id=86916&atid=581351]

Revision history for this message
Edloper (edloper) wrote :
Revision history for this message
Edloper (edloper) wrote :

Originator: YES

File Added: test-triple-strings.py

Revision history for this message
Glasserc (glasserc) wrote :

Originator: NO

Hi,

I'm not qualified to review your patch, but I did test it on my machine:
XEmacs 21.4 (patch 20) (i386-debian-linux). It works better than the last
patch, including not being confused by colons or parens inside strings.
Thanks for your time and effort!

Ethan

Revision history for this message
Andreas Roehler (a-roehler) wrote :

Hi,

unfortunately the other patch committed, herewith linked with, fixes the issue in GNU Emacs but not for XEmacs AFAIS.

Maybe we should try both?

Andreas

Revision history for this message
Georg Brandl (gbrandl) wrote :

IMO the fix is not complete for GNU Emacs either, as you can see from the problem when filling triple-quoted docstrings.

Changed in python-mode:
assignee: nobody → Andreas Roehler (a-roehler)
status: New → Confirmed
Revision history for this message
Andreas Roehler (a-roehler) wrote :

XEmacs only:

No remarkable success so far with patch applied at

https://code.launchpad.net/~a-roehler/python-mode/ed-loper-tqs-diff

Did not merge cleanly, as the code differs meanwhile. Had to tweak it; the error might be mine.

Revision history for this message
Georg Brandl (gbrandl) wrote :

Note that python.el's python-font-lock-syntactic-keywords have changed since you copied them to python-mode.el. Maybe an update would be in order?

Revision history for this message
Andreas Roehler (a-roehler) wrote : Re: [Bug 328841] Re: Handle triple-quoted strings correctly: take 2

Am 11.01.2011 19:51, schrieb Georg Brandl:
> Note that python.el's python-font-lock-syntactic-keywords have changed
> since you copied them to python-mode.el. Maybe an update would be in
> order?
>

Thanks, maybe.

Could you send a diff?
Is there a related bug report?

Revision history for this message
Andreas Roehler (a-roehler) wrote :

Tests with test-triple-strings.py delivered here now work for me with paragraph-fill-warts branch too.

Closing this.

Changed in python-mode:
status: Confirmed → Fix Committed
Changed in python-mode:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.