From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.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 ID8XB+86qGLqhgAAbAwnHQ (envelope-from ) for ; Tue, 14 Jun 2022 09:38:23 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id cAgXB+86qGL1MwAA9RJhRA (envelope-from ) for ; Tue, 14 Jun 2022 09:38:23 +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 2AD593E3AA for ; Tue, 14 Jun 2022 09:38:18 +0200 (CEST) Received: from localhost ([::1]:49054 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o117x-0007nQ-11 for larch@yhetil.org; Tue, 14 Jun 2022 03:38:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51976) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o117R-0007nH-3j for emacs-orgmode@gnu.org; Tue, 14 Jun 2022 03:37:45 -0400 Received: from mail-db3eur04olkn080b.outbound.protection.outlook.com ([2a01:111:f400:fe0c::80b]:5774 helo=EUR04-DB3-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o117O-0005gP-Ky for emacs-orgmode@gnu.org; Tue, 14 Jun 2022 03:37:44 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hadElmO4KrRckFtQroIInrGQfgI8soB0F9/3LUvI81jJKgU+YUohqgXq9CnnIiOIR5c445fI1gyf1PiZGYKYgA6vautlKJL87t5z9hO177JYPSvKGkDnUDAq0beYIRQ5vw8ipb4d7ampbzrtxKy6uAfs7psRifrmISQw+ZxZYHJrKY+Bu/TrmH1iX8O4mjhcZh0fyfNmoAQ592jw1w+gGH2j9lNl5LRLH/dfSP3mQ/MHpBDPdj7iW1FLqwUgjbf7gf2BQbL/mcATRitprRETW75b9RqGeJEhYhu+gx8l+ll2hET4EuoOLfSt4qwNdkzuOolUnYA1wzpjN1HTouanXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=R0Vz9Er/QTOZdHq7vdIxVUsVavHuBS+wmrDUZCjHzA0=; b=lX1yO246Cg38US/M9mcphxbTB1BbEycWK07NAxFosbBPsLD2J8EzCJdoqCNaJK6k+Q+Peh89WQgg0e9qzPuwc1IyhR9azTJs/OY6LfhSfdhPl+CMGOtK9KlEG8xImuJaIqx7Q8B3ZCRAKlAFvJ8x4qMHzJ3jU0hJZDdEgKmh2FEJh3ZA8m8Z1sA95ggUdOdPXV+O3T9fOu9SpHePEUoSm/dOcnlSIa2XkTaPu9z2zHRwXBDnKSPEdswVYgjJfJRcdYlmqMfjKiPzRr5IXbov4krSojrZ0kzfKAUMGsq0jeIfEor394xnvAFhnc4kMh1yvxUaZSE9YZG7Ejz+0EMOyw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=R0Vz9Er/QTOZdHq7vdIxVUsVavHuBS+wmrDUZCjHzA0=; b=P4xarsv5Z4r7Usq2QIAd4sTxNeT5SZcL+3hAb/RbfE9/rTkhadCCA2bA3NKLU16VNRq8X7QScSsdTqHFPF+JdmZ+5bzKtHIujkxvdFqqLeXZsnVLcxf5MP6ODXabNIlolyK316gq8GDhbY0IuJ0gckg3jr8PM1x8ZputhAl2Imbpi56DIEH9k+lkIgNP5yBbAiuNTrZVRyM3X+2rSO0vqygXQEF6RKhRz6lREaE/7Y7AoibaJ9Jfy8JUc4tmwSSWP6IiVWsY4L8+pYTk0Y1mCgi3RyV7NMLk3lYUYAa3I50dk9Wvs9g2OJ++mYOdnMBnarhMvJMAvd7Oi8Q5qZfaJQ== Received: from DB6PR0601MB2087.eurprd06.prod.outlook.com (2603:10a6:4:4f::26) by PAXPR06MB8390.eurprd06.prod.outlook.com (2603:10a6:102:227::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5227.22; Tue, 14 Jun 2022 07:32:38 +0000 Received: from DB6PR0601MB2087.eurprd06.prod.outlook.com ([fe80::cdbe:e542:a1b6:1a2]) by DB6PR0601MB2087.eurprd06.prod.outlook.com ([fe80::cdbe:e542:a1b6:1a2%2]) with mapi id 15.20.5332.022; Tue, 14 Jun 2022 07:32:38 +0000 References: <875yl7d52o.fsf@localhost> <87mtefq3nx.fsf@localhost> User-agent: mu4e 1.6.10; emacs 27.2 From: Ignacio Casso To: Ihor Radchenko Cc: emacs-orgmode@gnu.org Subject: Re: [BUG] org-copy-subtree in a file with local variables marks buffer as modified [9.5.3 (release_9.5.3-6-gef41f3 @ /home/ignacio/repos/emacs/lisp/org/)] Date: Tue, 14 Jun 2022 09:21:50 +0200 In-reply-to: <87mtefq3nx.fsf@localhost> Message-ID: Content-Type: multipart/mixed; boundary="=-=-=" X-TMN: [3zPMKbd/QfmNZpIZmbkF1NJ71QfXrSnn] X-ClientProxiedBy: PR0P264CA0284.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:1::32) To DB6PR0601MB2087.eurprd06.prod.outlook.com (2603:10a6:4:4f::26) X-Microsoft-Original-Message-ID: <87bkuvk8ds.fsf@hotmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 95fc6865-72e1-41b9-33ed-08da4dd80e41 X-MS-TrafficTypeDiagnostic: PAXPR06MB8390:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MhMFW983bvUWFuRCilCc0IxY2MpzedcjwSKaSCHDRERgiB2kAm/29I8UGs4IBOao3Jg/pgoz3gNfPp0illDtkUdjkyVHU8K0LmxLEywn1F9d0sBs4kXXG0fCm+RxJIgA9Kvn3KK83m8o7s9GWiMqsQgSt5RzxFbyE3suCX8V0urhGAE0B1yzUgP2lyS0ZZQxOsROod7pzEsFQXs0e23NvmeFMd6EVCucgmu5lwDiIPRfaoqT3yOLEu5ZjmFur9J5YyzLLyCpAuE1kx55k8n9TZ5lIRqQ8VAnToFBOIaBlLUXjVdgObHY/mYX+v6IxQP3FoYDK5HE0ceXI0XbUqAKvS0stlkHGdBa3/1ufcUrzbsQwtzc5cA/7wqvMlkLh2jEz3cm9tRYnHhJiWBJ/ljvF2TrdjrdTYvspemeo3dW2UjSKoVwD4ljWTTBn/IVsNMcM1xT9dFIVQ8go0X2TCVUpAVIji+YVOi4h+lDdXDdEQMshzLaaNEzMnn9OWWT80A+TBUqi7pgpFcyDVC0ssUnwPNzaOODhXKZvXbYmoFI4u5IxfhUFfob9mkTVZ2oiYPLldcqZfcSZDL2MttHSS4d6A== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?nYmjPuKe9EU2NlI4lG8ISGxour2wL/nSq7Z1zJ4fn3r0kd5XbNPaB/p6vSSI?= =?us-ascii?Q?zZy/njjZuu7aLDtyd4In2KMcgkjDJ/wMhBf6snqfI7ZyGxte/5BOR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bwuaehnpwjiAG5xoY7atYSrOKN4F14Nyd/Gc1cWVwbhtPhxC?= =?us-ascii?Q?nf/txadaGrHPkz5ibK9ugwcUhqm5N2UHkx0BqCFsN2U+WRqA3ehKwZ9upNui?= =?us-ascii?Q?tXqOt49g2uhm7sTfvHfEf2A0EWrNyMe78ysRK4ocK3MVquBLcM5HMSEBe4MV?= =?us-ascii?Q?ZM/+n5U4ITl+Kh/wkJ680vAH32IXNq91EVeDAghbLpJ/Yi+tSc9YO7M4xQQb?= =?us-ascii?Q?ZR7+R6NU+0c9pOYHU/umacjT/ByFHOR2WeBmMvlC/z0AMVKhbmT4BYkBlQUT?= =?us-ascii?Q?9lVmOoz6iGmrUDOI3iHSjp+CUO235VBsoRnqFO32ENzVUhuyd4LajvgDZozq?= =?us-ascii?Q?vzH96/KGOjLRMTuyCvNh8BLolu2Sfw05RVj5g/tuVwnCJ6unPMKHLXopHe+Q?= =?us-ascii?Q?WGQSEOhIV7PM0Mq15Up1o8A485TpW50dnBdA4WTEgpwY6U1//Yf6HwECiILL?= =?us-ascii?Q?oLpXdcr2wWk=3D?= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-6e454.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 95fc6865-72e1-41b9-33ed-08da4dd80e41 X-MS-Exchange-CrossTenant-AuthSource: DB6PR0601MB2087.eurprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jun 2022 07:32:37.9556 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR06MB8390 Received-SPF: pass client-ip=2a01:111:f400:fe0c::80b; envelope-from=ignaciocasso@hotmail.com; helo=EUR04-DB3-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_FROM=0.001, SPF_HELO_PASS=-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=2; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1655192298; 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=R0Vz9Er/QTOZdHq7vdIxVUsVavHuBS+wmrDUZCjHzA0=; b=O5x3r1hZyr1lQ4qqo9CUxeES+TKQ7Sp+vsm+AKTCeBUmhsHjuAg4rrPqgcGPeLYKAXX0mD 3bfI1BJ0LUp6TUMk93h7WoMBEntwSP7RQNS11Bo6BGVUf2S9edQD1QVOTdRMqQqHQe6rDi hHNZ28ux96G1VX4szya8uWdri7iuQv3cUXFYP+0MiuClGPUAz+7UtPRoZfLVLH61SAxcVA L7zUjl6SPfs0w1DAjMruEtv61ZVofKlFIJ+x03F/t3agQG8wwnYe6dSwbUHzoq3OUZYUCl 1S51Z8qiLh0UGgHO0H+F9L6lpNfRmuDMRF2sno6WYTrmbOwU9dQ4x5dKdx60VQ== ARC-Seal: i=2; s=key1; d=yhetil.org; t=1655192298; a=rsa-sha256; cv=pass; b=SM6Z0oy2wWwqlGF7x07NgP7+IEqkv+SeL58wC9RBFVb++/0L8rJG/4HVfRKrDoLZ2dCLNT tHwAJfCZj4dZkDIX8zTRsRD6ByAjIjbf0eP9EZZ+lk2Zr+1B6y7QBnNmFWqDxvYmfRy+xM a/9f+vKj/ePHyAAvp/k//eTO7OcGES+9y99KeE8Q/sLzcqRZO4nAZOQkNw+D1XOWrn8BsI X/LiFRZnEXBdTAPcfZm5wmyxvhNxzxoT/iZTXUSunPX7eSoMdyk/Hq8Ovg5W3Gwro6L//M TZ9jgCwK/QdeTMdq2Sj5L422sBj4v0B+2bdEpua+dImccAI6OlMpInZtd6NXlw== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=pass header.d=hotmail.com header.s=selector1 header.b=P4xarsv5; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=none) header.from=hotmail.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: -5.49 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=hotmail.com header.s=selector1 header.b=P4xarsv5; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=none) header.from=hotmail.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: 2AD593E3AA X-Spam-Score: -5.49 X-Migadu-Scanner: scn0.migadu.com X-TUID: LyHOUGEyyU2r --=-=-= Content-Type: text/plain >> - (delete-and-extract-region (point) (point-max))))))) >> + (undo-boundary) > >> + (setq buffer-undo-list >> + (seq-drop-while 'identity buffer-undo-list))))))) > > This looks fragile and can be disasterous when buffer-undo-list is > large. I agree that it is very fragile, but could you explain why is it also problematic with a large `buffer-undo-list'? I guess you mean efficiency-wise, but it would only iterate through the few items added since the call to (undo-boundary). Is there something else I'm not seeing? > Maybe just use with-silent-modifications or some ideas from there (for > example, wrapping modifications inside let-bound (buffer-undo-list t))? > We should not inhibit modification hooks though. Otherwise, it will mess > up with caching code. Done. I attach the new patch: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Do-not-mark-buffer-as-modified-with-org-preserve-loc.patch Content-Description: New patch using (let ((buffer-undo-list t)) ...) >From 54e05dc54fe7091f2d1c7e0c44e01cf5abeb4907 Mon Sep 17 00:00:00 2001 From: Ignacio Casso Date: Sun, 12 Jun 2022 10:38:53 +0200 Subject: [PATCH] Do not mark buffer as modified with org-preserve-local-variables * lisp/org-macs.el (org-preserve-local-variables): Do not mark buffer as modified or alter `buffer-undo-list' when body does not actually modify the buffer. This commit fixes a bug with `org-copy-subtree', which marked the buffer as modified and added an entry to the undo list when the visited file had local variables. --- lisp/org-macs.el | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lisp/org-macs.el b/lisp/org-macs.el index 19e5f42e9..c34ff3ab7 100644 --- a/lisp/org-macs.el +++ b/lisp/org-macs.el @@ -166,13 +166,19 @@ (and (re-search-backward "^[ \t]*# +Local Variables:" (max (- (point) 3000) 1) t) - (delete-and-extract-region (point) (point-max))))))) + (let ((buffer-undo-list t)) + (delete-and-extract-region (point) (point-max))))))) + (tick-counter-before (buffer-modified-tick))) (unwind-protect (progn ,@body) (when local-variables (org-with-wide-buffer (goto-char (point-max)) (unless (bolp) (insert "\n")) - (insert local-variables)))))) + (let ((modified (< tick-counter-before (buffer-modified-tick))) + (buffer-undo-list t)) + (insert local-variables) + (unless modified + (restore-buffer-modified-p nil)))))))) (defmacro org-no-popups (&rest body) "Suppress popup windows and evaluate BODY." -- 2.25.1 --=-=-=--