Emacs Python.el, Syntax Highlighting Quirks
I'm using python.el version 0.23.1 for Emacs right now. The syntax highlighting seems to be a bit off -- any variable name containing an underscore followed by a keyword will result in the keyword being highlighted. Example, "foo_list" will result in "list" being highlighted.
More for my own understanding of Emacs-Lisp than anything (it's not a big deal) how do I go about fixing that. Here is where I think the relevant code is in "python.el", lines 312-318. I suspect the problem is with the definition of "symbol-start" but I have no idea what that name refers to.
(defvar python-font-lock-keywords
;; Keywords
`(,(rx symbol-start
(or "and" "del" "from" "not" "while" "as" "elif" "global" "or" "with"
"assert" "else" "if" "pass" "yield" "break" "except" "import"
"print" "class" "exec" "in" "raise" "continue" "finally" "is"
"return" "def" "for" "lambda" "try" "self")
symbol-end)
One thing I've struggled with in Emacs-Lisp so far is that I am finding it difficult in situations like these to follow names back to their definitions.
Thanks in advance!
When you say you're using python-mode 0.23.1, do you mean the one that comes bundled with Emacs or this one: http://launchpad.net/python-mode ? (which seems to be on version 6.something)
The reason I'm asking is that I can't reproduce what you're seeing. In an empty python buffer, I inserted
def x ():
a_list =3
and "list" is only highlighted when I delete the "a_". I'm using the version bundled with Emacs, with a snapshot version of Emacs so this might be the difference?
Incidentally, the font lock rule that you quote looks right to me: maybe the problem is that in your version "_" isn't set to have symbol syntax? You can check by typing
M-: (string (char-syntax ?_))
when in a python buffer. You should get "_" (which means symbol). If you get "." (punctuation) or something else weird, that probably explains what's gone wrong.
链接地址: http://www.djcxy.com/p/52354.html上一篇: 语法突出显示适用于多个编辑器的工具/语言