Subject: Re: bug#20410: 24.5.50; cursor not updated after yank of non-ASCII string from the clipboard

From: Eli Zaretskii <[email-masked]>
Date: Sat, 25 Apr 2015 15:32:22 +0300

> Date: Sat, 25 Apr 2015 13:09:07 +0300
> From: Eli Zaretskii <[email-masked]>
> Cc: [email-masked]
> 
> > 1. Create a file named a.el with the following contents:
> > 
> >   (global-set-key "a" (string #x3042))	; HIRAGANA LETTER A
> > 
> > 2. $ emacs -Q -D -l a.el &
> > 3. Type "a" to insert a Japanese character.
> > 4. Type "C-p" to move the cursor upward.
> > 
> > Display is updated correctly until Step 3.  But Step 4 does not change
> > the display from the previous one.
> 
> I succeeded in reproducing this, after changing the default fontset to
> use a specific font for the u+3042 character.  Thanks, I will look
> into this.
> 
> > As for expose events, I suspect the current matrices get corrupted,
> > because the result of git bisect implies that it has something to do
> > with adjustment of glyph matrices triggered by font loading.
> 
> Sounds plausible, thanks.

Adjusting frame glyphs makes all glyph rows disabled, so various
redisplay optimizations should be disabled.  In particular, new cursor
position was correctly computed, but because it was on a disabled
glyph row, display_and_set_cursor would not obey that new position,
and exposing a window would not redraw the disabled glyph rows.

Does the patch below fix the problems you see?  (It might look a bit
drastic, but then loading new fonts is not supposed to be a frequent
operation, I think.)

diff --git a/src/dispnew.c b/src/dispnew.c
index 693dd49..c0fd679 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -1795,6 +1795,12 @@ struct glyph_row *
 
   f->glyphs_initialized_p = 1;
 
+  /* Disable all redisplay optimizations for this frame.  This is
+     because adjusting frame glyphs makes all glyph rows disabled, so
+     many optimizations will fail anyway, and some might not test this
+     flag and do bogus things.  */
+  SET_FRAME_GARBAGED (f);
+
   unblock_input ();
 }