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

From: Ergus <[email-masked]>
Date: Thu, 7 Nov 2019 16:41:36 +0100

On Thu, Nov 07, 2019 at 03:58:02PM +0200, Eli Zaretskii wrote:
>> Cc: [email-masked]
>> From: martin rudalics <[email-masked]>
>> Date: Wed, 6 Nov 2019 18:06:04 +0100
>>
>> One surprising effect with recent master is that with emacs -Q
>> evaluating
>>
>> (custom-set-faces
>>   '(font-lock-comment-face ((((class color) (background light)) (:background "Beige" :foreground "Black")))))
>>
>> makes the comment background extend to the end of the window.  This
>> means that unless I explicitly supply :extend nil, the behavior is as
>> with Emacs 26.  Is that intended?
>
>No, of course it isn't intended.
>
>Jimmy, are you looking into this?  It sounds like there's a difference
>with processing the :extend attribute when its value is 'unspecified'
>and when it's nil.  Because just adding
>
>  (set-face-extend 'FOO nil)
>
>for the faces named by Jonas and Martin makes the problem go away, and
>the faces aren't extended, as I'd expect.
>
>Let me know if you need help in debugging or resolving this.
>
>Thanks.

Hi:

Please try the attached patch. (I'm in a network where I can't use git
now.)

Best,
Ergus
diff --git a/src/xfaces.c b/src/xfaces.c
index 3806fa90e2..ff4e2796f2 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -2063,7 +2063,10 @@ merge_face_vectors (struct window *w, struct frame *f,
   eassert (attr_filter <  LFACE_VECTOR_SIZE);
 
   /* When FROM sets attr_filter to nil explicitly we don't merge it.  */
-  if (attr_filter > 0 && NILP(from[attr_filter]))
+  if (attr_filter > 0 && (NILP(from[attr_filter])
+                          || (UNSPECIFIEDP(from[attr_filter])
+			      && (NILP (from[LFACE_INHERIT_INDEX])
+			          || UNSPECIFIEDP (from[LFACE_INHERIT_INDEX])))))
     return;
 
   /* If FROM inherits from some other faces, merge their attributes into
@@ -2082,7 +2085,7 @@ merge_face_vectors (struct window *w, struct frame *f,
       else if (UNSPECIFIEDP (from[attr_filter])) /* FROM don't specify filter */
 	{
 	  Lisp_Object tmp[LFACE_VECTOR_SIZE];
-	  memcpy (tmp, to, LFACE_VECTOR_SIZE * sizeof *tmp);
+	  memcpy (tmp, to, LFACE_VECTOR_SIZE * sizeof(*tmp));
 
 	  merge_face_ref (w, f, from[LFACE_INHERIT_INDEX],
 	                  tmp, false, named_merge_points, attr_filter);
@@ -2177,7 +2180,8 @@ merge_named_face (struct window *w,
 		     && !UNSPECIFIEDP(from[attr_filter]))
                  || (!NILP(from[attr_filter])  /* Filter, unspecified, but inherited.  */
 		     && UNSPECIFIEDP(from[attr_filter])
-		     && !NILP (from[LFACE_INHERIT_INDEX]))))
+		     && !NILP (from[LFACE_INHERIT_INDEX])
+		     && !UNSPECIFIEDP (from[LFACE_INHERIT_INDEX]))))
         merge_face_vectors (w, f, from, to, named_merge_points, attr_filter);
 
       return ok;