Subject: Re: bug#14616: 24.3.50; Excessive cursor movement on non-X Emacs

From: Eli Zaretskii <[email-masked]>
Date: Mon, 05 Aug 2013 22:45:12 +0300

> From: Lars Magne Ingebrigtsen <[email-masked]>
> Cc: [email-masked]
> Date: Mon, 05 Aug 2013 21:21:22 +0200
> 
> Lars Magne Ingebrigtsen <[email-masked]> writes:
> 
> > #<frame F1 0xc12be0>
> > #<frame emacs 0x2f8fba8>
> 
> Hm.  So...  reading the code, it is really trying to switch between the
> two frames, which then means that it has to redraw everything.

The redrawing isn't supposed to happen.

> But why is it trying to switch frames in the first place?
> 
> I'm probably reading this wrong, but it's waiting for process output
> (check), but that means that it wants to switch frames.  Which I don't
> understand why it'd want to...

Because prepare_menu_bars, called as part of redisplay, loops over all
the frames.

> 0x0000000000420725 in do_switch_frame (frame=12659685, track=1, for_deletion=0, norecord=12571250) at frame.c:844
> 844		  SET_FRAME_VISIBLE (XFRAME (frame), 1);
> #0  0x0000000000420725 in do_switch_frame (frame=12659685, track=1, for_deletion=0, norecord=12571250) at frame.c:844
> #1  0x0000000000420829 in Fselect_frame (frame=12659685, norecord=12571250) at frame.c:883
> #2  0x00000000004454ac in unwind_format_mode_line (vector=17901885) at xdisp.c:11002
> #3  0x00000000005ad565 in unbind_to (count=6, value=12571202) at eval.c:3337
> #4  0x0000000000445936 in x_consider_frame_title (frame=48936325) at xdisp.c:11133
> #5  0x0000000000445a34 in prepare_menu_bars () at xdisp.c:11185
> #6  0x00000000004497f6 in redisplay_internal () at xdisp.c:13051
> #7  0x000000000044ac22 in redisplay_preserve_echo_area (from_where=11) at xdisp.c:13643
> #8  0x00000000005f7d4f in wait_reading_process_output (time_limit=30, nsecs=0, read_kbd=-1, do_display=true, wait_for_cell=12571202, 
>     wait_proc=0x0, just_wait_proc=0) at process.c:4459

Here:

  /* Prepare for redisplay by updating menu-bar item lists when
     appropriate.  This can call eval.  */

  void
  prepare_menu_bars (void)
  {
    int all_windows;
    struct gcpro gcpro1, gcpro2;
    struct frame *f;
    Lisp_Object tooltip_frame;

  #ifdef HAVE_WINDOW_SYSTEM
    tooltip_frame = tip_frame;
  #else
    tooltip_frame = Qnil;
  #endif

    /* Update all frame titles based on their buffer names, etc.  We do
       this before the menu bars so that the buffer-menu will show the
       up-to-date frame titles.  */
  #ifdef HAVE_WINDOW_SYSTEM
    if (windows_or_buffers_changed || update_mode_lines)
      {
	Lisp_Object tail, frame;

	FOR_EACH_FRAME (tail, frame) <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
	  {
	    f = XFRAME (frame);
	    if (!EQ (frame, tooltip_frame)
		&& (FRAME_VISIBLE_P (f) || FRAME_ICONIFIED_P (f)))
	      x_consider_frame_title (frame);
	  }
      }
  #endif /* HAVE_WINDOW_SYSTEM */

Hmmm... maybe we should have here something special for TTY frames.  I
will take a look.

Thanks.