Subject: bug#66942: move-to-column behavior when newlines have a display property

From: JD Smith <[email-masked]>
Date: Sun, 5 Nov 2023 12:18:12 -0500

Eli Zaretskii <[email-masked]> writes:

> ...unless someone comes with an idea for how to handle these situations in a sensible way (and I thought long and hard about it, but couldn't find such ideas), this will remain a limitation of move-to-column, and one of the complications introduced by display strings with embedded newlines in general.

Would it not make more sense to place the cursor _before_ the first character with a `\n` in its replacing-display property, if move-to-column attempts to move past it?  It is true that neither that position nor a position on a subsequent line is “correct”, but the former at least preserves the expected move-to-column semantics of “stay on this line”.  

The final newline is the only place to add display on blank lines, so this will be a general problem for any package attempting to do that.  Here’s a simple test of this for people wanting to investigate:

(progn
  (insert "\n>>>>\n" (propertize "\n" 'display "xxxxx\n") "SHOULD NOT MOVE HERE\n<<<<")
  (forward-line -2) ; at beginning of xxxxx\n line
  (move-to-column 10)) ; should not move past the line