[Python-mode] [ python-mode-Patches-1770556 ] Handle triple-quoted strings correctly: take 2

SourceForge.net noreply at sourceforge.net
Fri Aug 10 09:07:19 CEST 2007


Patches item #1770556, was opened at 2007-08-08 20:53
Message generated for change (Comment added) made by glasserc
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=581351&aid=1770556&group_id=86916

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Edward Loper (edloper)
Assigned to: Nobody/Anonymous (nobody)
Summary: Handle triple-quoted strings correctly: take 2

Initial Comment:
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=86916&atid=581351


----------------------------------------------------------------------

Comment By: Ethan Glasser-Camp (glasserc)
Date: 2007-08-10 02:07

Message:
Logged In: YES 
user_id=270121
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

----------------------------------------------------------------------

Comment By: Edward Loper (edloper)
Date: 2007-08-08 20:55

Message:
Logged In: YES 
user_id=195958
Originator: YES

File Added: test-triple-strings.py

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=581351&aid=1770556&group_id=86916


More information about the Python-mode mailing list