From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:306:2d92::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id wDrpKpFJ92S6mAAA9RJhRA:P1 (envelope-from ) for ; Tue, 05 Sep 2023 17:30:25 +0200 Received: from aspmx1.migadu.com ([2001:41d0:306:2d92::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id wDrpKpFJ92S6mAAA9RJhRA (envelope-from ) for ; Tue, 05 Sep 2023 17:30:25 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 5277237865 for ; Tue, 5 Sep 2023 17:30:25 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=whxvd.name header.s=MBO0001 header.b=n7Muq1EF; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1693927825; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=PdzbzfHlgAiYE+ZGtYfrys6pTDruDOBScby9SOL7ny8=; b=pcMvxr8PGszn7mlNuymgnAD3hz1auqOHQs1fwwOJlps46HNwS4zx1i6NtSr88mTy5WP0ze j+4M6QuWtibOFcdpWsur4/g88hSAXq/G0B+/mkXrA1vr0AVZBgHq1VS+yD7pc55W4MEM3z qE5sWPL0dA4OpKLq6XWjAM3bsqb2UzhJ0qSd+5I+eOJRXtcyritY9LDs72pMWBQ5sqXhJc aR19Nf2M3zl4mUwzSeAgJHggfXo7ho8osDJom/szJLLb/amC9UCq3rwtbiQitFCSSjLNZY DFNkVRs+K6UVyylYHHL+4K25/RjVrVmxtp56iND61kOst5D4G01V9ojaMBi+kg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1693927825; a=rsa-sha256; cv=none; b=elqYL8PAehbjp3K7Uq1wbAXPFU4TwQz/zn2dkpP8K08aNvRocHyEActvSEX7AfX/3WUDqk If8Tpz8CstGCBCQCRn9Hk360mzCJHer9v/qnEHp1qgsamwJKUfJBouqf2NWs8gGDK7xcnV /dI9IpxgkYFikKLYMDeknEIA0KcvTwRvLaoAN2Tc/uUT8X5aG8aayj8n0i2EyrEFooqm6G cUqFcce+T4iRjWG4r3meSYxFT1FI/CEi3RVx/s8BJvddSdA4oFRKx6lc6BPucYnrqDT8kI 6h16UHcZNc0emayfv535Kly/dwR72noxcwLazUB0XcRron4JWZ+PIXXwO0PTtg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=whxvd.name header.s=MBO0001 header.b=n7Muq1EF; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=none Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qdXzr-0004Ib-Pi; Tue, 05 Sep 2023 11:29:43 -0400 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 1qdXzp-0004Fl-HA for emacs-orgmode@gnu.org; Tue, 05 Sep 2023 11:29:41 -0400 Received: from mout-p-101.mailbox.org ([2001:67c:2050:0:465::101]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from ) id 1qdXzm-0003Xy-MP; Tue, 05 Sep 2023 11:29:41 -0400 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== References: <87il8pao4l.fsf@whxvd.name> <87tts8vrpb.fsf@localhost> <83h6o84yz1.fsf@gnu.org> From: Sebastian Miele To: Eli Zaretskii Cc: Ihor Radchenko , 65734@debbugs.gnu.org, emacs-orgmode@gnu.org Subject: Re: 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 In-reply-to: <83h6o84yz1.fsf@gnu.org> Message-ID: <875y4oaban.fsf@whxvd.name> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=2001:67c:2050:0:465::101; envelope-from=iota@whxvd.name; helo=mout-p-101.mailbox.org X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Scanner: mx2.migadu.com X-Spam-Score: -7.03 X-Migadu-Queue-Id: 5277237865 X-Migadu-Spam-Score: -7.03 X-TUID: oFoydps4oQjL > 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.