From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Sebastian Miele Newsgroups: gmane.emacs.bugs Subject: bug#65734: [BUG] kill-whole-line on folded subtrees [9.6.8 (release_9.6.8-3-g21171d @ /home/w/usr/emacs/0/29/0/lisp/org/)] Date: Tue, 05 Sep 2023 17:25:38 +0200 Message-ID: <875y4oaban.fsf__13226.8813949608$1693927840$gmane$org@whxvd.name> References: <87il8pao4l.fsf@whxvd.name> <87tts8vrpb.fsf@localhost> <83h6o84yz1.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="25752"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-orgmode@gnu.org, Ihor Radchenko , 65734@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Sep 05 17:30:31 2023 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 1qdY0c-0006SG-VJ for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 05 Sep 2023 17:30:31 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qdY0B-0004Sx-VC; Tue, 05 Sep 2023 11:30:03 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qdY0A-0004ST-13 for bug-gnu-emacs@gnu.org; Tue, 05 Sep 2023 11:30:02 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qdY09-0003cA-OM for bug-gnu-emacs@gnu.org; Tue, 05 Sep 2023 11:30:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qdY0A-00017k-1X for bug-gnu-emacs@gnu.org; Tue, 05 Sep 2023 11:30:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Sebastian Miele Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 05 Sep 2023 15:30:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65734 X-GNU-PR-Package: emacs Original-Received: via spool by 65734-submit@debbugs.gnu.org id=B65734.16939277744260 (code B ref 65734); Tue, 05 Sep 2023 15:30:01 +0000 Original-Received: (at 65734) by debbugs.gnu.org; 5 Sep 2023 15:29:34 +0000 Original-Received: from localhost ([127.0.0.1]:57865 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qdXzh-00016e-Pm for submit@debbugs.gnu.org; Tue, 05 Sep 2023 11:29:34 -0400 Original-Received: from mout-p-101.mailbox.org ([2001:67c:2050:0:465::101]:47606) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qdXze-00016O-Kc for 65734@debbugs.gnu.org; Tue, 05 Sep 2023 11:29:32 -0400 Original-Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4Rg8Yt0yqDz9stN; Tue, 5 Sep 2023 17:29:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=whxvd.name; s=MBO0001; t=1693927762; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PdzbzfHlgAiYE+ZGtYfrys6pTDruDOBScby9SOL7ny8=; b=n7Muq1EFr6mFICfJ8vozmj9tYqrRKzjiZEp5XSowdCOkIayvpW/1R70LeUUYr7DdekuGIP 3FfUWyXrtq1+CnuX1d+Ema6AIxcgDWDx3KArnuiQpVTdGPoMAyNZn37HP02adloh0yz0PX a4qG+i1YdaodYZ4ikkiHi+GmWBfIzJ808SwYtyJvoZvYzr8JrR3qmRq6HFGCaGOU0z5QZf ruhDDQ2AaAo7gAffQAfxdixyHahxTlYB/krZuD1ydeqnWGoknDBqyIqCrMlBpsOlO79BLX zu8tWWMC1bOlN+MpDmYZsv1W9PTA5yCssOOqmYFk34hI06vsQ7fFmM4kEJUvgg== In-reply-to: <83h6o84yz1.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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:269359 Archived-At: > From: Eli Zaretskii > Date: Tue, 2023-09-05 14:54 +0300 > > [=E2=80=A6] > > So we could decide that this command needs to become smarter when the > visual line includes invisible text. That is, improve the command > without making any Org-specific changes anywhere. Patches to that > effect are welcome. The following would do it. I think I tested it rather thoroughly. During testing I found another bug that is addressed by the let-binding of kill-read-only-ok during the first kill-region below. diff --git a/lisp/simple.el b/lisp/simple.el index abd587245fe..d983cb85ab3 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -6631,28 +6631,50 @@ kill-whole-line (unless (eq last-command 'kill-region) (kill-new "") (setq last-command 'kill-region)) - (cond ((zerop arg) - ;; We need to kill in two steps, because the previous command - ;; could have been a kill command, in which case the text - ;; before point needs to be prepended to the current kill - ;; ring entry and the text after point appended. Also, we - ;; need to use save-excursion to avoid copying the same text - ;; twice to the kill ring in read-only buffers. - (save-excursion - (kill-region (point) (progn (forward-visible-line 0) (point)))) - (kill-region (point) (progn (end-of-visible-line) (point)))) - ((< arg 0) - (save-excursion - (kill-region (point) (progn (end-of-visible-line) (point)))) - (kill-region (point) - (progn (forward-visible-line (1+ arg)) - (unless (bobp) (backward-char)) - (point)))) - (t - (save-excursion - (kill-region (point) (progn (forward-visible-line 0) (point)))) - (kill-region (point) - (progn (forward-visible-line arg) (point)))))) + ;; - We need to kill in two steps, because the previous command + ;; could have been a kill command, in which case the text before + ;; point needs to be prepended to the current kill ring entry and + ;; the text after point appended. + ;; - We need to be careful to avoid copying text twice to the kill + ;; ring in read-only buffers. + ;; - We need to determine the boundaries of visible lines before we + ;; do the first kill, because that may change visibility + ;; (bug#65734). + (let ((regions-begin (point-marker)) + region1-end) + (cond ((zerop arg) + (setq region1-end (save-excursion + (forward-visible-line 0) + (point-marker))) + (end-of-visible-line)) + ((< arg 0) + (setq region1-end (save-excursion + (end-of-visible-line) + (point-marker))) + (forward-visible-line (1+ arg)) + (unless (bobp) (backward-char))) + (t + (setq region1-end (save-excursion + (forward-visible-line 0) + (point-marker))) + (progn (forward-visible-line arg)))) + ;; - Pass the marker positions and not the markers themselves. + ;; kill-region determines whether to prepend or append to a + ;; previous kill by checking the direction of the region. But + ;; it deletes the content and hence moves the markers before + ;; that. That effectively makes every region delimited by + ;; markers an (empty) forward region. + ;; - Make the first kill-region emit a non-local exit only if the + ;; second kill-region below would not operate on a non-empty + ;; region. + (let ((kill-read-only-ok (or kill-read-only-ok + (/=3D regions-begin (point))))) + (kill-region (marker-position regions-begin) + (marker-position region1-end))) + (kill-region (marker-position regions-begin) + (point)) + (set-marker regions-begin nil) + (set-marker region1-end nil))) =20 (defun forward-visible-line (arg) "Move forward by ARG lines, ignoring currently invisible newlines only.