Subject: bug#28936: nRe: bug#28936: move_it_in_display_line_to returns MOVE_POS_MATCH_OR_ZV before ZV

From: Eli Zaretskii <[email-masked]>
Date: Sun, 22 Oct 2017 22:41:14 +0300

> Date:  Sun, 22 Oct 2017 12:22:26 -0700
> From:  Keith David Bershatsky <[email-masked]>
> Cc:  [email-masked]
> 
> The issue is observable at a distance of approximately up to five (5) text characters prior to ZV, rather than a distance of just one (1) it->pixel_width.  And, the issue is only present when word-wrap is non-nil.  In the example of a buffer containing only "Hello world!", the wrong result is observable on the letter "w", and on the letter "o", and on the letter "r" and on the letter "l", and on the letter "d", and on the exclamation point.  If my recollection is collect when trying out the example, the wrong result was also observable on the space between "hello" and "world".

There's something you didn't tell, because otherwise what you describe
is done all the time by the display engine, and it is certainly
incorrect that it's impossible to get to a given X coordinate, with or
without word-wrap.

It is possible that you didn't reset current_x before the iteration,
or that the window-start point is not where you think it is.  Or
something else.  This code works, it's the workhorse of many Emacs
display operations.

> The code that I borrowed is from xdisp.c at approximately 22680:  "while (it.current_x + it.pixel_width <= target_x".

That doesn't mean anything: the code you copied tries to find the
character _before_ target_x, whereas you are trying to get to target_x
itself.