Emacs 具有较少冗余的defface

Emacs 具有较少冗余的defface,emacs,elisp,Emacs,Elisp,我想为不同的角色定义一组面,如下所示: (defface char-face-a '((((type tty) (class color)) (:background "yellow" :foreground "black")) (((type tty) (class mono)) (:inverse-video t)) (((class color) (background dark)) (:background "yellow" :foreground "black"))

我想为不同的角色定义一组面,如下所示:

(defface char-face-a
  '((((type tty) (class color)) (:background "yellow" :foreground "black"))
    (((type tty) (class mono)) (:inverse-video t))
    (((class color) (background dark)) (:background "yellow" :foreground "black"))
    (((class color) (background light)) (:background "yellow" :foreground "black"))
    (t (:background "gray")))
  "Face for marking up A's"
  :group 'char-faces)

(defface char-face-b
  '((((type tty) (class color)) (:background "red" :foreground "black"))
    (((type tty) (class mono)) (:inverse-video t))
    (((class color) (background dark)) (:background "red" :foreground "black"))
    (((class color) (background light)) (:background "red" :foreground "black"))
    (t (:background "gray")))
  "Face for marking up B's"
  :group 'char-faces)

...
...

是否有办法避免显式编写所有的
defface
定义,并减少代码的冗余?(我知道
make face
,但它似乎已被弃用,并且不能像
defface
那样根据不同的终端类型设置属性。)

一个宏和一个循环如何操作后缀颜色的映射:

(defmacro-def-char-face(字母backgrnd-foregrn)
`(面部)(实习医生)布莱恩·查尔面部-
(信)
“(((tty型)(类别颜色))
(:背景)
,背面
:前景
,国外)
((tty型)(类别颜色)(:反向视频t))
((类别颜色)(背景暗))
(:前景
,国外
:背景
,backgrnd)
((类别颜色)(背景光))
(:前景
,国外
:背景
,backgrnd)
(t(:背景“灰色”))
,(concat“标记面”(大写字母)
让((白-黑))
(t.(黑黄))
(u(绿粉)(()))
(letcol列表中元素的循环)
对于l=(格式“%s”(汽车元素))
对于背面=(格式“%s”(cadr元素))
fore=(格式“%s”(caddr元素))
做
(eval(macroexpand`(brian def char face,l,back,fore‘‘‘)’)
给你新的面孔:

brian-char-face-s
brian-char-face-t
,和
brian-char-face-u

现在,您只需要维护lettercolor映射列表,并可能扩展宏以支持其他面属性(如果需要)

  • make face
    一点也不反对,AFAICT

  • defface
    可以利用继承——请参见面属性
    :继承
    。 不知道这在你的特定环境中是否有帮助


  • +1.我将为包含所有公共属性的所有面定义一个基础面,然后从中继承所有其他面。+1。我在帮助信息中看到了这一点:
    (makeface-face&可选NO-INIT-FROM-RESOURCES)定义一个名为face的新面,一个符号。不要直接从Lisp代码中调用它;改用defface。
    这就是为什么我认为它不受欢迎的原因。有趣的是,您使用的是什么Emacs版本?从昨天的Emacs 20到Emacs 24版本,我没有看到最后一句话(关于在Lisp代码中不使用它)作为任何Emacs版本帮助的一部分。