]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix use-package :custom-face to set face-defface-spec (bug#77928)
authorMichael Shields <shields@msrl.com>
Sat, 19 Apr 2025 19:58:26 +0000 (12:58 -0700)
committerEshel Yaron <me@eshelyaron.com>
Sun, 27 Apr 2025 13:29:57 +0000 (15:29 +0200)
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)

doc/misc/use-package.texi
lisp/use-package/use-package-core.el
test/lisp/use-package/use-package-tests.el

index fb3538cae8bc198ab05334ab55ac71efe6e8f8e0..582cc9ab22645461b430292583587a3a4f92b922 100644 (file)
@@ -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
index c41709c4494fa8d4f1887840ebad6f3112d11a9f..d1f089e2eeee3ec3fb554c66af545702c66d0738 100644 (file)
@@ -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
index cfcf3700b940c6bfdd377fe4cddaf6a29c53cf55..e25b484bf2f553787bcbfee17d19f68ced8a5adc 100644 (file)
   (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 ()
      (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))