0

我对动态符号等的语法不太满意。我想我可能可以dolist在这里做一些颜色列表,但不确定是什么:

  (custom-set-faces
   `(term-color-black ((t (:inherit term-color-black :background ,(face-attribute 'term-color-black :foreground)))))
   `(term-color-red ((t (:inherit term-color-red :background ,(face-attribute 'term-color-red :foreground)))))
   `(term-color-green ((t (:inherit term-color-green :background ,(face-attribute 'term-color-green :foreground)))))
   `(term-color-yellow ((t (:inherit term-color-yellow :background ,(face-attribute 'term-color-yellow :foreground)))))
   `(term-color-blue ((t (:inherit term-color-blue :background ,(face-attribute 'term-color-blue :foreground)))))
   `(term-color-magenta ((t (:inherit term-color-magenta :background ,(face-attribute 'term-color-magenta :foreground)))))
   `(term-color-cyan ((t (:inherit term-color-cyan :background ,(face-attribute 'term-color-cyan :foreground)))))
   `(term-color-white ((t (:inherit term-color-white :background ,(face-attribute 'term-color-white :foreground))))))
4

2 回答 2

1

这不是 100% 相同,但在大多数情况下是等价的:

(defmacro set-term-faces (names)
  `(custom-set-faces
    ,@(loop for color in names
         for sym = (intern (concat "term-color-" (symbol-name color)))
         collect (list 'quote
                       `(,sym ((t (:inherit ,sym
                                   :background
                                   ,(face-attribute sym :foreground)))))))))

(set-term-faces (black red green yellow blue magenta cyan white))

差异在于评估,(face-attribute ...)发生的时间点。即这个宏不会产生与你相同的源代码,它已经计算了逗号后的表达式,所以如果你的代码在宏内,那会有所不同。

于 2013-03-31T11:34:43.150 回答
1

可以重构该代码,但您可能不应该这样做。所有(custom-set-...)代码都是由 Emacs 的“轻松定制”系统自动生成的。因此,如果您对其进行重构,则很有可能

  1. 你破坏了与定制系统的兼容性
  2. 下次自定义人脸时,重构的代码将被原始代码覆盖

但是,如果您发现 .emacs 文件过于混乱,您可以配置 Emacs 以将自定义代码写入单独的文件。请参阅对相关问题的回答,以及 Emacs 的文档

于 2013-04-01T22:58:49.500 回答