Skip to content

Instantly share code, notes, and snippets.

@hlissner
Last active May 30, 2020 13:18
Show Gist options
  • Save hlissner/1ace77658c772cf150a43dc9396fa2ed to your computer and use it in GitHub Desktop.
Save hlissner/1ace77658c772cf150a43dc9396fa2ed to your computer and use it in GitHub Desktop.
Convenience macro for additively setting face attributes in Doom Emacs
(defmacro custom-theme-set-faces! (theme &rest specs)
"Apply a list of face specs as user customizations for THEME.
THEME can be a single symbol or list thereof. If nil, apply these settings to
all themes. It will apply to all themes once they are loaded.
(custom-theme-set-faces! '(doom-one doom-one-light)
`(mode-line :foreground ,(doom-color 'blue))
`(mode-line-buffer-id :foreground ,(doom-color 'fg) :background \"#000000\")
'(mode-line-success-highlight :background \"#00FF00\")
'(org-tag :background \"#4499FF\")
'(org-ellipsis :inherit org-tag)
'(which-key-docstring-face :inherit font-lock-comment-face))"
`(let* ((themes (doom-enlist (or ,theme 'user)))
(fn (gensym (format "doom|customize-%s-" (mapconcat #'symbol-name themes "-")))))
(fset fn
(lambda ()
(dolist (theme themes)
(when (or (eq theme 'user)
(custom-theme-enabled-p theme))
(apply #'custom-theme-set-faces 'user
(cl-loop for (face . spec) in (list ,@specs)
if (keywordp (car spec))
collect `(,face ((t ,spec)))
else collect `(,face ,spec)))))))
(funcall fn)
(add-hook 'doom-load-theme-hook fn)))
(defmacro custom-set-faces! (&rest specs)
"Apply a list of face specs as user customizations.
SPECS is a list of face specs.
This is a drop-in replacement for `custom-set-face' that allows for a simplified
face format, e.g.
(custom-set-faces!
`(mode-line :foreground ,(doom-color 'blue))
`(mode-line-buffer-id :foreground ,(doom-color 'fg) :background \"#000000\")
'(mode-line-success-highlight :background \"#00FF00\")
'(org-tag :background \"#4499FF\")
'(org-ellipsis :inherit org-tag)
'(which-key-docstring-face :inherit font-lock-comment-face))"
`(custom-theme-set-faces! 'user ,@specs))
@hlissner
Copy link
Author

These depend on doom-load-theme-hook, which is implemented like so:

(defvar doom-load-theme-hook nil
  "Hook run after the theme is loaded with `load-theme'.")

(defun doom*run-load-theme-hooks (theme &optional _no-confirm no-enable)
  "Set up `doom-load-theme-hook' to run after `load-theme' is called."
  (unless no-enable
    (run-hooks 'doom-load-theme-hook)))

(advice-add #'load-theme :after #'doom*run-load-theme-hooks)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment