gpt4 book ai didi

emacs - 如何定义多个 emacs 面孔?

转载 作者:行者123 更新时间:2023-12-04 02:40:44 25 4
gpt4 key购买 nike

我正在尝试定义一些 emacs 字体以进行一些自定义突出显示。当我单独定义它们时,这似乎有效:

(defface my-r-face `((t (:foreground "red")))  "Red highlight")
(defvar m-r-face 'my-r-face "Red.")
(defface my-g-face `((t (:foreground "green"))) "Green highlight")
(defvar m-g-face 'my-g-face "Green.")
(defface my-b-face `((t (:foreground "#0088ff"))) "Blue highlight")
(defvar m-b-face 'my-b-face "Blue.")
....etc

但是我有几十个这样的,我想从某种颜色表中一次性定义它们:

(setq ctable '(("red" "r")
("orange" "o")
("yellow" "y")
("#88ff00" "gy")
("green" "g")
("#00ff88" "gc")
("cyan" "c")
("#0088ff" "bc")
("blue" "b")
("purple" "bm")
("magenta" "m")
("#ff0088" "rm")
("grey" "lg")
("white" "w") ))

我的困难在于为每张脸组装符号名称,即将“my-”和“-face”连接到表中条目的任一侧。我发现 (intern) 可以从字符串中创建一个新符号,但是这个符号不能被 (defface) 接受,因为我所做的似乎等同于 (defface 'my-r-face ...,并且 defface 不喜欢引用的符号,并期望 (defface my-r-face .. 相反。我的尝试如下:

(dolist (tpl ctable)
(defvar (intern (concat "my-" (nth 1 tpl) "-face"))
(quote (intern (concat "my-" (nth 1 tpl) "-face"))) "colour")
(defface (intern (concat "my-" (nth 1 tpl) "-face"))
`((t (:foreground ,(car tpl)))) "Highlight" :group 'fortran)
)

运行结果为

Lisp error: (wrong-type-argument symbolp (intern (concat "fegs-" (nth 1 tpl) "-face")))
(defvar (intern (concat "fegs-" ... "-face")) (quote (intern ...)) "colour")

任何人都可以阐明我做错了什么,或者如果我完全错误地吠叫错误的树并且有更好的方法来做到这一点?

谢谢。

最佳答案

你可以避免eval:

(defconst my-ctable '(...))

(defmacro my-init-cfaces ()
`(progn
,@(mapcar (lambda (tpl)
`(defface ,(intern (format "my-%s-face" (nth 1 tpl)))
'((t :foreground ,(car tpl)))
,(format "Face for color %s." (car tpl))
:group 'fortran))
my-ctable)))

(my-init-cfaces)

关于emacs - 如何定义多个 emacs 面孔?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20000531/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com