#17 Handle triple-quoted strings correctly.

closed
None
5
2015-01-10
2004-09-06
No

This patch adds an option that will color triple-quoted strings
correctly. It works by turning off syntax-highlighting for strings and
comments (by registering quotes and hashes in the syntax table as
normal punctuation); and using a fairly advanced keyword matcher
to find all strings and comments. The keyword matcher uses a text-
property to keep track of the syntax category of each character, and
only updates it as needed. Therefore, the option can only be used if
text-properties are available (but they are available on all current
versions of emacs, as far as I know).

Caveat: it's possible that this will be slow on some machines, or
under certian circumstances. But it's not noticably slower on the
machines & files I've tested it on.

Discussion

  • Skip Montanaro

    Skip Montanaro - 2004-09-07

    Logged In: YES
    user_id=44345

    Edward, perhaps you forgot to check the box when uploading
    the patch? There's nothing currently attached to this item.

    -Skip

     
  • Edward Loper

    Edward Loper - 2004-09-07

    Logged In: YES
    user_id=195958

    So I did. Trying again.

     
  • Edward Loper

    Edward Loper - 2004-09-07

    unified diff against python-mode.el, revision 4.62

     
  • Johannes Gijsbers

    Logged In: YES
    user_id=469548

    I applied this patch to the latest python-mode and while
    triple-quoted-strings mostly work fine (thank you! thank
    you! thank you!), comments seem to be a bit broken. Take a
    look at BaseHTTPServer.py from the Python CVS for a
    particularly bad example.

    I'm running "GNU Emacs 21.3.50.1 (i386-pc-linux-gnu, GTK+
    Version 2.4.10)
    of 2004-10-11 on surfboy, modified by Debian", compiled
    from Emacs CVS using the emacs-snapshot package.

     
  • Skip Montanaro

    Skip Montanaro - 2005-06-04
    • assigned_to: nobody --> edloper
     
  • Skip Montanaro

    Skip Montanaro - 2005-06-04

    Logged In: YES
    user_id=44345

    Ed, this looks like this would be a good addition, but there are
    some problems. Is there any resolution to Johannes' note about
    comment breakage? I just patched my copy of python-mode.el.
    When I visit a .py file it complains that it can't find the
    text-properties package. (This is XEmacs 21.4.15.) I didn't
    see anything like text-properties or properties in the package
    list.

     
  • Daniel

    Daniel - 2005-11-19

    Logged In: YES
    user_id=1383230

    Sorry, how do I install this? I'm using python-mode
    ver1.0alpha, found on the "Files" page.

     
  • Edward Loper

    Edward Loper - 2006-03-11

    unified diff against python-mode.el, revision 4.78

     
  • Edward Loper

    Edward Loper - 2006-03-11

    Logged In: YES
    user_id=195958

    I have attached a new version of the patch, which should
    hopefully address both Skip's issue, and the problem that
    Johannes Gijsbers pointed out.

    I'd appreciate it if several people could try it out
    (preferably on both emacs and xemacs), and let me know if
    it works.

    danielx_: download the patch file (handle-tqs-v2.diff) at
    the bottom of this page, and run "patch python-mode.el
    handle-tqs-v2.diff".

    The changes I made were:

    - removed (require 'text-properties), since 'text-
    properties isn't defined as a feature in emacs; and it
    should be available by default in both xemacs and emacs,
    anyway.

    - Replaced calls to "replace-regexp-in-string" with a
    compatibility function "py-replace-regexp-in-string",
    since the former is only available on xemacs.

    - Fixed a bug in the regexp used to find the end of
    comments (this was what caused problems in
    BaseHTTPServer.py).

     
  • Ethan Glasser-Camp

    Logged In: YES
    user_id=270121
    Originator: NO

    I tried this on XEmacs and it worked fine so far as I could tell. Thanks a ton!

    XEmacs 21.4 (patch 20) "Double Solitaire" [Lucid] (i486-linux-gnu, Mule) of Sun Mar 25 2007 on penell

    Ethan

     
  • Edward Loper

    Edward Loper - 2007-08-09
    • status: open --> closed
     

Log in to post a comment.