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

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Liu Hui <liuhui1610@HIDDEN>; Done: Eli Zaretskii <eliz@HIDDEN>; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at 45837-done <at> debbugs.gnu.org:


Received: (at 45837-done) by debbugs.gnu.org; 21 Jan 2021 14:22:47 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Jan 21 09:22:47 2021
Received: from localhost ([127.0.0.1]:57199 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1l2arG-0004QF-Q6
	for submit <at> debbugs.gnu.org; Thu, 21 Jan 2021 09:22:46 -0500
Received: from eggs.gnu.org ([209.51.188.92]:41846)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1l2arF-0004Q2-4U
 for 45837-done <at> debbugs.gnu.org; Thu, 21 Jan 2021 09:22:45 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e]:42353)
 by eggs.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <eliz@HIDDEN>)
 id 1l2ar9-0001yk-Uf; Thu, 21 Jan 2021 09:22:39 -0500
Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:2343
 helo=home-c4e4a596f7)
 by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256)
 (Exim 4.82) (envelope-from <eliz@HIDDEN>)
 id 1l2ar9-0007QQ-Cf; Thu, 21 Jan 2021 09:22:39 -0500
Date: Thu, 21 Jan 2021 16:22:53 +0200
Message-Id: <838s8m74jm.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Liu Hui <liuhui1610@HIDDEN>
In-Reply-To: <CAOQTW-M5d1HFrvJHdR=sdPFyYXCByQVxyDm7OYu4eeaY98Vmog@HIDDEN>
 (message from Liu Hui on Thu, 21 Jan 2021 11:07:50 +0800)
Subject: Re: bug#45837: 28.0.50; incorrect cursor position in visual-line-mode
 when word-wrap-by-category is t
References: <CAOQTW-Pr7EG6__BFfP1eg6yqN-9v=zVE1YEwYYtSHeK7EW3UMw@HIDDEN>
 <838s8wdhbf.fsf@HIDDEN>
 <CAOQTW-PgkF5P-TeFeXtY27wwsrefgg42Es0Nj6FSKGYYjYR7bQ@HIDDEN>
 <83v9bzbp8s.fsf@HIDDEN>
 <CAOQTW-MfV0qaKvpmruP1offiBjVyWy1QWaLcgCXZyELeGsdumA@HIDDEN>
 <834kjiboqb.fsf@HIDDEN> <83a6t688wt.fsf@HIDDEN>
 <CAOQTW-M5d1HFrvJHdR=sdPFyYXCByQVxyDm7OYu4eeaY98Vmog@HIDDEN>
MIME-version: 1.0
Content-type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 45837-done
Cc: 45837-done <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Liu Hui <liuhui1610@HIDDEN>
> Date: Thu, 21 Jan 2021 11:07:50 +0800
> Cc: 45837 <at> debbugs.gnu.org
> 
> Eli Zaretskii <eliz@HIDDEN> 于2021年1月19日周二 上午1:14写道:
> >
> > However, posn-at-point also returns the coordinates in (COLUMN . ROW)
> > units, and we can use that instead.  So I propose to fix the current
> > code on master as below.  WDYT?
> 
> I think it's a better fix. Thanks!

Thanks for the feedback.  I've now installed that change, and I'm
closing this bug.




Notification sent to Liu Hui <liuhui1610@HIDDEN>:
bug acknowledged by developer. Full text available.
Reply sent to Eli Zaretskii <eliz@HIDDEN>:
You have taken responsibility. Full text available.

Message received at 45837 <at> debbugs.gnu.org:


Received: (at 45837) by debbugs.gnu.org; 21 Jan 2021 03:08:09 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Jan 20 22:08:09 2021
Received: from localhost ([127.0.0.1]:56529 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1l2QKP-0002C5-Hl
	for submit <at> debbugs.gnu.org; Wed, 20 Jan 2021 22:08:09 -0500
Received: from mail-yb1-f181.google.com ([209.85.219.181]:37716)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <liuhui1610@HIDDEN>) id 1l2QKN-0002Bq-Fc
 for 45837 <at> debbugs.gnu.org; Wed, 20 Jan 2021 22:08:07 -0500
Received: by mail-yb1-f181.google.com with SMTP id z1so703665ybr.4
 for <45837 <at> debbugs.gnu.org>; Wed, 20 Jan 2021 19:08:07 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=mime-version:references:in-reply-to:from:date:message-id:subject:to
 :cc:content-transfer-encoding;
 bh=R3UAAqNoJPclFrG2Qhynx/6+j3Go1CwKdrO+pq3bVy4=;
 b=fhndE7PNqRTQpsrMkoLs5vxwZ4BgsnObxYDmZR4Q1rSJpOLLmEQ5eApoTHOlDdBWcZ
 FvyTA3edmNZJLl+7CUfS7Zm0y2aRT5F6n9Tjy/0WWbHoC9HVJMtLlqauwvPMX+74kOAf
 c62HtzH1N/k+E0KTlEnXm46078B4NOzHWEjpzoQrmnKK0ckk1pVTS3JfbyHuswqbQYzS
 eVHdJB/mPco20E441MRU2GifJJEkm4q+HSvbd2+o5Z42Nd0kXBAVsStVhBnpU9HTrNhE
 PM4z4tar0unKY4ANBn4M96THTWsZLqgjIoEQsAmveG8nMtapBvEt9DKhgMPEuWdhh3QS
 bQPA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:references:in-reply-to:from:date
 :message-id:subject:to:cc:content-transfer-encoding;
 bh=R3UAAqNoJPclFrG2Qhynx/6+j3Go1CwKdrO+pq3bVy4=;
 b=Bg/oNo9mkxhfGqR13jP6oLPGuQ9dyU2MY+Kkax4IKpqCq8GmFtVqqe4O91qzHZ99c+
 C5YqsvEnfg7/FJQNdXEp44pZ5i7hCmv3thTEJHINHVM9YKuSjf5oaqQwPWyAapdkVtHe
 fYgqZbY9X6UH4LXvoSWaVMGQu9yvhgzTDi6XGOLv7yim7Ik9Z7npt0KwOUAU1BdPBTaQ
 pH+RYx+ry867jyWBOAGzAJ/XIfOBzo5ih0WIglBo0lTO95bbS/HreAesQGPrIpemoyR9
 tw8e3AXOb8v3XI57gCok92VSAQFE48X936ew/WCNS2yXq257FGdou9xcnIN5uvyNPDVN
 Lnow==
X-Gm-Message-State: AOAM53230r/cZi98VutbCjvu/yjeo4sjmvZlUSamuvj9OrcbDiQrs1Lk
 56cPuFuBxyMyYIJg95UVJ+N9jSPDqnGTp47hVcA=
X-Google-Smtp-Source: ABdhPJzAX6QwQiwN5Ryvd11cZq+BH+qq8wCsIiLBpbLKnRoUBJPa5SgyR+DREYXOjYZKgRDGGlDExFFYW19aNZitQFw=
X-Received: by 2002:a25:2a56:: with SMTP id q83mr18160124ybq.144.1611198481629; 
 Wed, 20 Jan 2021 19:08:01 -0800 (PST)
MIME-Version: 1.0
References: <CAOQTW-Pr7EG6__BFfP1eg6yqN-9v=zVE1YEwYYtSHeK7EW3UMw@HIDDEN>
 <838s8wdhbf.fsf@HIDDEN>
 <CAOQTW-PgkF5P-TeFeXtY27wwsrefgg42Es0Nj6FSKGYYjYR7bQ@HIDDEN>
 <83v9bzbp8s.fsf@HIDDEN>
 <CAOQTW-MfV0qaKvpmruP1offiBjVyWy1QWaLcgCXZyELeGsdumA@HIDDEN>
 <834kjiboqb.fsf@HIDDEN> <83a6t688wt.fsf@HIDDEN>
In-Reply-To: <83a6t688wt.fsf@HIDDEN>
From: Liu Hui <liuhui1610@HIDDEN>
Date: Thu, 21 Jan 2021 11:07:50 +0800
Message-ID: <CAOQTW-M5d1HFrvJHdR=sdPFyYXCByQVxyDm7OYu4eeaY98Vmog@HIDDEN>
Subject: Re: bug#45837: 28.0.50; incorrect cursor position in visual-line-mode
 when word-wrap-by-category is t
To: Eli Zaretskii <eliz@HIDDEN>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: 0.2 (/)
X-Debbugs-Envelope-To: 45837
Cc: 45837 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.8 (/)

Eli Zaretskii <eliz@HIDDEN> =E4=BA=8E2021=E5=B9=B41=E6=9C=8819=E6=97=A5=E5=
=91=A8=E4=BA=8C =E4=B8=8A=E5=8D=881:14=E5=86=99=E9=81=93=EF=BC=9A
>
> However, posn-at-point also returns the coordinates in (COLUMN . ROW)
> units, and we can use that instead.  So I propose to fix the current
> code on master as below.  WDYT?

I think it's a better fix. Thanks!




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#45837; Package emacs. Full text available.

Message received at 45837 <at> debbugs.gnu.org:


Received: (at 45837) by debbugs.gnu.org; 18 Jan 2021 17:14:14 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Jan 18 12:14:14 2021
Received: from localhost ([127.0.0.1]:48239 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1l1Y6Y-0001PH-91
	for submit <at> debbugs.gnu.org; Mon, 18 Jan 2021 12:14:14 -0500
Received: from eggs.gnu.org ([209.51.188.92]:56098)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1l1Y6W-0001P3-Id
 for 45837 <at> debbugs.gnu.org; Mon, 18 Jan 2021 12:14:13 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e]:60098)
 by eggs.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <eliz@HIDDEN>)
 id 1l1Y6R-0001bU-Do; Mon, 18 Jan 2021 12:14:07 -0500
Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:1254
 helo=home-c4e4a596f7)
 by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256)
 (Exim 4.82) (envelope-from <eliz@HIDDEN>)
 id 1l1Y6N-0007Ny-WA; Mon, 18 Jan 2021 12:14:04 -0500
Date: Mon, 18 Jan 2021 19:14:10 +0200
Message-Id: <83a6t688wt.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: liuhui1610@HIDDEN
In-Reply-To: <834kjiboqb.fsf@HIDDEN> (message from Eli Zaretskii on Fri, 15
 Jan 2021 10:15:08 +0200)
Subject: Re: bug#45837: 28.0.50;
 incorrect cursor position in visual-line-mode when
 word-wrap-by-category is t
References: <CAOQTW-Pr7EG6__BFfP1eg6yqN-9v=zVE1YEwYYtSHeK7EW3UMw@HIDDEN>
 <838s8wdhbf.fsf@HIDDEN>
 <CAOQTW-PgkF5P-TeFeXtY27wwsrefgg42Es0Nj6FSKGYYjYR7bQ@HIDDEN>
 <83v9bzbp8s.fsf@HIDDEN>
 <CAOQTW-MfV0qaKvpmruP1offiBjVyWy1QWaLcgCXZyELeGsdumA@HIDDEN>
 <834kjiboqb.fsf@HIDDEN>
MIME-version: 1.0
Content-type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 45837
Cc: 45837 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> Date: Fri, 15 Jan 2021 10:15:08 +0200
> From: Eli Zaretskii <eliz@HIDDEN>
> Cc: 45837 <at> debbugs.gnu.org
> 
> > From: Liu Hui <liuhui1610@HIDDEN>
> > Date: Fri, 15 Jan 2021 15:28:33 +0800
> > Cc: 45837 <at> debbugs.gnu.org
> > 
> > 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.
> 
> Hmm... you are right.  But that sounds like a bug in posn-at-point, I
> will look into fixing it soon.

Upon looking into this, it isn't a bug: posn-at-point is working as
designed and documented:

  Return nil if POS is not visible in WINDOW.  Otherwise,
  the return value is similar to that returned by ‘event-start’ for
  a mouse click at the upper left corner of the glyph corresponding
  to POS:       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

"At the upper left corner of the glyph".  IOW, if we ask about a glyph
from a small font on an otherwise tall visual line, posn-at-point will
try to adjust the Y coordinate for the fact that the glyph is smaller,
and thus its upper left corner is further down from the window top.

So using the (X . Y) part of what posn-at-point returns is unworkable
for the purpose of this issue: a character about which we are asking
can be arbitrarily small, and thus to work in all the cases, we will
have to allow for a very large tolerance, and that could miss some
situations where we really end up on the next visual line.

However, posn-at-point also returns the coordinates in (COLUMN . ROW)
units, and we can use that instead.  So I propose to fix the current
code on master as below.  WDYT?

diff --git a/lisp/simple.el b/lisp/simple.el
index 37c0885dcc..2c6e3916cd 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -7338,10 +7338,7 @@ kill-visual-line
   ;; of the kill before killing.
   (let ((opoint (point))
         (kill-whole-line (and kill-whole-line (bolp)))
-        (orig-y (cdr (nth 2 (posn-at-point))))
-        ;; FIXME: This tolerance should be zero!  It isn't due to a
-        ;; bug in posn-at-point, see bug#45837.
-        (tol (/ (line-pixel-height) 2)))
+        (orig-vlnum (cdr (nth 6 (posn-at-point)))))
     (if arg
 	(vertical-motion (prefix-numeric-value arg))
       (end-of-visual-line 1)
@@ -7352,8 +7349,8 @@ kill-visual-line
         ;; end-of-visual-line didn't overshoot due to complications
         ;; like display or overlay strings, intangible text, etc.:
         ;; otherwise, we don't want to kill a character that's
-        ;; unrelated to the place where the visual line wrapped.
-        (and (< (abs (- (cdr (nth 2 (posn-at-point))) orig-y)) tol)
+        ;; unrelated to the place where the visual line wraps.
+        (and (= (cdr (nth 6 (posn-at-point))) orig-vlnum)
              ;; Make sure we delete the character where the line wraps
              ;; under visual-line-mode, be it whitespace or a
              ;; character whose category set allows to wrap at it.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#45837; Package emacs. Full text available.

Message received at 45837 <at> debbugs.gnu.org:


Received: (at 45837) by debbugs.gnu.org; 15 Jan 2021 08:15:29 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Jan 15 03:15:29 2021
Received: from localhost ([127.0.0.1]:39845 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1l0KGX-0006EU-EO
	for submit <at> debbugs.gnu.org; Fri, 15 Jan 2021 03:15:29 -0500
Received: from eggs.gnu.org ([209.51.188.92]:38984)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1l0KGU-0006EH-Vs
 for 45837 <at> debbugs.gnu.org; Fri, 15 Jan 2021 03:15:27 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e]:40892)
 by eggs.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <eliz@HIDDEN>)
 id 1l0KGP-00075X-R8; Fri, 15 Jan 2021 03:15:21 -0500
Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:1516
 helo=home-c4e4a596f7)
 by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256)
 (Exim 4.82) (envelope-from <eliz@HIDDEN>)
 id 1l0KGF-0006os-KA; Fri, 15 Jan 2021 03:15:21 -0500
Date: Fri, 15 Jan 2021 10:15:08 +0200
Message-Id: <834kjiboqb.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Liu Hui <liuhui1610@HIDDEN>
In-Reply-To: <CAOQTW-MfV0qaKvpmruP1offiBjVyWy1QWaLcgCXZyELeGsdumA@HIDDEN>
 (message from Liu Hui on Fri, 15 Jan 2021 15:28:33 +0800)
Subject: Re: bug#45837: 28.0.50; incorrect cursor position in visual-line-mode
 when word-wrap-by-category is t
References: <CAOQTW-Pr7EG6__BFfP1eg6yqN-9v=zVE1YEwYYtSHeK7EW3UMw@HIDDEN>
 <838s8wdhbf.fsf@HIDDEN>
 <CAOQTW-PgkF5P-TeFeXtY27wwsrefgg42Es0Nj6FSKGYYjYR7bQ@HIDDEN>
 <83v9bzbp8s.fsf@HIDDEN>
 <CAOQTW-MfV0qaKvpmruP1offiBjVyWy1QWaLcgCXZyELeGsdumA@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 45837
Cc: 45837 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Liu Hui <liuhui1610@HIDDEN>
> Date: Fri, 15 Jan 2021 15:28:33 +0800
> Cc: 45837 <at> debbugs.gnu.org
> 
> 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.

Hmm... you are right.  But that sounds like a bug in posn-at-point, I
will look into fixing it soon.

> 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.

I went with half the line height, thanks.

> The patch works well in other cases, thanks!

Thanks for testing, I've now installed the change on the master
branch.  I'm not yet closing the bug, because I want to see what can
be done about removing the tolerance in comparing values of
posn-at-point.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#45837; Package emacs. Full text available.

Message received at 45837 <at> debbugs.gnu.org:


Received: (at 45837) by debbugs.gnu.org; 15 Jan 2021 07:28:55 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Jan 15 02:28:55 2021
Received: from localhost ([127.0.0.1]:39814 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1l0JXS-00056y-W0
	for submit <at> debbugs.gnu.org; Fri, 15 Jan 2021 02:28:55 -0500
Received: from mail-yb1-f169.google.com ([209.85.219.169]:38707)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <liuhui1610@HIDDEN>) id 1l0JXN-00056i-Kl
 for 45837 <at> debbugs.gnu.org; Fri, 15 Jan 2021 02:28:53 -0500
Received: by mail-yb1-f169.google.com with SMTP id r63so4210355ybf.5
 for <45837 <at> debbugs.gnu.org>; Thu, 14 Jan 2021 23:28:49 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=mime-version:references:in-reply-to:from:date:message-id:subject:to
 :cc:content-transfer-encoding;
 bh=Zx+poW4xVgL4/htp3/SDMarE1Quf/zoWV+aVY/oXyH0=;
 b=XXvDjhs+09ETe/IGB/MTjdPzEyMX57ckcU4oZ8SLsamYc0o1IbFBV4HStUNQdQ72sJ
 RvjihUpXoGRnuRIv43prb27RyeA1THV5KtmGhp3vavGqyQod0ix+eYmNWdCdf9OqCRX3
 jlyBn/3OXWH990piomP2nzG0ml1GFG/+3Mb3U61uHImiIxcg99ejDxDVCbiAk9EgqqDr
 b1h0PRd68vKmI9HBE8Zbk0TcsfY6pKWQYqBBbM73ehoATxnwYWJEWEbIy6jvl0YAnP3e
 fcDxZvCD/Pnzp/5AjPcBe1awJUkyfp06TrL2rBFIF2LR1mlw1h9ji2H1/NcM6Mi8AGWv
 dgcQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:references:in-reply-to:from:date
 :message-id:subject:to:cc:content-transfer-encoding;
 bh=Zx+poW4xVgL4/htp3/SDMarE1Quf/zoWV+aVY/oXyH0=;
 b=nTo+qEoMyz2rcolQLkvqjSFnVQc4N/SUTXSpPs4gOxh0E5ELUACPkkJs6DskOIDzTo
 SPeOmBoYiSZAKZ65HkyoGA/EynZ2zlgq4+e7r/K3+IJ7BuXA0yJK0tJLRDVVa1LvdSRO
 Kz+58FttXCCV35uzblOfovLEmobp/P28aHbuFyL724wOPqcFHPoI+Xx5BsUVSE2PtBqW
 oQRivFgbCK7OJaEqdjMJ6UiTEYGPBMvz/LCNE7ThvwiiZ3KiR2CDGLDAIeDk4D1R4GpZ
 gHQB4pAsHr9T+DQ3+QccmrNgCmrpErE0FkpttKaUCDZx9p+TNKyDCL7X9bATzgk79zRs
 H8Pg==
X-Gm-Message-State: AOAM532AtbUEuotCwaqRN9JoUs0jrD6Uy50/dQk51MMw2C7SyhSG9FZr
 2DL/fftaWeIwWaGV/JrL6U8xL/dosECCvoAuTEj+ZZi7jKhihw==
X-Google-Smtp-Source: ABdhPJwlQXhpuhUL+kbqnI7rmmai8OBJEeEgemJJlFOYqUKtZBu18F/GjazjS/l8OO9YYmOp2GYWQ4AnRKVRV0Ueqgs=
X-Received: by 2002:a25:d98e:: with SMTP id
 q136mr17119470ybg.280.1610695724066; 
 Thu, 14 Jan 2021 23:28:44 -0800 (PST)
MIME-Version: 1.0
References: <CAOQTW-Pr7EG6__BFfP1eg6yqN-9v=zVE1YEwYYtSHeK7EW3UMw@HIDDEN>
 <838s8wdhbf.fsf@HIDDEN>
 <CAOQTW-PgkF5P-TeFeXtY27wwsrefgg42Es0Nj6FSKGYYjYR7bQ@HIDDEN>
 <83v9bzbp8s.fsf@HIDDEN>
In-Reply-To: <83v9bzbp8s.fsf@HIDDEN>
From: Liu Hui <liuhui1610@HIDDEN>
Date: Fri, 15 Jan 2021 15:28:33 +0800
Message-ID: <CAOQTW-MfV0qaKvpmruP1offiBjVyWy1QWaLcgCXZyELeGsdumA@HIDDEN>
Subject: Re: bug#45837: 28.0.50; incorrect cursor position in visual-line-mode
 when word-wrap-by-category is t
To: Eli Zaretskii <eliz@HIDDEN>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: 0.2 (/)
X-Debbugs-Envelope-To: 45837
Cc: 45837 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.8 (/)

Eli Zaretskii <eliz@HIDDEN> =E4=BA=8E2021=E5=B9=B41=E6=9C=8814=E6=97=A5=E5=
=91=A8=E5=9B=9B =E4=B8=8B=E5=8D=889:51=E5=86=99=E9=81=93=EF=BC=9A
>
> > From: Liu Hui <liuhui1610@HIDDEN>
> > Date: Thu, 14 Jan 2021 12:51:12 +0800
> > Cc: 45837 <at> debbugs.gnu.org
> >
> > 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 `(=3D (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!




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#45837; Package emacs. Full text available.

Message received at 45837 <at> debbugs.gnu.org:


Received: (at 45837) by debbugs.gnu.org; 14 Jan 2021 13:52:01 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Jan 14 08:52:01 2021
Received: from localhost ([127.0.0.1]:37526 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1l032e-0003xf-Pn
	for submit <at> debbugs.gnu.org; Thu, 14 Jan 2021 08:52:01 -0500
Received: from eggs.gnu.org ([209.51.188.92]:35076)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1l032a-0003xP-St
 for 45837 <at> debbugs.gnu.org; Thu, 14 Jan 2021 08:51:59 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e]:50722)
 by eggs.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <eliz@HIDDEN>)
 id 1l032T-0003PT-Bz; Thu, 14 Jan 2021 08:51:51 -0500
Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:4427
 helo=home-c4e4a596f7)
 by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256)
 (Exim 4.82) (envelope-from <eliz@HIDDEN>)
 id 1l032S-0003Kr-LK; Thu, 14 Jan 2021 08:51:49 -0500
Date: Thu, 14 Jan 2021 15:51:47 +0200
Message-Id: <83v9bzbp8s.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Liu Hui <liuhui1610@HIDDEN>
In-Reply-To: <CAOQTW-PgkF5P-TeFeXtY27wwsrefgg42Es0Nj6FSKGYYjYR7bQ@HIDDEN>
 (message from Liu Hui on Thu, 14 Jan 2021 12:51:12 +0800)
Subject: Re: bug#45837: 28.0.50; incorrect cursor position in visual-line-mode
 when word-wrap-by-category is t
References: <CAOQTW-Pr7EG6__BFfP1eg6yqN-9v=zVE1YEwYYtSHeK7EW3UMw@HIDDEN>
 <838s8wdhbf.fsf@HIDDEN>
 <CAOQTW-PgkF5P-TeFeXtY27wwsrefgg42Es0Nj6FSKGYYjYR7bQ@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 45837
Cc: 45837 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Liu Hui <liuhui1610@HIDDEN>
> Date: Thu, 14 Jan 2021 12:51:12 +0800
> Cc: 45837 <at> debbugs.gnu.org
> 
> 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?

diff --git a/lisp/simple.el b/lisp/simple.el
index 54c35c04be..e7421c069f 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -5606,7 +5606,9 @@ zap-to-char
 ;; kill-line and its subroutines.
 
 (defcustom kill-whole-line nil
-  "If non-nil, `kill-line' with no arg at start of line kills the whole line."
+  "If non-nil, `kill-line' with no arg at start of line kills the whole line.
+This variable also affects `kill-visual-line' in the same way as
+it does `kill-line'."
   :type 'boolean
   :group 'killing)
 
@@ -7319,6 +7321,9 @@ kill-visual-line
 If ARG is zero, kill the text before point on the current visual
 line.
 
+If `kill-whole-line' is non-nil, and this command is invoked at
+start of a line that ands in a newline, kill the newline as well.
+
 If you want to append the killed line to the last killed text,
 use \\[append-next-kill] before \\[kill-line].
 
@@ -7331,18 +7336,26 @@ kill-visual-line
   ;; Like in `kill-line', it's better to move point to the other end
   ;; of the kill before killing.
   (let ((opoint (point))
-	(kill-whole-line (and kill-whole-line (bolp))))
+        (kill-whole-line (and kill-whole-line (bolp)))
+        (orig-y (cdr (nth 2 (posn-at-point)))))
     (if arg
 	(vertical-motion (prefix-numeric-value arg))
       (end-of-visual-line 1)
       (if (= (point) opoint)
 	  (vertical-motion 1)
-	;; 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
-	;; whether the trailing whitespace is highlighted.  But, it's
-	;; OK to just do this unconditionally.
-	(skip-chars-forward " \t")))
+        ;; The first condition below verifies we are still on the same
+        ;; screen line, i.e. that the line isn't continued, and that
+        ;; end-of-visual-line didn't overshoot due to complications
+        ;; like display or overlay strings, intangible text, etc.:
+        ;; otherwise, we don't want to kill a character that's
+        ;; unrelated to the place where the visual line wrapped.
+        (and (= (cdr (nth 2 (posn-at-point))) orig-y)
+             ;; Make sure we delete the character where the line wraps
+             ;; under visual-line-mode.
+             (or (looking-at-p "[ \t]")
+                 (and word-wrap-by-category
+                      (aref (char-category-set (following-char)) ?\|)))
+             (forward-char))))
     (kill-region opoint (if (and kill-whole-line (= (following-char) ?\n))
 			    (1+ (point))
 			  (point)))))




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#45837; Package emacs. Full text available.

Message received at 45837 <at> debbugs.gnu.org:


Received: (at 45837) by debbugs.gnu.org; 14 Jan 2021 04:51:31 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Jan 13 23:51:31 2021
Received: from localhost ([127.0.0.1]:36987 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1kzuba-0006aw-Ps
	for submit <at> debbugs.gnu.org; Wed, 13 Jan 2021 23:51:31 -0500
Received: from mail-qk1-f181.google.com ([209.85.222.181]:46601)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <liuhui1610@HIDDEN>) id 1kzubZ-0006ag-55
 for 45837 <at> debbugs.gnu.org; Wed, 13 Jan 2021 23:51:30 -0500
Received: by mail-qk1-f181.google.com with SMTP id d14so5670215qkc.13
 for <45837 <at> debbugs.gnu.org>; Wed, 13 Jan 2021 20:51:29 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=mime-version:references:in-reply-to:from:date:message-id:subject:to
 :cc:content-transfer-encoding;
 bh=Duso+8r5/60tDrlUlKeodhGDPlJbeW7/ZkP/Lb/Y0u4=;
 b=b6myKw6ZBqwCdr1uAuM37ShmV5P8ZQmN/+Pi7ZyO7NGRoA+spIVxFIUsorgHc/dWR0
 M1ff4lNtzUSn9CWv728He950VNG0zyW0H2sjnv535H3nILlLev9MmVedGPzicI+0ZDhT
 geK5INED5+F/C7qKEJVHof/gS430pxdvMPZxEa8K69cZLAPUrfNpJ3QecQs4QQGPwj/u
 NLKrqEns8rWANP1d2o/24dxCEaEyBl0yX9qAH8vrnp49M6gm/nRPCOAn6yvviVVygBqb
 1uk6gs4CCDlMXI22Q8/HmezlaUoZYdAAN168dS297nxhLDijZM6607rkZjN8eofwKzBJ
 2ZPA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:references:in-reply-to:from:date
 :message-id:subject:to:cc:content-transfer-encoding;
 bh=Duso+8r5/60tDrlUlKeodhGDPlJbeW7/ZkP/Lb/Y0u4=;
 b=HL9/kIGpJrOLUS281Ekd/S2/buD5jOmXSPksCr70WaLqHldtNSLOYWYYSJiDTbE33J
 y8ualRPgtP8vAsEIcV13rSkU9+aoVN8ApBy4Ci5+XgOa/om6VGIQUdkYxmgZCe+9DjoB
 MKrl9gmhtdudv2TGOvkOCF5NF1wbagBDQk7CkQGcRiaYRtoHnr/oQnRXIM2fI2nuwryz
 bV/E+4tkJqxZKlaPuxif1PsLahKqHvWzF54QzNwcg7AeWi7xyih19cxnyb2XSAdN7xao
 eNY5+1tA4jE6vR8IoG96NKFkYW7gflJsUpDA3LElGM+OABOqoGoMFKJusHpOs5l4IVHB
 5h4w==
X-Gm-Message-State: AOAM530J9kOPd3zZ7EBR9wbpdfZ/GLQIAT2LlUswmPHogusXlDiu/OPD
 kH+99faxHMwwbJ6oxfWzhKqjPD89bqDDR4TQOeM=
X-Google-Smtp-Source: ABdhPJzCcvJcH3hLwj/y0MPGxGo9Ir3MHVYIvhjHfiFPnAkpNXgF2Re91tz1VZRrFnH63Bdak2x4Xuflxbc0+0y5Ar0=
X-Received: by 2002:a25:26c7:: with SMTP id m190mr7889830ybm.464.1610599883412; 
 Wed, 13 Jan 2021 20:51:23 -0800 (PST)
MIME-Version: 1.0
References: <CAOQTW-Pr7EG6__BFfP1eg6yqN-9v=zVE1YEwYYtSHeK7EW3UMw@HIDDEN>
 <838s8wdhbf.fsf@HIDDEN>
In-Reply-To: <838s8wdhbf.fsf@HIDDEN>
From: Liu Hui <liuhui1610@HIDDEN>
Date: Thu, 14 Jan 2021 12:51:12 +0800
Message-ID: <CAOQTW-PgkF5P-TeFeXtY27wwsrefgg42Es0Nj6FSKGYYjYR7bQ@HIDDEN>
Subject: Re: bug#45837: 28.0.50; incorrect cursor position in visual-line-mode
 when word-wrap-by-category is t
To: Eli Zaretskii <eliz@HIDDEN>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: 0.2 (/)
X-Debbugs-Envelope-To: 45837
Cc: 45837 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.8 (/)

Eli Zaretskii <eliz@HIDDEN> =E4=BA=8E2021=E5=B9=B41=E6=9C=8813=E6=97=A5=E5=
=91=A8=E4=B8=89 =E4=B8=8B=E5=8D=8810:47=E5=86=99=E9=81=93=EF=BC=9A
>
> > From: Liu Hui <liuhui1610@HIDDEN>
> > 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 "=E4=B8=80=E4=BA=8C=E4=B8=89=E5=9B=9B=E4=BA=94=E5=85=
=AD=E4=B8=83=E5=85=AB=E4=B9=9D=E5=8D=81"))
> >         (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 (=3D (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




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#45837; Package emacs. Full text available.

Message received at 45837 <at> debbugs.gnu.org:


Received: (at 45837) by debbugs.gnu.org; 13 Jan 2021 14:48:00 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Jan 13 09:48:00 2021
Received: from localhost ([127.0.0.1]:34766 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1kzhRH-0007JL-Re
	for submit <at> debbugs.gnu.org; Wed, 13 Jan 2021 09:48:00 -0500
Received: from eggs.gnu.org ([209.51.188.92]:36278)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1kzhRF-0007J5-Ge
 for 45837 <at> debbugs.gnu.org; Wed, 13 Jan 2021 09:47:57 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e]:57296)
 by eggs.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <eliz@HIDDEN>)
 id 1kzhR8-0004qU-Ks; Wed, 13 Jan 2021 09:47:52 -0500
Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:2198
 helo=home-c4e4a596f7)
 by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256)
 (Exim 4.82) (envelope-from <eliz@HIDDEN>)
 id 1kzhR7-0006MS-WA; Wed, 13 Jan 2021 09:47:50 -0500
Date: Wed, 13 Jan 2021 16:47:48 +0200
Message-Id: <838s8wdhbf.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Liu Hui <liuhui1610@HIDDEN>
In-Reply-To: <CAOQTW-Pr7EG6__BFfP1eg6yqN-9v=zVE1YEwYYtSHeK7EW3UMw@HIDDEN>
 (message from Liu Hui on Wed, 13 Jan 2021 10:27:24 +0800)
Subject: Re: bug#45837: 28.0.50;
 incorrect cursor position in visual-line-mode when
 word-wrap-by-category is t
References: <CAOQTW-Pr7EG6__BFfP1eg6yqN-9v=zVE1YEwYYtSHeK7EW3UMw@HIDDEN>
MIME-version: 1.0
Content-type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 45837
Cc: 45837 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Liu Hui <liuhui1610@HIDDEN>
> 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.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#45837; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 13 Jan 2021 02:27:43 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Jan 12 21:27:42 2021
Received: from localhost ([127.0.0.1]:33836 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1kzVss-0003Le-JM
	for submit <at> debbugs.gnu.org; Tue, 12 Jan 2021 21:27:42 -0500
Received: from lists.gnu.org ([209.51.188.17]:58340)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <liuhui1610@HIDDEN>) id 1kzVsp-0003LV-Oh
 for submit <at> debbugs.gnu.org; Tue, 12 Jan 2021 21:27:40 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10]:52648)
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <liuhui1610@HIDDEN>)
 id 1kzVso-0001Xg-Nf
 for bug-gnu-emacs@HIDDEN; Tue, 12 Jan 2021 21:27:39 -0500
Received: from mail-yb1-xb44.google.com ([2607:f8b0:4864:20::b44]:45360)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <liuhui1610@HIDDEN>)
 id 1kzVsm-0003LU-QL
 for bug-gnu-emacs@HIDDEN; Tue, 12 Jan 2021 21:27:38 -0500
Received: by mail-yb1-xb44.google.com with SMTP id k78so707286ybf.12
 for <bug-gnu-emacs@HIDDEN>; Tue, 12 Jan 2021 18:27:35 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=mime-version:from:date:message-id:subject:to
 :content-transfer-encoding;
 bh=X49yU8jdUP2cVzoOWOBySBVUiz5f9aYgCBJ6a1vaR6Y=;
 b=bQk7w59h5FBEn3TCsVq8BGla9EQpUtMYJGGIE4ntYXKpBb4SKXoAmTXFlNNiHMwZlZ
 RO7hKY9pJBe5zMZynVCGCDtwKib3dEQzvn4ljZ5mEevOjIE7Y18LMFWNir2WH/NnFADv
 HHrD+Jx67dKSnvX9M0rrpRMorEAndBdi4c/W//55vT4joPT2hozHIvvv9CDB3yYRN3bD
 KC9pQ8kAWNrz6Gkn6UotiFglXywfEnnb3pSfXFWrr7xlYH3ME3AWrNj/Pwxr8pPv8QHC
 /Syn6o9YwkBlEdiaGtprL6b4ssjoL83TooeDk8YFW22wKzrhPRU/Sb5E3kEEIM7CHnBc
 98xA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:from:date:message-id:subject:to
 :content-transfer-encoding;
 bh=X49yU8jdUP2cVzoOWOBySBVUiz5f9aYgCBJ6a1vaR6Y=;
 b=E+sZIjJfnkvGxiax6sIY3SzFWkL9cADN7hlMjxEdslL8oI4sgNq9TRKuxLRP9FLw5R
 WGed/DtE+SY0/Fx+3HeSPIT2HQh2z4zzXbMTSi7HdyuaYuw99JOn8WEedtoXP3mWQ12V
 q/9q204OFHyP9V7lGt5uXmvr45THXL9osFN6Y72sIeJLfgl5huuPnmmOOmK+bX+kegbu
 lCjyfuyFVszGtiJr/wPwWUnRq1UdSU8gw9vmXDuM7oyv/XnjiCC1GhP7JBluEvObGOKS
 LQX13SKvL1zt4MWHgZhgxMGAZjrQIdWf/ur27MiIUW25Z3IqE6FA1RO2u0EuUnkK+iS3
 6G8A==
X-Gm-Message-State: AOAM532fNj1Vvobv4hk0DTzBq8kmZyMR0Yi0iVKwYbCGdDynX25NIF09
 3iI394gyQOuldZ1UFIrRRnor4alxf6yMjaX/75OWlf/CYiUIZFmqKxQ=
X-Google-Smtp-Source: ABdhPJx6gDf/mQ+/4L5Eq44ZXA8do3hEWVu4x4aiLM8iy50XTXZ17kySo9ep3MrMMvMDLZhWK6NKw05U6kttK7Pd0UQ=
X-Received: by 2002:a25:d802:: with SMTP id p2mr180160ybg.305.1610504854807;
 Tue, 12 Jan 2021 18:27:34 -0800 (PST)
MIME-Version: 1.0
From: Liu Hui <liuhui1610@HIDDEN>
Date: Wed, 13 Jan 2021 10:27:24 +0800
Message-ID: <CAOQTW-Pr7EG6__BFfP1eg6yqN-9v=zVE1YEwYYtSHeK7EW3UMw@HIDDEN>
Subject: 28.0.50; incorrect cursor position in visual-line-mode when
 word-wrap-by-category is t
To: bug-gnu-emacs@HIDDEN
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass client-ip=2607:f8b0:4864:20::b44;
 envelope-from=liuhui1610@HIDDEN; helo=mail-yb1-xb44.google.com
X-Spam_score_int: -17
X-Spam_score: -1.8
X-Spam_bar: -
X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
 FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001,
 RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: -1.1 (-)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.1 (--)

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 "=E4=B8=80=E4=BA=8C=E4=B8=89=E5=9B=9B=E4=BA=94=E5=85=AD=
=E4=B8=83=E5=85=AB=E4=B9=9D=E5=8D=81"))
        (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.


In GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
3.24.20, cairo version 1.16.0)
of 2021-01-12 built on lcy01-amd64-029
Windowing system distributor 'The X.Org Foundation', version 11.0.12009000
System Description: Ubuntu 20.04.1 LTS

Configured using:
'configure --build=3Dx86_64-linux-gnu --prefix=3D/usr
'--includedir=3D${prefix}/include' '--mandir=3D${prefix}/share/man'
'--infodir=3D${prefix}/share/info' --sysconfdir=3D/etc --localstatedir=3D/v=
ar
--disable-silent-rules '--libdir=3D${prefix}/lib/x86_64-linux-gnu'
'--libexecdir=3D${prefix}/lib/x86_64-linux-gnu' --disable-maintainer-mode
--disable-dependency-tracking --prefix=3D/usr --sharedstatedir=3D/var/lib
--program-suffix=3D-snapshot --with-modules=3Dyes --with-x=3Dyes
--with-x-toolkit=3Dgtk3 --with-xwidgets=3Dyes 'CFLAGS=3D-g -O2
-fdebug-prefix-map=3D/build/emacs-snapshot-4HYkJA/emacs-snapshot-103322=3D.
-fstack-protector-strong
-Wformat -Werror=3Dformat-security' 'CPPFLAGS=3D-Wdate-time
-D_FORTIFY_SOURCE=3D2' 'LDFLAGS=3D-Wl,-Bsymbolic-functions -Wl,-z,relro''

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NOTIFY
INOTIFY PDUMPER PNG RSVG SOUND THREADS TIFF TOOLKIT_SCROLL_BARS X11 XDBE
XIM XPM XWIDGETS GTK3 ZLIB

Important settings:
value of $LANG: zh_CN.UTF-8
value of $XMODIFIERS: @im=3Dibus
locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
tooltip-mode: t
global-eldoc-mode: t
eldoc-mode: t
electric-indent-mode: t
mouse-wheel-mode: t
tool-bar-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
blink-cursor-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
line-number-mode: t
transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs
rfc822 mml easymenu mml-sec epa derived epg epg-config gnus-util rmail
rmail-loaddefs auth-source cl-seq eieio eieio-core cl-macs
eieio-loaddefs password-cache json map text-property-search time-date
subr-x seq byte-opt gv bytecomp byte-compile cconv mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader cl-loaddefs
cl-lib sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils
china-util iso-transl tooltip eldoc electric uniquify ediff-hook
vc-hooks lisp-float-type mwheel term/x-win x-win term/common-win x-dnd
tool-bar dnd fontset image regexp-opt fringe tabulated-list replace
newcomment text-mode elisp-mode lisp-mode prog-mode register page
tab-bar menu-bar rfn-eshadow isearch timer select scroll-bar mouse
jit-lock font-lock syntax facemenu font-core term/tty-colors frame
minibuffer cl-generic cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite charscript charprop case-table epa-hook jka-cmpr-hook help
simple abbrev obarray cl-preloaded nadvice button loaddefs faces
cus-face macroexp files window text-properties overlay sha1 md5 base64
format env code-pages mule custom widget hashtable-print-readable
backquote threads xwidget-internal dbusbind inotify lcms2
dynamic-setting system-font-setting font-render-setting cairo
move-toolbar gtk x-toolkit x multi-tty make-network-process emacs)

Memory information:
((conses 16 51700 5953)
(symbols 48 6834 1)
(strings 32 18505 2017)
(string-bytes 1 607714)
(vectors 16 12701)
(vector-slots 8 222094 12046)
(floats 8 21 45)
(intervals 56 226 0)
(buffers 984 10))




Acknowledgement sent to Liu Hui <liuhui1610@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#45837; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Thu, 21 Jan 2021 14:30:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.