> /* When running redisplay, we play a bit fast-and-loose and allow e.g.
> selected_frame and selected_window to be temporarily out-of-sync so
> when we come back here via `goto retry', we need to resync because we
> may need to run Elisp code (via prepare_menu_bars). */
> select_frame_for_redisplay (old_frame);
>
> It would be good to get rid of such risky code.
Is there any reason why this should not select the window too?
By "this" you mean what? IOW, who or what should "select the window
too"?