[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#13278: 24.3.50; Attributes aren't inherited in a copied face across
From: |
Chong Yidong |
Subject: |
bug#13278: 24.3.50; Attributes aren't inherited in a copied face across frames |
Date: |
Mon, 31 Dec 2012 12:03:15 +0800 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.2.91 (gnu/linux) |
Katsumi Yamaoka <yamaoka@jpl.org> writes:
>> May I ask why you are trying to use `copy-face' instead of `defface'?
>
> I've been using it conveniently since the face feature was introduced
> in Emacs. For example, it's handy when I want a face of which only
> the color differs from the built-in one:
>
> (copy-face 'bold 'orange-bold)
> (set-face-foreground 'orange-bold "Orange")
>
> Of course doing it by defface is not so troublesome, so I can live
> without copy-face.
Here's the basic issue: `copy-face' acts on internal faces (and always
has, IIRC). Internal faces are vectors of face attributes, which are
stored by Emacs in `face-new-frame-defaults' and in per-frame alists.
The key point is that the face spec, which is specified by `defface', is
separate from this. Since `defface' is used for practically all Emacs
faces, the internal faces stored in `face-new-frame-defaults' are
usually empty. The purpose of `face-new-frame-defaults' is to keep
track of the "overriding attributes", for when the user calls
`set-face-attribute', `set-face-foreground', etc.
What `copy-face' does is to create a new entry for the face copy in
`face-new-frame-defaults'; it doesn't touch the face spec (customization
data). When you create a new frame, Emacs combines
`face-new-frame-defaults' with the face spec from the face's
customization data. So a face created with `copy-face', lacking that
customization data, would have a blank appearance.
Note also that `face-new-frame-defaults' overrides the customization
data, so this mechanism inherently doesn't play well with Custom themes.
That's one reason the direct setting of internal faces is
downplayed/deprecated these days: it can lead to surprising effects for
people who don't know what they're doing.
Of course, we could make `copy-face' copy the customization data as
well, if that is more useful. But this would be a backward incompatible
change, and I would have to think about whether it would screw anything
up.