如何重构这个Emacs lisp?

如何重构这个Emacs lisp?,emacs,elisp,emacs-faces,Emacs,Elisp,Emacs Faces,我不太懂动态符号等的语法。我想我可以用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 ,(fac

我不太懂动态符号等的语法。我想我可以用
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))))))

这不是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))
差异出现在计算
,(面属性…
时。也就是说,此宏不会生成与您相同的源代码,它已经计算逗号后的表达式,因此如果您的代码在宏中,则会产生不同。

您可以重构该代码,但可能不应该重构。所有
(自定义设置-…)
代码由Emacs“系统自动生成。因此,如果您重构它,很有可能

  • 您破坏了与自定义系统的兼容性
  • 下次自定义面时,重构代码将被原始代码覆盖

  • 但是,如果您发现.emacs文件过于杂乱,可以配置emacs将自定义代码写入单独的文件。查看一个相关问题,以及Emacs.

    该代码不是由
    customize
    编写的-我自己编写的。我只是使用
    自定义设置面
    来覆盖某些内容。在这种情况下,您可以直接使用
    设置面属性
    ,或者
    定义面