Subject: bug#11068: 24.0.94; Face-remapped background does not extend to end of window

From: Eli Zaretskii <[email-masked]>
Date: Sat, 24 Mar 2012 14:37:17 +0200

> Date: Fri, 23 Mar 2012 12:36:31 +0200
> From: Eli Zaretskii <[email-masked]>
> Cc: [email-masked]
> 
> This is how Emacs display engine always worked: the non-text parts of
> the window display are drawn in the default face.  (Remapping does not
> change the default face, as far as Emacs internals are concerned, it
> just substitutes a different face in its stead, leaving the literal
> DEFAULT_FACE_ID intact.)
> 
> So this bug has rather low priority at this time, as it's not a
> regression wrt Emacs 23.  Time permitting, I will at the very least
> try to figure out what changes are needed to make this work as
> expected.

The patch below makes Emacs work as expected in this case.  Whether to
install this now or wait until after Emacs 24.1, is up to Stefan and
Chong.

=== modified file 'src/xdisp.c'
--- a/src/xdisp.c	2012-03-24 12:33:40 +0000
+++ b/src/xdisp.c	2012-03-24 12:34:53 +0000
@@ -18173,7 +18173,12 @@
 	  it->len = 1;
 
 	  if (default_face_p)
-	    it->face_id = DEFAULT_FACE_ID;
+	    {
+	      if (NILP (Vface_remapping_alist))
+		it->face_id = DEFAULT_FACE_ID;
+	      else
+		it->face_id = lookup_basic_face (it->f, DEFAULT_FACE_ID);
+	    }
 	  else if (it->face_before_selective_p)
 	    it->face_id = it->saved_face_id;
 	  face = FACE_FROM_ID (it->f, it->face_id);
@@ -18209,7 +18214,7 @@
 static void
 extend_face_to_end_of_line (struct it *it)
 {
-  struct face *face;
+  struct face *face, *default_face;
   struct frame *f = it->f;
 
   /* If line is already filled, do nothing.  Non window-system frames
@@ -18223,11 +18228,16 @@
 	 && !it->glyph_row->continued_p))
     return;
 
+  /* The default face, possibly remapped. */
+  default_face = FACE_FROM_ID (f, lookup_basic_face (f, DEFAULT_FACE_ID));
+
   /* Face extension extends the background and box of IT->face_id
      to the end of the line.  If the background equals the background
      of the frame, we don't have to do anything.  */
   if (it->face_before_selective_p)
     face = FACE_FROM_ID (f, it->saved_face_id);
+  else if (it->face_id == DEFAULT_FACE_ID)
+    face = default_face;
   else
     face = FACE_FROM_ID (f, it->face_id);
 
@@ -18260,7 +18270,7 @@
       if (it->glyph_row->used[TEXT_AREA] == 0)
 	{
 	  it->glyph_row->glyphs[TEXT_AREA][0] = space_glyph;
-	  it->glyph_row->glyphs[TEXT_AREA][0].face_id = it->face_id;
+	  it->glyph_row->glyphs[TEXT_AREA][0].face_id = face->id;
 	  it->glyph_row->used[TEXT_AREA] = 1;
 	}
 #ifdef HAVE_WINDOW_SYSTEM
@@ -18296,7 +18306,7 @@
 		 face, to avoid painting the rest of the window with
 		 the region face, if the region ends at ZV.  */
 	      if (it->glyph_row->ends_at_zv_p)
-		it->face_id = DEFAULT_FACE_ID;
+		it->face_id = default_face->id;
 	      else
 		it->face_id = face->id;
 	      append_stretch_glyph (it, make_number (0), stretch_width,
@@ -18329,7 +18339,7 @@
 	 avoid painting the rest of the window with the region face,
 	 if the region ends at ZV.  */
       if (it->glyph_row->ends_at_zv_p)
-	it->face_id = DEFAULT_FACE_ID;
+	it->face_id = default_face->id;
       else
 	it->face_id = face->id;
 
@@ -18993,8 +19003,13 @@
 	  /* A row that displays right-to-left text must always have
 	     its last face extended all the way to the end of line,
 	     even if this row ends in ZV, because we still write to
-	     the screen left to right.  */
-	  if (row->reversed_p)
+	     the screen left to right.  We also need to extend the
+	     last face if the default face is remapped to some
+	     different face, otherwise the functions that clear
+	     portions of the screen will clear with the default face's
+	     background color.  */
+	  if (row->reversed_p
+	      || lookup_basic_face (it->f, DEFAULT_FACE_ID) != DEFAULT_FACE_ID)
 	    extend_face_to_end_of_line (it);
 	  break;
 	}