From: Michael Shields Date: Sat, 19 Apr 2025 19:58:26 +0000 (-0700) Subject: Fix use-package :custom-face to set face-defface-spec (bug#77928) X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=accbacaaa15e2bb2265311a347c03e2011f0b62a;p=emacs.git Fix use-package :custom-face to set face-defface-spec (bug#77928) By default, `face-set-spec' sets the override face spec, so face attributes are combined with defaults rather than replacing them. This was a behavior change that was an apparently unintended consequence of commit 6b344a9. Also set the `face-modified' property, which causes Customize to flag the face as changed outside Customize. * doc/misc/use-package.texi (Faces): Document the behavior. * lisp/use-package/use-package-core.el (use-package-handler/:custom-face): (use-package): Improve docstring to reflect implementation. * test/lisp/use-package/use-package-tests.el (use-package-test/:custom-face-1): (use-package-test/:custom-face-2): (use-package-test/:custom-face-3): (use-package-test/:custom-face-4): Add tests. (cherry picked from commit ebcde0f90f67852d485a36941b0661cfd1b892eb) --- diff --git a/doc/misc/use-package.texi b/doc/misc/use-package.texi index fb3538cae8b..582cc9ab226 100644 --- a/doc/misc/use-package.texi +++ b/doc/misc/use-package.texi @@ -1461,7 +1461,7 @@ faces. Example: (use-package example :custom-face (example-1-face ((t (:foreground "LightPink")))) - (example-2-face ((t (:foreground "LightGreen"))) face-defspec-spec)) + (example-2-face ((t (:foreground "LightGreen"))))) @end group @group @@ -1476,6 +1476,11 @@ faces. Example: @end group @end lisp +Similarly to @code{:custom} (@pxref{User options}), this allows +configuring customizable faces outside of Customize (@pxref{Saving +Customizations,,, emacs, GNU Emacs Manual}). Using both systems to +configure the same face can lead to confusing results. + @node Hiding minor modes @section Hiding minor modes with diminish and delight @cindex hiding minor modes diff --git a/lisp/use-package/use-package-core.el b/lisp/use-package/use-package-core.el index c41709c4494..d1f089e2eee 100644 --- a/lisp/use-package/use-package-core.el +++ b/lisp/use-package/use-package-core.el @@ -1594,7 +1594,11 @@ no keyword implies `:all'." (defun use-package-handler/:custom-face (name _keyword args rest state) "Generate use-package custom-face keyword code." (use-package-concat - (mapcar #'(lambda (def) `(apply #'face-spec-set (backquote ,def))) args) + (mapcar #'(lambda (def) + `(progn + (apply #'face-spec-set (append (backquote ,def) '(face-defface-spec))) + (put ',(car def) 'face-modified t))) + args) (use-package-process-keywords name rest state))) ;;;; :init @@ -1742,7 +1746,7 @@ Usage: :custom Call `Custom-set' or `set-default' with each variable definition without modifying the Emacs `custom-file'. (compare with `custom-set-variables'). -:custom-face Call `custom-set-faces' with each face definition. +:custom-face Call `face-spec-set' with each face definition. :ensure Loads the package using package.el if necessary. :pin Pin the package to an archive. :vc Install the package directly from a version control system diff --git a/test/lisp/use-package/use-package-tests.el b/test/lisp/use-package/use-package-tests.el index cfcf3700b94..e25b484bf2f 100644 --- a/test/lisp/use-package/use-package-tests.el +++ b/test/lisp/use-package/use-package-tests.el @@ -1127,7 +1127,12 @@ (match-expansion (use-package foo :custom-face (foo ((t (:background "#e4edfc"))))) `(progn - (apply #'face-spec-set (backquote (foo ((t (:background "#e4edfc")))))) + (progn + (apply #'face-spec-set + (append (backquote (foo ((t (:background "#e4edfc"))))) + '(face-defface-spec)) + ) + (put 'foo 'face-modified t)) (require 'foo nil nil)))) (ert-deftest use-package-test/:custom-face-2 () @@ -1137,19 +1142,42 @@ (example-1-face ((t (:foreground "LightPink")))) (example-2-face ((t (:foreground "LightGreen"))))) `(progn - (apply #'face-spec-set - (backquote (example-1-face ((t (:foreground "LightPink")))))) - (apply #'face-spec-set - (backquote (example-2-face ((t (:foreground "LightGreen")))))) + (progn + (apply #'face-spec-set + (append (backquote (example-1-face ((t (:foreground "LightPink"))))) + '(face-defface-spec))) + (put 'example-1-face 'face-modified t)) + (progn + (apply #'face-spec-set + (append (backquote (example-2-face ((t (:foreground "LightGreen"))))) + '(face-defface-spec))) + (put 'example-2-face 'face-modified t)) (require 'example nil nil)))) (ert-deftest use-package-test/:custom-face-3 () (match-expansion (use-package foo :custom-face (foo ((t (:background "#e4edfc"))) face-defspec-spec)) `(progn - (apply #'face-spec-set (backquote (foo ((t (:background "#e4edfc"))) face-defspec-spec))) + (progn + (apply #'face-spec-set + (append (backquote (foo ((t (:background "#e4edfc"))) face-defspec-spec)) + '(face-defface-spec))) + (put 'foo 'face-modified t)) (require 'foo nil nil)))) +(ert-deftest use-package-test/:custom-face-4 () + (defface use-package-test/base-face '((t (:background "green"))) "") + (defface use-package-test/face '((t (:inherit use-package-test/base-face))) "") + (use-package emacs + :custom-face + (use-package-test/face ((t (:foreground "blue"))))) + (should (equal (face-foreground 'use-package-test/face nil t) + "blue")) + (should (equal (face-background 'use-package-test/face nil t) + nil)) + (should (equal (get 'use-package-test/face 'face-modified) + t))) + (ert-deftest use-package-test/:init-1 () (match-expansion (use-package foo :init (init))