use-package icon indicating copy to clipboard operation
use-package copied to clipboard

[Question] How the custom-face keyword acts on the faces ?

Open john-mirage opened this issue 4 years ago • 1 comments

Hello, I think i don't understand how the :custom-face keyword works.

My goal

For Org, i would like to add a face attribute (height) to the org-level-1 face.

Initial configuration

Before using use-package, my configuration was

(set-face-attribute 'org-level-1 nil :height 1.4)

Result

The result was the org-level-1 face with the inherit face outline-1 and the height value set to 1.4.

New configuration

With use-package, i now use this configuration

(use-package org
  :custom-face
  (org-level-1 ((t (:height 1.4)))))

Result

The result is now the org-level-1 face WITHOUT the inherit face outline-1 but with the height value set to 1.4.

My questions

  1. Is this behavior intended ?
  2. If this is a normal behavior, how can i add the attribute i want with the :custom-face keyword without redefining the face ?

I know i can simply add :inherit outline-1 attribute+value in (org-level-1 ((t (:height 1.4))))) or simply put my old configuration in the :config keyword to fix this issue but i would like to know how the :custom-face keyword works in order to define what to do.

I also looked in the use-package source code but i'm fairly new to emacs/elisp so as you can guess, i didn't understand what i've seen in it.

john-mirage avatar Jan 15 '21 15:01 john-mirage

use-package is not use set-face-attribute.

(setq use-package-expand-minimally t)
;;=> t

(macroexpand
 '(use-package org
    :custom-face
    (org-level-1 ((t (:height 1.4))))))
;;=> (progn
;;     (custom-set-faces
;;      '(org-level-1 ((t (:height 1.4)))))
;;     (require 'org nil nil))

so, the difference should come from set-face-attribute and custom-set-faces. But I can configure face via :custom-face correctory...? However, this information is the first step to investigate your issue.

conao3 avatar Feb 22 '21 11:02 conao3

I think @conao3 answered this question. You should use the following form:

(use-package org
  :custom-face
  (org-level-1 ((t (:height 1.4 :inherit outline-1)))))

Alternatively, I see nothing wrong with using this:

(use-package org
  :config
  (set-face-attribute 'org-level-1 nil :height 1.4))

For now, I don't see any strong reason to make any changes in use-package, as the above seems to cover this use case sufficiently well. We don't want to replace all types of customization with use-package, only some of the more tedious and common boiler-plate.

I hope that helps.

skangas avatar Nov 30 '22 17:11 skangas