Reputation: 5852
I'm not quite down with the syntax for dynamic symbols etc. I guess I can probably do something with dolist
and a list of colors here, but not sure what:
(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))))))
Upvotes: 0
Views: 317
Reputation: 17412
You can refactor that code, but you probably shouldn't. All (custom-set-...)
code is generated automatically by Emacs' "easy customization" system. Thus if you refactor it, there is a good chance that
However, if you find your .emacs file too cluttered, you can configure Emacs to write customization code to a separate file. See this answer to a related question, and also Emacs' documentation.
Upvotes: 1
Reputation:
This is not 100% identical, but in most cases will be equivalent:
(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))
The discrepancy is at the point of when the evaluation of ,(face-attribute ...)
happens. I.e. this macro doesn't produce the same source code you have, it already evaluates the expression after comma, so if your code was inside a macro, that would make a difference.
Upvotes: 1