emacs python-mode quote in triple quote font-lock problem
Alfred Morgan
amorgan at netlojix.com
Thu Dec 5 14:12:03 EST 2002
I have been looking into the font-lock problem where quotes in triple
quotes confuses font-lock. I feel that I am getting somewhere close to
a solution but I need a push in the right direction. I got the strings
to highlight correctly but only because I changed the quotes from being
string quote syntax "\"" and set them to punctuation syntax "." and then
added a keyword rule to highlight python strings in string-face. The
problem is that when editing inside such a string, i.e. on line "Say
ni.", font-lock doesn't know it is editing inside a string so it
re-fontifies from that line on starting in regular face which then
messes up the highlighting for the rest of the document's strings. You
can get proper highlighting back only until you edit the line that
started the problem "'''Don't say nu," or (font-lock-fontify-buffer) the
whole buffer.
Python font-lock text sample:
def ni():
'''Don't say nu,
Say ni.
'''
print r'''Python'''
return
The following lisp code gets the python strings highlighted properly but
with bad side effects.
Lisp code:
(modify-syntax-entry ?' "." py-mode-syntax-table)
(modify-syntax-entry ?\" "." py-mode-syntax-table)
(font-lock-add-keywords 'python-mode (list (cons py-stringlit-re
font-lock-string-face)))
(python-mode)
(font-lock-fontify-buffer)
-alfred
More information about the Python-list
mailing list