1

我是emacs的新手。我从这里开始使用 emacs 的 twilight 主题。import def class try但是我在 python中得到了相同的颜色if。(到目前为止,我只尝试过使用这个主题的 python。)

但是,我想要以下对使用不同的颜色:

  • import and from
  • def and class
  • try and if.

我查看了主题文件并发现font-lock-keyword-face决定了上述关键字的颜色以及与它们相似的关键字的颜色。

那么如何为上述对设置不同的颜色呢?有办法吗?

我在emacs24上。我的怎么了.emacs

4

3 回答 3

1

There's nothing wrong with your .emacs. That's what font lock does: there's a handful of font lock targets--one for types, one for variables, one for keywords, etc. You can customize what face each one gets (e.g., M-x customize, then Faces, Font Lock, Font Lock Faces), and you can configure how each language matches regular expressions to targets. Since those are all keywords, they all get mapped to the keyword face.

If you really want to, you can edit the font-lock-keywords variable set by python-mode to match each keyword separately, and instead of just naming a font-lock target as your facespec, give a list (face FACE PROP VALUE ...), with as many props and values as you prefer. If you really want to do this, you really want to read the docs.

The full details are described in the manual section "Search-based Fontification" (23.6.2 in GNU emacs 23.4; maybe different in your version, but you can find it pretty easily from the Font Lock customize page).

于 2013-10-15T06:28:37.180 回答
1

由于ALLpython.elas中定义了以下关键字python-font-lock-keywords,因此您需要使用不同的字体来胜过其中一些关键字,或者破解这些相同关键字的源以具有不同的字体:

“and” “del” “from” “not” “while” “as” “elif” “global” “or” “with” “assert” “else” “if” “pass” “yield” “break” “except ""import""class""in""raise""continue""finally""is""return""def""for""lambda""try""print""exec""nonlocal""self"。

下面的代码是一个示例,说明如何对python-font-lock-keywords已经定义的一些关键字进行处理python.el——在这个示例中,while是蓝色加粗体;并且,for是绿色的,带有粗体斜体python-font-lock-keywords没有被特别定义的字体所胜过的字体将默认为font-lock-keyword-face- 我也包含了对该字体的示例修改:

(custom-set-faces
  '(font-lock-keyword-face
     ((t (:background "white" :foreground "red" :bold t))))
  )

(defvar lawlist-blue (make-face 'lawlist-blue))
(set-face-attribute 'lawlist-blue nil
  :background "white" :foreground "blue" :bold t)

(defvar lawlist-green (make-face 'lawlist-green))
(set-face-attribute 'lawlist-green nil
  :background "white" :foreground "green" :bold t :italic t)

(defvar lawlist-keywords-01
  (concat "\\b\\(?:"
    (regexp-opt (list "hello" "world" "while" ))
  "\\)\\b"))

(defvar lawlist-keywords-02
  (concat "\\b\\(?:"
    (regexp-opt (list "foo" "bar" "for" ))
  "\\)\\b"))

(font-lock-add-keywords 'python-mode (list

  (list (concat
    "\\("lawlist-keywords-01"\\)") 1 'lawlist-blue t)

  (list (concat
    "\\("lawlist-keywords-02"\\)") 1 'lawlist-green t)

   ))
于 2013-10-15T06:25:45.603 回答
0

它在这里实现:

https://github.com/pdee/pdee

代码库基本上是 python-mode.el 的代码库,但带有内联 Pymacs、公司模式、自动完成

或通过集市获得:

bzr branch lp:python-mode/components-python-mode

这是 python-mode.el 的开发分支

于 2013-10-17T19:19:09.833 回答