简体   繁体   中英

Emacs: syntax highlighting quirks in python-mode

I run GNU Emacs 23.3.1. When I do python programming (chiefly version 2.7), I notice two small, but rather annoying syntax highlighting discrepancies. One is highlighting of variable names; they are only highlighted if written in a block that has zero indentation and no other aspects to it. Example:

A = 0
B, C = 0, 0
def f():
    D = 0

In this case, A is highlighted, while B, C, and D is not. What causes this, and is it possible find and change it? I'd rather have all variables highlighted always, but if that is tricky, then not highlighting variables (while retaining all other highlighting and not changing any other modes) is an alternative.

The other discrepancy is related to the print statement and special variables like file, map and range (and any other word that is similarly highlighted):

print file

In this case, file is not highlighted.

print file, file

In this case however, the first instance of file is not highlighted, while the second is. Keywords that are highlighted differently (no highlighting, True/False, None, etc.) are always consistently highlighted correctly.

This persists if I run emacs nongraphically (emacs -nw). I also tested with other editors (vi, nano and kate) and while highlighting was different (different words and different colors), no discrepansies or inconsistensies were found. I have had no such issues when writing C++, bash or latex with emacs.

With python-mode.el, Mx customize-face RET py-variable-name-face RET

https://launchpad.net/python-mode

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM