Subject: bug#18545: 24.4.50: Bug - forward-line inside with-selected-window

From: Eli Zaretskii <[email-masked]>
Date: Sat, 27 Sep 2014 22:25:30 +0300

> Date: Sat, 27 Sep 2014 21:01:51 +0200
> From: martin rudalics <[email-masked]>
> CC: [email-masked], [email-masked]
> 
>  >> 117
>  >> 122 [28 times]
>  >
>  > This says point doesn't move, which I don't understand how can
>  > happen.  forward-line doesn't care about anything except moving point
>  > to the next line.
> 
> But after 28 times point moves which is even less understandable.

I don't think this is relevant.  It could be related to
blink-cursor-mode or some other feature that triggers a more thorough
redisplay.  (Try typing "M-x", for example.)  The code part that seems
to be involved in this is an optimization, so when it is not taken,
you don't see the problem.

>  > But if new_vpos is 426 and row->height is 16, then the last row, which
>  > starts at y = 426, will end at y = 442, i.e. it's fully visible.  This
>  > contradicts what you said earlier, that the last line is only
>  > partially visible.
> 
> Then why does cursor_row_fully_visible_p return 0 here?

Because w->cursor.y is 432, only 10 pixels from the window bottom,
which is less than 16 pixels we need for the row.

Hmm, I think I see the problem in the logic behind this part:

      if (!cursor_row_fully_visible_p (w, 0, 0))
	{
	  /* Point does appear, but on a line partly visible at end of window.
	     Move it back to a fully-visible line.  */
	  new_vpos = window_box_height (w);
	  /* But if window_box_height suggests a Y coordinate that is
	     not less than we already have, that line will clearly not
	     be fully visible, so give up and scroll the display.
	     This can happen when the default face uses a font whose
	     dimensions are different from the frame's default
	     font.  */
	  if (new_vpos >= w->cursor.y)
	    {
	      w->cursor.vpos = -1;
	      clear_glyph_matrix (w->desired_matrix);
	      goto try_to_scroll;
	    }

What I think happens is that window_box_height tells us to put the
cursor at y = 426, but the first row that fits that is too far down,
due to the window size being not an integral multiple of the font
height.  So the condition to goto try_to_scroll needs to become
smarter.

Can you show all the values of MATRIX_ROW_BOTTOM_Y that are examined
in this loop, after we determine that new_vpos should be 426:

	  row = MATRIX_FIRST_TEXT_ROW (w->desired_matrix);
	  while (MATRIX_ROW_BOTTOM_Y (row) < new_vpos)
	    ++row;

> You probably mean I should answer that myself but honestly I don't
> understand cursor_row_fully_visible_p much.

Which part of it do you not understand?