Subject: bug#9034: point adjustment (with invisible text) moves to the next line

From: Eli Zaretskii <[email-masked]>
Date: Wed, 25 Aug 2021 19:43:34 +0300

> From: Lars Ingebrigtsen <[email-masked]>
> Date: Wed, 25 Aug 2021 18:32:15 +0200
> Cc: [email-masked]
> 
> Also as previously noted, if Vglobal_disable_point_adjustment is on,
> then this doesn't happen, so the problem almost has to be here:
> 
> command_loop_1
> ...
>       if (current_buffer == prev_buffer
> 	  && XBUFFER (XWINDOW (selected_window)->contents) == current_buffer
> 	  && last_point_position != PT
> 	  && NILP (Vdisable_point_adjustment)
> 	  && NILP (Vglobal_disable_point_adjustment))
> 	{
> 	  if (last_point_position > BEGV
> 	      && last_point_position < ZV
> 	      && (composition_adjust_point (last_point_position,
> 					    last_point_position)
> 		  != last_point_position))
> 	    /* The last point was temporarily set within a grapheme
> 	       cluster to prevent automatic composition.  To recover
> 	       the automatic composition, we must update the
> 	       display.  */
> 	    windows_or_buffers_changed = 21;
> 	  if (!already_adjusted)
> 	    adjust_point_for_property (last_point_position,
> 				       MODIFF != prev_modiff);
> 	}
> 
> I haven't tried to debug any further -- is it obvious to anybody what's
> failing here, by any chance?  :-)

This code is chock-full of questionable heuristics, and in particular
tries to guess in which direction to move point out of the invisible
text.  The results are sometimes surprising.  The upside is that it
"mostly works".  But if someone can come up with a better heuristics,
I'm all ears.