Subject: Re: bug#37774: 27.0.50; new :extend attribute broke visuals of all themes and other packages

From: Eli Zaretskii <[email-masked]>
Date: Sat, 07 Dec 2019 09:53:40 +0200

> Cc: [email-masked], [email-masked]
> From: Dmitry Gutov <[email-masked]>
> Date: Sat, 7 Dec 2019 03:06:05 +0200
> 
> > Well, we will have to document this exemption prominently, then.
> 
> I suppose so. Though I wouldn't consider it too important to most users, 

It's important to developers of Lisp programs that manipulate faces.

> > Is the patch likely to change any behavior except that of
> > custom-theme-set-faces? 
> 
> Only the behavior of other its callers (direct and indirect). :-)
> 
> Such as enable-theme, face-set-after-frame-default, 
> frame-set-background-mode and face-spec-set. I'm pretty sure all of 
> these should behave consistently WRT this change.
> 
> >> I think the purpose of face-spec-recalc is clear enough. So I'd like to
> >> see at least one of those "unintended consequences".
> > 
> > Let's try to avoid such consequences from the get-go, okay?
> 
> I'm "avoiding such consequences" by trying to make sure the change is in 
> the correct function and that it makes sense within the context.

I meant to avoid such consequences by making sure those other callers
can never trigger this new processing of :extend.  Can we please do
that?  That will go a long way towards my agreement to have this code
in Emacs 27.

> >>>> +    (when (and theme-face-applied (not themed-extend-attr))
> >>>> +      (let ((extend-p (plist-get default-attrs :extend)))
> >>>> +        (and extend-p (face-spec-set-2 face frame '(:extend t)))))
> >>>                                                        ^^^^^^^^^^^^
> >>> I think this should be extend-p instead, because the face's default
> >>> spec could legitimately say ":extend nil".  Right?
> >>
> >> But that's the default value of that attribute.
> > 
> > No, the default is 'unspecified', which is different from nil, when
> > merging with a face that specifies :extend, and when inheriting.  A
> > theme that says ':extend nil' should override the default spec, unlike
> > 'unspecified'.
> 
> This distinction is handled in the second hunk of the patch where 
> themed-extend-attr is calculated. If this attribute is not themed, there 
> is no difference between nil and 'unspecified' (in the default spec).

The use case I had in mind is this:

  . the theme doesn't specify :extend
  . the default spec for a face specifies ':extend nil'

In this case, after applying the theme, the face should have
':extend nil', implicitly "inherited" from the default spec.  Do you
agree?

> Finally, the value 'unspecified' seems impossible to get from the 
> attributes list this way. plist-get will simply return nil.

Exactly.  And when a face does specify a nil value for :extend, then
plist will return the list '(:extend nil), which is non-nil.

> That said, I think I've found one valid scenario where this patch will 
> do wrong: if the themed spec includes an :inherit directive, and the 
> inherited face specifies (:extend nil). The current patch would 
> inevitably ignore it and override with the value from the default spec.

Once again, I think this part:

> +    (when (and theme-face-applied
> +               (eq 'unspecified (face-attribute face :extend frame t)))
> +      (let ((extend-p (plist-get default-attrs :extend)))
> +        (and extend-p (face-spec-set-2 face frame '(:extend t)))))
                                                     ^^^^^^^^^^^^
isn't right, because it seems to say that when the default face says
':extend nil', the face after applying a theme will have ':extend t',
which isn't TRT, IMO.

Thanks.