How do I change the font Emacs font for Python Docstrings?

I am just starting to learn Python and use Emacs as my editor. Emacs currently uses the same color for regular strings (single quotes) and docstrings (triple quotes). I want the docstrings to be a different color, so I used the "Options-> Customize Emacs" option to change the "font-lock-doc-face" to a new color and save the changes. However, Emacs continues to maintain the dockedros of the same color as regular strings. Changing the color of regular strings also changes the dockstrong.

It would seem that Emacs treats docstrings and regular strings as the same thing. Is there a way to get Emacs to correctly find colored Python Docstrings separately from regular strings?

Edit: I am using Emacs 23.1.1 (Kubuntu 10.10 package) with the default Python mode settings. I also use a color theme pack with a midnight theme.

+6
python emacs docstring emacs-faces
source share
1 answer

Interesting. I was going to say that because of the way the emacs syntax table works, emacs thinks that the """ and ''' represent the empty line represented by the start of a new line.

You can easily verify this in your copy of emacs by pasting the following code into the python buffer:

 class MrsRobinson(object): ''' What that you say? ''' pass 

In emacs 23.1.1 [ update: and apparently in stackoveflow!], This completely breaks the syntax highlighting for the rest of the file.

I always use """ specifically to avoid problems with the apostrophe in docstrings, so I haven’t noticed until this minute that in emacs 23.2.1 this is somehow finally fixed ...

(Yes, the new function is called python-quote-syntax in python.el)

So: in your version of emacs this is not possible because strings are not processed correctly. If you upgrade to the latest emacs, you can do this by changing this function in python.el to handle them differently.

+1
source share

All Articles