Subject: bug#45837: 28.0.50; incorrect cursor position in visual-line-mode when word-wrap-by-category is t

From: Liu Hui <[email-masked]>
Date: Fri, 15 Jan 2021 15:28:33 +0800

Eli Zaretskii <[email-masked]> 于2021年1月14日周四 下午9:51写道：
>
> > From: Liu Hui <[email-masked]>
> > Date: Thu, 14 Jan 2021 12:51:12 +0800
> > Cc: [email-masked]
> >
> > BTW, in the case above, if the line wraps after a non-whitespace
> > character, C-k does not delete this character. How about the following
> > change to kill-visual-line?
>
> Yes, good catch.  However, this is not entirely right, as the code you
> suggest should be _instead_ of skipping the whitespace that follows,
> not _in_addition_ to it (imagine that the line is wrapped at a
> non-whitespace character followed by whitespace).  And while looking
> into adapting your patch to avoid removing more than the user
> intended, I found more issues with the existing code.  So I'm
> proposing the patch below instead, which should correctly handle the
> following use cases:
>
>  . visual line that ends in one or more whitespace characters, and the
>    following visual line begins with one or more whitespace characters
>  . visual line that ends with a non-whitespace character (under
>    word-wrap-by-category) that is followed by one or more whitespace
>    characters
>  . line that is continued on the next visual line (visual-line-mode is
>    off)
>  . visual line that is wrapped in the middle of a display string or an
>    overlay string with embedded whitespace characters
>  . visual line that is wrapped in the middle of intangible text
>
> (The patch also fixes some minor issues with the documentation of this
> command.)
>
> WDYT?
>

I have tested the patch and found that the condition `(= (cdr (nth 2
(posn-at-point))) orig-y)` was sometimes too strict. `posn-at-point`
may give slightly different y positions for characters on the same
line when different fonts were used (examples can be found in the
HELLO file). If there are inline graphics (e.g. latex previews), the y
position can also be different.

My suggestion is `(< (abs (- (cdr (nth 2 (posn-at-point))) orig-y))
X)`, where X could be, empirically, `(/ (line-pixel-height) 3)` or
a customizable value.

The patch works well in other cases, thanks!