From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id +MZoFIitpWIdCwAAbAwnHQ (envelope-from ) for ; Sun, 12 Jun 2022 11:10:32 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id mNZoFIitpWJ2iAAA9RJhRA (envelope-from ) for ; Sun, 12 Jun 2022 11:10:32 +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 DF294BA87 for ; Sun, 12 Jun 2022 11:10:31 +0200 (CEST) Received: from localhost ([::1]:46044 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o0Jc7-0002ui-17 for larch@yhetil.org; Sun, 12 Jun 2022 05:10:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48480) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0JYU-0002qu-MX for emacs-orgmode@gnu.org; Sun, 12 Jun 2022 05:06:48 -0400 Received: from mail-vi1eur05acsn20809.outbound.protection.outlook.com ([2a01:111:f400:7d00::809]:24289 helo=EUR05-VI1-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 1o0JYS-00072A-9w for emacs-orgmode@gnu.org; Sun, 12 Jun 2022 05:06:46 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G5bbh5KqxuYq+AeOTTVUU1E5uCrbm6SSdnZWxQjwgOmHX4Q8Jbe/JkAqx2rSE4HKQaR2sADyvHxZUnUBhH1mJRWtmmZAm5eUmlmL2sSMlJUzu+KOIS1EnsikyYPU+M/vcNW1sFfoFWh7n1uiYD3/E4b1TsZLxUWtkuCJvp+z9m5KT0YCIHxfppsZ8xoSjBleA1ym0bZfGksKcjf48ptR3coiuMJmyPc6PvGCE+DUdMrC4DsEJ9xYNEdULOw4UdYIMJSQhq6AHCfLl2gI/st5n7d2M4B5O0psB+1ZpDxR0xavoMkdKoSlwYDeu5pifjFpM7r171eJwH9BnbMVb5yObQ== 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=+V96D0/0oUHQYNELUREGjWzNadMsscIe1FJ0et1C8Rk=; b=TD+k7SQoxQkbzAbOH7AIeJ6ikFqUC9xHhOaIQ7nK0Zj3G7mnCc77Hmd3/SEm3gm9ym5CR+R2OiBMD0uCTng+y4b9bSx0MC8ghcXa4ntGHiJ1l+aoxPoIG1ScL0dS7JmGjJqR5QHi3acBmrI5O4VkKhaxpBAbyDzET1XSeO4WjCNltGw0YlDLsQhZW9f6VFSvbPOl1lKRgf5nm3wZg8K+zaDcq8EqntfJs5+fQEo9nIH5UAUFIMaPXpdIDjcL/Lmg2qzJGdfgNKNyWdWOkwKml64X+bnYPWA4vj4psvNZmn000LBRtv9947xONaheMQEzLxHoBpzrfEqwf7/EvnUDUQ== 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=+V96D0/0oUHQYNELUREGjWzNadMsscIe1FJ0et1C8Rk=; b=J5Yf2H/iXzHnOqIikDguUkdKLqkVFU8Q1rvqNmraXcYnnCYY+wfiWqulLt9zvY9KlPfXcN7zxWX3bI+Oox79rcBWWL9bGAiU/zG3TnmEMvwmIO7MDWDE7a3YCNgRSjOMtYVqxxA22PbkPnGIVfFEyjpR+3xWXlspo0LlDrcqluK9sanBLDD7k4SB1f8yPZrxtPBi8vSGgcUDFx8NZ5cMMLCdstwuDwWZvcGi4n00EVC2qxRuJIED0aiHC9CcpEU1zp6UFYYVV9SiqnHl5Nlo1s/Mw4kbMV/gMv685Rw/P4Dux9BR7dfgxsn2SUGzF4fwcsKswXweWT3PmTetH/4OBQ== Received: from AM4PR0601MB2081.eurprd06.prod.outlook.com (2603:10a6:200:52::27) by DB7PR06MB4155.eurprd06.prod.outlook.com (2603:10a6:5:2c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.16; Sun, 12 Jun 2022 09:01:38 +0000 Received: from AM4PR0601MB2081.eurprd06.prod.outlook.com ([fe80::3144:2c73:fd21:1600]) by AM4PR0601MB2081.eurprd06.prod.outlook.com ([fe80::3144:2c73:fd21:1600%8]) with mapi id 15.20.5332.019; Sun, 12 Jun 2022 09:01:38 +0000 References: <875yl7d52o.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: Sun, 12 Jun 2022 10:53:16 +0200 In-reply-to: <875yl7d52o.fsf@localhost> Message-ID: Content-Type: multipart/mixed; boundary="=-=-=" X-TMN: [r6mOo1AiTEoRWt7wW/kfTAwjWtxfJI3Y] X-ClientProxiedBy: PR0P264CA0275.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:1::23) To AM4PR0601MB2081.eurprd06.prod.outlook.com (2603:10a6:200:52::27) X-Microsoft-Original-Message-ID: <87pmjefe6u.fsf@hotmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0de4e84a-6dab-4507-118e-08da4c5226e4 X-MS-TrafficTypeDiagnostic: DB7PR06MB4155:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gvXI05CnWh/0O+JFaVqyqMOj9DNlu25caDEFbZegNkeceohblX76ETRYorG2TrNgmU6G8GiCppzABEA56Pcr7p1UkzPJgQt229JQ7wClne74jPhxc9EU/KxOVSWZ5euO1IiC8fTYXYUTIGrT72bebCY6/011cEqeSlUyxF/V7xwvAZXbBlE+gN09r8Z2g/wyXtULa4xfeH6XayX0tYLu5UgI8JfvvFxNt3sNil0CLgi7f4Lpfg0+UI1kw/V8gZSGBoaaZQ9f28edwio3FhAmNPgFt9VdieFp3Sr5MslMkKffD4rGIG2l8ZwlZXJXy0fWBU4Au91rC7PweFQnSXXY9r/CgfWjPZD6rWTa0I/oZJUFzmdNdaqMqqjUepJnewt7aFsQtnJSEocEoURDm50O4tPedL8EjkeigIJINxLWs1PDCkNb+ArJvUqJtcFPsFuGlGb6qL9sXu4r4+vdCbQTvSKrzeBxoW6CPVN9Cmqi5YbF9M9poEjJQ2B/9sjx12FSECXe8yzotQ5MnX1Cylg51gVbPdJPRV2WjjQawSbLmhiX9+n6VRmcC4GJqJNUjgX0BKCcuImNV3SRR7sKrByRhw== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?OBJ7cPcfhjeAx1JN3ktLnWf490DPQ/B5MxrEOlCaJnMiouRS9X+98xirjwi/?= =?us-ascii?Q?opwdlrouI6WbDkf60Qz5PDJzjQOxzTsbgiu5w3lRFK3srSBUtJjyNF/D/6sR?= =?us-ascii?Q?B3zd3fqsJqt6KNl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bXJ?= =?us-ascii?Q?ECYUfZh9A+qGZmgHEDebgLMuRSCwUV+Wj3B7chuId2bThX51T1f+f9JSn6qi?= =?us-ascii?Q?ZVOjlrFT1WgXEWsSmcAjsY0zhnrGD7leiyOXvIi79+hxsrHDB/78xmKo2sb7?= =?us-ascii?Q?Vm1pWoFnXSSd1cZIdNNCbkxCYBSFUskZsfC+hcEVA+R2el8fSlzSJCdp6xLP?= =?us-ascii?Q?XxyJSTu/m2Ffdkm3tJ1ldr8WlvVB7B9oR8oasPxwNLNSh0qqTP5ZAlQlKy4F?= =?us-ascii?Q?aFuBBKA50St1K/5foAVD8RSqG73YFxctxjNZRStm69TdCGFMRH5CHLCL81EM?= =?us-ascii?Q?fB48WooPB/8ske1NLbBwF0e/6trDH6nDVSAZbAoyrUWt9zLxqpLUcqkfVa1F?= =?us-ascii?Q?SZh5N4Gb4RuIayEuZPZOP3dF5w+Gb4FHWhY7ulx1un58hdnY+cBmsUuTKeQo?= =?us-ascii?Q?3bU4Fy99SGI=3D?= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-6e454.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 0de4e84a-6dab-4507-118e-08da4c5226e4 X-MS-Exchange-CrossTenant-AuthSource: AM4PR0601MB2081.eurprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jun 2022 09:01:38.6105 (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: DB7PR06MB4155 Received-SPF: pass client-ip=2a01:111:f400:7d00::809; envelope-from=ignaciocasso@hotmail.com; helo=EUR05-VI1-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, RCVD_IN_DNSWL_NONE=-0.0001, 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=1655025032; 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=+V96D0/0oUHQYNELUREGjWzNadMsscIe1FJ0et1C8Rk=; b=UgljQ03BOq9CiDlnL0/fSezlEbEAOAguv2/eTVnTaiuWuLwedYjlKKgifIHStofXPGMJ4C Iu92lqWnPPsq5orRsx8/jr7uf0KNglx8R9psV3sro2pOBC3KmhPtKx+Qjgk+3glgeMJiAd rwrbW7AfiKlJFXJ/EooUkvVQiR/xqG2XFlRWXtHtQjE7VNFW8rCazrl35BpNIl9aSAqJ/N kc1ZNvvDbyc2mRhh16hixIAKZXenH0iluf3qNrCvExWS08gVYJ5Jx2dlNOz0Xl2MvF07eC ZTymefCVKbPNQ2KmkqWwiidoyANA8gUNRbCVJC318I7+sm1rhqf96IP6dkqJIQ== ARC-Seal: i=2; s=key1; d=yhetil.org; t=1655025032; a=rsa-sha256; cv=pass; b=kkp0f2xiD+o2S1mL++5bxAdKJPzHznzhFUPs8tKJDRTvIjt4W5VV+u/S7G+EJsh0mVIVv9 Ow9XHLvhVOVj3O7FoqXzjGIpoDDn0m9nvkwq2xlX/mFVWcoqtFHPHzHuApi1geJ+uYAgRR GkDozTA8r/A8hgPhhs3PyRT1rnyPFeyfLen6UwRxmrXHxCzdg99VuBLRvzKXYxI2apma39 4aO1/xNZJ39mrCq3gMtFBmnlcQyd1/WrCzzWKrw89qK44P0wfUGPqWB4dTE8YQXYzW5xrG SW+vLykOURdqEeTUKLKs9IB0beglBDw44RiJCcXDXUI95x3mgEIAcrdAuKYCCQ== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=pass header.d=hotmail.com header.s=selector1 header.b="J5Yf2H/i"; 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: -8.49 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=hotmail.com header.s=selector1 header.b="J5Yf2H/i"; 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: DF294BA87 X-Spam-Score: -8.49 X-Migadu-Scanner: scn0.migadu.com X-TUID: dGjOSCOwTHCe --=-=-= Content-Type: text/plain > buffer-modified-p is not the only parameter affected by juggling around > the local variables. There will be undo history, > buffer-chars-modified-tick, before/after-change-hooks triggered by > `org-preserve-local-variables', etc. > > However, I do not see any obvious way how your proposed change can > negatively affect all the above. Feel free to propose a patch. I've written a patch proposal. It deals with buffer-modified-p and undo history, but not the other two points you mention. I have tested it and it works, but I had never dealt before with `buffer-undo-list' so maybe there are some cases that I have not considered and for which this patch could be problematic. Let me know what you think: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Do-not-mark-buffer-as-modified-with-org-preserve-loc.patch Content-Description: patch >From 14506bea13bf6278d95825257d90bbc3390ae8f1 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 | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lisp/org-macs.el b/lisp/org-macs.el index 19e5f42e9..64beeff53 100644 --- a/lisp/org-macs.el +++ b/lisp/org-macs.el @@ -163,16 +163,24 @@ (org-with-wide-buffer (goto-char (point-max)) (let ((case-fold-search t)) - (and (re-search-backward "^[ \t]*# +Local Variables:" + (when (re-search-backward "^[ \t]*# +Local Variables:" (max (- (point) 3000) 1) t) - (delete-and-extract-region (point) (point-max))))))) + (undo-boundary) + (delete-and-extract-region (point) (point-max)))))) + (tick-counter (buffer-modified-tick)) + modified) (unwind-protect (progn ,@body) (when local-variables + (setq modified (< tick-counter (buffer-modified-tick))) (org-with-wide-buffer (goto-char (point-max)) (unless (bolp) (insert "\n")) - (insert local-variables)))))) + (insert local-variables)) + (unless modified + (set-buffer-modified-p nil) + (setq buffer-undo-list + (seq-drop-while 'identity buffer-undo-list))))))) (defmacro org-no-popups (&rest body) "Suppress popup windows and evaluate BODY." -- 2.25.1 --=-=-=--