From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id sAkuBB7l3GInGAEAbAwnHQ (envelope-from ) for ; Sun, 24 Jul 2022 08:22:22 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id MCJkAx7l3GIoRAAAG6o9tA (envelope-from ) for ; Sun, 24 Jul 2022 08:22:22 +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 B12831A5F1 for ; Sun, 24 Jul 2022 08:22:20 +0200 (CEST) Received: from localhost ([::1]:50904 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oFV0N-0007aH-GI for larch@yhetil.org; Sun, 24 Jul 2022 02:22:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47780) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oFUzG-0007Zv-DM for emacs-orgmode@gnu.org; Sun, 24 Jul 2022 02:21:10 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]:43944) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oFUzE-0000UY-LF for emacs-orgmode@gnu.org; Sun, 24 Jul 2022 02:21:10 -0400 Received: by mail-pf1-x42d.google.com with SMTP id b9so7749379pfp.10 for ; Sat, 23 Jul 2022 23:21:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=JwQ7P6FA/nGifvnYZj4zHDK3TefVry4WoN8Qy4Kb/II=; b=RwIn6SrvglJ+td++hs5HxuAwYBLgGWaFiwYNrI7I3gEWsxgA7Pui51gzKODRPDU1ca g5nClh6VMjrF7ispuGPdkqZmE3VcAl6dN+Rqa8DhaAmgoS+g/K5ScMc5+0gaFXtDcqNi /mtiQYhds7Ja01+bbk0xyPObQmWfXOMdvLtriVKQAgV7ZCYNtGs0NxT3aw1QXOvyBkgn meF7NF8OeNXbmXLnzAv3ip3hydcylZuC9jgbnzF7ciBVJxp8XR1556/IYjZF0N7IBSmi LeHSsZAIHP7gDC1OooT3e0oryWxbo3YLZIuoWD9zKkxfbL04ddDWDVkZ8a7psEkTc7hR fx2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=JwQ7P6FA/nGifvnYZj4zHDK3TefVry4WoN8Qy4Kb/II=; b=xKFbGdOy3sX643itHJETc1JwOsrxrSwWeWEOe5ZHmS+wMp218rwD+/aKdll+ORc4Qr VS9D/IxHYy3efkmcJpDGmC+JQzBhUo3S6cqoQVbb672HPQDYu1gk9M75nwYMjUOu+nRb HAg4r/MwTIjLJuuHn3IOQYVMs1kn6BRBs8EfgplAmjNIkh3rRIXhEJTAOofbrjR2fzGq S7Q2pLHZOLuwuTizJAwAAaeOgiPW1GDjkMSv/lQjP7ul63lfm7Jjudu/FDzGsLxMYtG5 ib6pOySzRcyDq3C+Q1uAt/RkUnrpOfDDeC/CyV06Q+pSw0ZoOFig/zROcQiO/CBzzb8S AnPw== X-Gm-Message-State: AJIora/3RPRF5aXTosKDiAi4YZVCuGOAQSyxpzMJwkb+CkWRfzXMwcXE ID3tEC7R8czIgvxgwfGST4Q= X-Google-Smtp-Source: AGRyM1tn5vE3WYuE4Q8QMqyAlwHYuyAhu8FSdgwd9BAo6kIQh341YyMxq910qxtLHp7WslRoVkiBHA== X-Received: by 2002:a63:2686:0:b0:419:a2da:5078 with SMTP id m128-20020a632686000000b00419a2da5078mr6388813pgm.613.1658643666708; Sat, 23 Jul 2022 23:21:06 -0700 (PDT) Received: from localhost ([1.83.155.1]) by smtp.gmail.com with ESMTPSA id h13-20020a170902680d00b0016ce31cfea6sm6646949plk.159.2022.07.23.23.21.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Jul 2022 23:21:05 -0700 (PDT) From: Ihor Radchenko To: Caleb Chase Cc: emacs-orgmode@gnu.org Subject: Re: [BUG] org-capture-kill: doesn't remove the right text region In-Reply-To: References: Date: Sun, 24 Jul 2022 14:21:59 +0800 Message-ID: <874jz7rpx4.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=yantar92@gmail.com; helo=mail-pf1-x42d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, T_SCC_BODY_TEXT_LINE=-0.01 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" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1658643740; 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:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=JwQ7P6FA/nGifvnYZj4zHDK3TefVry4WoN8Qy4Kb/II=; b=RmOYnGy7pgA8tmhFYOe0Z1HblsZ72+pQTC0Ui4kW8GOf4DEG+dupHIIt0xv8dVEiTpLRQQ vc9hqKbXiOZZVe6t0aTTlM5KBD9+7yiRMsVRe1xUJTwdEl3BKnwfwLuKTLaLOAMj3JaFPz 7Ye/yw4nKT8kccm2evWaCtY1I5euudsq/8D0YsNc8vwnibAuKYsVCqJlaAMXfcdwOSM2iV X9SAZdWkpAT5KEAwF5MnB38Xk5OrtC+hLGUr14XiqK1Eh4iKhu8Wojhc8KJV01WGwnENq1 I9LFZAFI+0K4moorRWmARl6sGgpD9zvRjWqb+M975mjiVDb16hWKl3KCjGWu/g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1658643740; a=rsa-sha256; cv=none; b=IruqVBu/1O2ftpBolbvfg3+fv//xVQ//cxTVjLMZ3eYwX4ERbuQjoCYE+xGBKgokeePikX hzxWpDTlQg5djCIBB/kYivVUruz0tbBZ4BOgtXhDKZ5gcMn+3yxHk+5oeP19f57ICtuV+V XzQdTZNjza6ZGcpewPZi/FDyJsgR9VxjEcj3EIhEPkXknF52GJAU6aRUk7ViqHiib4J2im FMjSQDvWYOGFzFXe7fsFOXj3fAI/tbH9pE/5Yklfw41PGtVRWbHLMUFzSZQ3AzFl7BV6LU pOK/oN/dBaGm0TKHO0VIRnRWpjU0LGPeefEgiNgUwcxJ8evts5O2xuoAUJ9IUw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=RwIn6Srv; dmarc=pass (policy=none) header.from=gmail.com; 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" X-Migadu-Spam-Score: -3.73 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=RwIn6Srv; dmarc=pass (policy=none) header.from=gmail.com; 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" X-Migadu-Queue-Id: B12831A5F1 X-Spam-Score: -3.73 X-Migadu-Scanner: scn0.migadu.com X-TUID: TWmMfyUk7llr --=-=-= Content-Type: text/plain Caleb Chase writes: > I discovered a bug with org-capture and org-capture kill when > canceling an item or plain type template on a heading that has only an > empty line for content. Minimal reproduction is as follows: The fix is attached. The reason why this bug is happening is `org-capture-empty-lines-before` adding/removing the lines before the capture region. This situation was not considered by org-capture. Note that `org-capture-empty-lines-before` changes are not going to be restored upon capture abortion. Fixing this will not be trivial (AFAIU, suggestions are welcome) and the gains are marginal - I doubt that anyone is going to care much about this side effect. Of course, feel free to disagree by replying. Best, Ihor --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-org-capture-kill-Fix-capture-boundaries-when-deletin.patch >From 66c3f8c6f54ec4a4aa4a3ca567e9c2ff5370246e Mon Sep 17 00:00:00 2001 Message-Id: <66c3f8c6f54ec4a4aa4a3ca567e9c2ff5370246e.1658643473.git.yantar92@gmail.com> From: Ihor Radchenko Date: Sun, 24 Jul 2022 14:14:58 +0800 Subject: [PATCH] org-capture-kill: Fix capture boundaries when deleting empty lines above * lisp/org-capture.el (org-capture-place-entry): (org-capture-place-item): (org-capture-place-table-line): (org-capture-place-plain-text): Store beginning of the capture region as marker. This will make the ORIGIN move if `org-capture-empty-lines-before` has to add/remove lines. Fixes https://orgmode.org/list/CAGyCDkPos+W_MEJffSZga83NsOLZx2XGTYEmSGQuHQvS-sNa8A@mail.gmail.com --- lisp/org-capture.el | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lisp/org-capture.el b/lisp/org-capture.el index 8748b7f84..6ca66835a 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -1178,7 +1178,7 @@ (defun org-capture-place-entry () ;; Make sure that last point is not folded. (org-fold-core-cycle-over-indirect-buffers (org-fold-region (max 1 (1- (point-max))) (point-max) nil)))) - (let ((origin (point))) + (let ((origin (point-marker))) (unless (bolp) (insert "\n")) (org-capture-empty-lines-before) (let ((beg (point))) @@ -1243,7 +1243,7 @@ (defun org-capture-place-item () (point)) beg))))))) ;; Insert template. - (let ((origin (point))) + (let ((origin (point-marker))) (unless (bolp) (insert "\n")) ;; When a new list is created, always obey to `:empty-lines' and ;; friends. @@ -1344,7 +1344,7 @@ (defun org-capture-place-table-line () ;; No table found. Create it with an empty header. (goto-char end) (unless (bolp) (insert "\n")) - (let ((origin (point))) + (let ((origin (point-marker))) (insert "| |\n|---|\n") (narrow-to-region origin (point)))) ;; In the current table, find the appropriate location for TEXT. @@ -1373,7 +1373,7 @@ (defun org-capture-place-table-line () (t (goto-char (org-table-end)))) ;; Insert text and position point according to template. - (let ((origin (point))) + (let ((origin (point-marker))) (unless (bolp) (insert "\n")) (let ((beg (point)) (end (save-excursion @@ -1405,7 +1405,7 @@ (defun org-capture-place-plain-text () (t ;; Beginning or end of file. (goto-char (if (org-capture-get :prepend) (point-min) (point-max))))) - (let ((origin (point))) + (let ((origin (point-marker))) (unless (bolp) (insert "\n")) (org-capture-empty-lines-before) (org-capture-position-for-last-stored (point)) -- 2.35.1 --=-=-=--