我想为不同的角色定义一堆面孔,如下所示:
(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
的不同终端类型设置属性。)
答案 0 :(得分:5)
make-face
完全没有被弃用,AFAICT。
defface
可以使用继承 - 请参阅face属性:inherit
。
Dunno是否有助于您的特定背景。
答案 1 :(得分:3)
对后缀< - >的映射进行操作的宏和循环怎么样?颜色:
(defmacro brian-def-char-face (letter backgrnd foregrnd)
`(defface ,(intern (concat "brian-char-face-"
letter))
'((((type tty) (class color))
(:background
,backgrnd
:foreground
,foregrnd))
(((type tty) (class color)) (:inverse-video t))
(((class color) (background dark))
(:foreground
,foregrnd
:background
,backgrnd))
(((class color) (background light))
(:foreground
,foregrnd
:background
,backgrnd))
(t (:background "gray")))
,(concat "Face for marking up " (upcase letter) "'s")))
(let ((letcol-alist '((s . (white black))
(t . (black yellow))
(u . (green pink)))))
(loop for elem in letcol-alist
for l = (format "%s" (car elem))
for back = (format "%s" (cadr elem))
for fore = (format "%s" (caddr elem))
do
(eval (macroexpand `(brian-def-char-face ,l ,back ,fore)))))
给你新面孔:
brian-char-face-s
,brian-char-face-t
和brian-char-face-u
现在您只需要维护字母< - >颜色映射列表,并可能扩展宏以支持其他面部属性(如果需要)。