fix(lib): avoid writing customized faces to custom.el

`custom-theme-set-faces!` calls `custom-theme-set-faces`, which will
mark the customizations for saving to custom.el. But
`custom-theme-set-faces!` is not intended for permanent customizations.
I fix this by setting `custom--inhibit-theme-enable` to prevent some of
the extra work `custom-theme-set-faces` does around changing faces, and
call face-spec-set manually.

Also renames doom--custome-theme-set-face to doom--normalize-face-space,
to better reflect what it does.

Close: #7929
Co-authored-by: real-or-random <real-or-random@users.noreply.github.com>
This commit is contained in:
Henrik Lissner 2024-07-10 01:38:17 -04:00
parent b4b1b48e26
commit 68771150ba
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -6,13 +6,17 @@
(add-hook! 'doom-load-theme-hook
(defun doom-apply-customized-faces-h ()
"Run `doom-customize-theme-hook'."
(run-hooks 'doom-customize-theme-hook)))
(letf! (defun custom-push-theme (prop symbol theme mode &optional value)
(funcall custom-push-theme prop symbol theme mode value)
(if (facep symbol) (face-spec-set symbol value t)))
(let ((custom--inhibit-theme-enable t))
(run-hooks 'doom-customize-theme-hook)))))
(defun doom--custom-theme-set-face (spec)
(defun doom--normalize-face-spec (spec)
(cond ((listp (car spec))
(cl-loop for face in (car spec)
collect
(car (doom--custom-theme-set-face (cons face (cdr spec))))))
(car (doom--normalize-face-spec (cons face (cdr spec))))))
((keywordp (cadr spec))
`((,(car spec) ((t ,(cdr spec))))))
(`((,(car spec) ,(cdr spec))))))
@ -27,13 +31,12 @@ all themes. It will apply to all themes once they are loaded."
(let ((fn (gensym "doom--customize-themes-h-")))
`(progn
(defun ,fn ()
(let (custom--inhibit-theme-enable)
(dolist (theme (ensure-list (or ,theme 'user)))
(when (or (eq theme 'user)
(if (or (eq theme 'user)
(custom-theme-enabled-p theme))
(apply #'custom-theme-set-faces theme
(mapcan #'doom--custom-theme-set-face
(list ,@specs)))))))
(mapcan #'doom--normalize-face-spec
(list ,@specs))))))
;; Apply the changes immediately if the user is using the default theme
;; or the theme has already loaded. This allows you to evaluate these
;; macros on the fly and customize your faces iteratively.