From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Liu Hui Newsgroups: gmane.emacs.bugs Subject: bug#45837: 28.0.50; incorrect cursor position in visual-line-mode when word-wrap-by-category is t Date: Fri, 15 Jan 2021 15:28:33 +0800 Message-ID: References: <838s8wdhbf.fsf@gnu.org> <83v9bzbp8s.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22627"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 45837@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jan 15 08:30:00 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l0JYW-0005ly-7G for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 15 Jan 2021 08:30:00 +0100 Original-Received: from localhost ([::1]:33216 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l0JYV-0005St-5g for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 15 Jan 2021 02:29:59 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53728) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l0JXb-0004xF-QY for bug-gnu-emacs@gnu.org; Fri, 15 Jan 2021 02:29:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:56501) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l0JXa-000209-Ln for bug-gnu-emacs@gnu.org; Fri, 15 Jan 2021 02:29:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l0JXa-00057L-Hz for bug-gnu-emacs@gnu.org; Fri, 15 Jan 2021 02:29:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Liu Hui Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 15 Jan 2021 07:29:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45837 X-GNU-PR-Package: emacs Original-Received: via spool by 45837-submit@debbugs.gnu.org id=B45837.161069573519656 (code B ref 45837); Fri, 15 Jan 2021 07:29:02 +0000 Original-Received: (at 45837) by debbugs.gnu.org; 15 Jan 2021 07:28:55 +0000 Original-Received: from localhost ([127.0.0.1]:39814 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l0JXS-00056y-W0 for submit@debbugs.gnu.org; Fri, 15 Jan 2021 02:28:55 -0500 Original-Received: from mail-yb1-f169.google.com ([209.85.219.169]:38707) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l0JXN-00056i-Kl for 45837@debbugs.gnu.org; Fri, 15 Jan 2021 02:28:53 -0500 Original-Received: by mail-yb1-f169.google.com with SMTP id r63so4210355ybf.5 for <45837@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) In-Reply-To: <83v9bzbp8s.fsf@gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:197973 Archived-At: Eli Zaretskii =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 > > Date: Thu, 14 Jan 2021 12:51:12 +0800 > > Cc: 45837@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!