tags:

views:

144

answers:

2

Running GNU Emacs 22.2.1 on Ubuntu 9.04.

When editing python code in emacs, if a docstring contains an apostrophe, emacs highlights all following code as a comment, until another apostrophe is used. Really annoying!

In other words, if I have a docstring like this:

''' This docstring has an apostrophe ' '''

Then all following code is highlighted as a comment. Comments are highlighted as code.

I can escape the docstring to avoid this, like this:

''' This docstring has an escaped apostrophe \' '''

Then highlighting is fine, but then it looks funny and unnecessary to other devs on my team, and I get made fun of for using emacs since " it can't handle apostrophies". ;)

So, anyone know how to make emacs behave better in this regard?

Thanks,

Josh

+1  A: 

It may be an emacs bug, but it could also be by purpose. If you insert doctests in your docstrings, as I often do to explain API, I could even wish to have the full python syntax highlighting inside docstrings.

But it's probably a bug... (probably emacs syntax highlighter just care of simple and double quotes and ignore triple simple and triple doubles). If so, you should use triple double quotes instead of triple simple quotes as in your example (as far as I know most users use triple double quotes for docstring), and you won't have the problem.

kriss
+6  A: 

This appears to work correctly in GNU Emacs 23.2.1. If it's not practical to upgrade, you might be able to copy python.el out of the Emacs 23 source code, or perhaps just the relevant pieces of it (python-quote-syntax, python-font-lock-syntactic-keywords, and the code that uses the latter, I think - I'm not much of an Elisp hacker).

Unfortunately savannah.gnu.org's bzr browser isn't working just now so I can't point you directly at the code, you'll have to download it. See http://www.gnu.org/software/emacs/

Zack
Building 23.2 now. Hopefully that fixes it.
Josh
Yup fixed. Thanks.
Josh
FWIW, I also noticed this issue when using a version of python-mode.el with Emacs 23.1. I've since removed that and dropped the python.el.gz from Emacs 23.2 into /usr/local/share/emacs/23.1/site-lisp/, and all seems well thus far.
phils