如何继承/copy并修改一个face?

比如warning这个face的内容是Foreground: #b58900(其他未设置),怎样自己建一个face,继承它的Foreground,再添加一些其他的内容?

普通的变量可以用let,但是face不是一个变量,C-h v "warning"找不到。

1 个赞

定义自己的 face:

https://www.gnu.org/software/emacs/manual/html_node/elisp/Defining-Faces.html

如果是简单修改,直接覆盖:

(set-face-attribute 'warning nil :foreground "red")

查看 face:

describe-face


UPDATE

继承一个已经存在的 face:

(defface my/warning
  '((t (:inherit warning
        :foreground "red")))
  "Basic face used to highlight warnings."
  :version "24.1"
  :group 'basic-faces)
1 个赞

(接着楼上说)M-x customize-face some-face RET里面其实也是有inherit项的,填写然后save可以发现配置的custom部分被写入了

(custom-set-faces
 '(web-mode-constant-face ((t (:inherit font-lock-keyword-face)))))

之类的字样。


有个小问题:custom-set-faces的doc里面说

The arguments should be a list where each entry has the form: (FACE SPEC [NOW [COMMENT]])

但是font-spec函数却没有:inherit部分,不都是"SPEC"么。。。