Subject: Re: 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: Thu, 14 Jan 2021 12:51:12 +0800

Eli Zaretskii <[email-masked]> 于2021年1月13日周三 下午10:47写道：
>
> > From: Liu Hui <[email-masked]>
> > Date: Wed, 13 Jan 2021 10:27:24 +0800
> >
> > Steps to reproduce:
> > 1. emacs -Q
> > 2. eval the following code in the *scratch* buffer:
> >
> >     (with-current-buffer-window "*test*" nil nil
> >       (dotimes (_ 3)
> >         (dotimes (i 10)
> >           (insert "一二三四五六七八九十"))
> >         (dotimes (i 20)
> >           (insert "test ")))
> >       (setq word-wrap-by-category t)
> >       (visual-line-mode))
> >
> > 3. In the *test* buffer, C-a/C-e don't always move the cursor to the
> > beginning/end of screen line. There is also an offset between the mouse
> > click location and the cursor position. If there seems to be no problem,
> > you can adjust the window width and recheck the cursor movement.
>
> Thanks, should be fixed now.

Thank you, cursor motion is correct now.

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?

diff --git a/lisp/simple.el b/lisp/simple.el
index 54c35c04be..86e2c41ac2 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -7337,6 +7337,9 @@ kill-visual-line
       (end-of-visual-line 1)
       (if (= (point) opoint)
          (vertical-motion 1)
+        (when (and word-wrap-by-category
+                   (elt (char-category-set (following-char)) ?|))
+          (forward-char))
        ;; Skip any trailing whitespace at the end of the visual line.
        ;; We used to do this only if `show-trailing-whitespace' is
        ;; nil, but that's wrong; the correct thing would be to check