From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id CBIiCmwisGXXyQAAqHPOHw:P1 (envelope-from ) for ; Tue, 23 Jan 2024 21:32:44 +0100 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id CBIiCmwisGXXyQAAqHPOHw (envelope-from ) for ; Tue, 23 Jan 2024 21:32:44 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; 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" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1706041964; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=NNAUV08bBlGOGN/8YeT7EqfrCwtsUzb1c3Ekf3+e1U0=; b=tbam4zJQV0l4BAvTARqTa4KUgWrGMca8FlT84xHJehl65AzMN2HTW/rryjz08d5TXeBfvA kcwe+IxmuthKItLu+tDqkpd6+LPM7TYj5Tx2T7j+FNJi22kRJn/KNQhxdsOz8sAPmDnKyQ alqI75CQ0zq1nDS2hEU59EvuAPiXv4YNli9d7fOcgZgosMxXaWa2xEZn/i16E1dovSbWxb xnoG6T+hiJthFGeh/GRCzlF3oKN6ixLlIdQcgpq5A0woPagqL8oxHsrS2Gc/1y4MsDxwEK p+1GNAY6B1cBobjLPJS+NgKDX1H5z3qnwUzzGN+Au3fvNyLjdLglda9n0VH82g== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; 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" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1706041964; a=rsa-sha256; cv=none; b=aXhopJyl6gB8UhKjZsW7r5p66f/XIOimTKNjB/x9ZugZ7Xnqs1IUIVHvwOCi9tfxmMQrsL k91l/y+TL2Kn5gXzzDVfuTHwmZ7VH9xGNA3UkM/77IoiXNTnAvEeaicWMV8dyE6z3c/0vN WNdehBRmqu4JzTKwvy3oYzNXLCvs/EPKs90rtxb8k5p2Y/BoZoMml6CZkptvdC9NaAQwPs c8jwAt7ET+T+MPMn1Tud74IzEd+xYD1LOONWE6aKQ7K4k9yoltQgHOqPXVuH6s7ISQ0GbZ QwZ1PTOd1jtyHcubpBRKYEL7MQGjj7TRBGyW72LAVg9uEKwCSfok2XmHzV1G0A== 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 DF779186CA for ; Tue, 23 Jan 2024 21:32:43 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rSNRA-0003C1-BK; Tue, 23 Jan 2024 15:32:00 -0500 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 1rSNR8-0003Ba-9a for emacs-orgmode@gnu.org; Tue, 23 Jan 2024 15:31:58 -0500 Received: from mxout012.mail.hostpoint.ch ([2a00:d70:0:e::312]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rSNR5-0006TZ-Fq for emacs-orgmode@gnu.org; Tue, 23 Jan 2024 15:31:58 -0500 Received: from [10.0.2.45] (helo=asmtp012.mail.hostpoint.ch) by mxout012.mail.hostpoint.ch with esmtps (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.97.1 (FreeBSD)) (envelope-from ) id 1rSNQz-0000000062w-26MW for emacs-orgmode@gnu.org; Tue, 23 Jan 2024 21:31:49 +0100 Received: from bbcs-114-103.pub.wingo.ch ([144.2.114.103] helo=BERGAMOTTE) by asmtp012.mail.hostpoint.ch with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.97.1 (FreeBSD)) (envelope-from ) id 1rSNQz-00000000EKO-112J for emacs-orgmode@gnu.org; Tue, 23 Jan 2024 21:31:49 +0100 X-Authenticated-Sender-Id: olivier.lischer@liolin.ch User-agent: mu4e 1.10.8; emacs 29.1 From: Olivier Lischer To: emacs-orgmode@gnu.org Subject: [PATCH] ob-tangle: Add flag to optionally remove files before writing Date: Tue, 23 Jan 2024 21:25:11 +0100 Message-ID: <877cjzhjtg.fsf@liolin.ch> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Vs-State: 0 Received-SPF: pass client-ip=2a00:d70:0:e::312; envelope-from=olivier.lischer@liolin.ch; helo=mxout012.mail.hostpoint.ch X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, 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-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -6.77 X-Spam-Score: -6.77 X-Migadu-Queue-Id: DF779186CA X-Migadu-Scanner: mx12.migadu.com X-TUID: bItay97UkEyz --=-=-= Content-Type: text/plain In December last year was a change introduced, that a file should not be removed before tangling (https://lists.gnu.org/r/emacs-orgmode/2021-05/msg00337.html). In an older bug report (https://lists.gnu.org/r/emacs-orgmode/2021-05/msg00337.html) the decision was to remove the file before writing. I added a variable to switch between both behaviors. Any feedback or advice is welcome. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-ob-tangle-Add-flag-to-optionally-remove-files-before.patch >From 4f2f2a0dcca82a934144636da478a9243e514f66 Mon Sep 17 00:00:00 2001 From: Olivier Lischer Date: Tue, 23 Jan 2024 21:02:20 +0100 Subject: [PATCH] ob-tangle: Add flag to optionally remove files before writing * lisp/ob-tangle.el: Add variable `org-babel-tangle-remove-file-before-write'. (org-babel-tangle): Remove file before writing when `org-babel-tangle-remove-file-before-write' is set. The variable `org-babel-tangle-remove-file-before-write' adds support for the current and old behaviour of `org-babel-tangle'. TINYCHANGE --- etc/ORG-NEWS | 4 ++++ lisp/ob-tangle.el | 12 +++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index f537486d4..c7c3ee264 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -800,6 +800,10 @@ Completion is enabled for links to man pages added using ~org-insert-link~: =C-c C-l man RET emacscl TAB= to get =emacsclient=. Of course, the ~ol-man~ library should be loaded first. +*** =ob-tangle.el=: Add flag to optionally remove files before writing + +When ~org-babel-tangle-remove-file-before-write~ is set to ~t~ the file is removed before writing. + ** New functions and changes in function arguments *** New API functions to store data within ~org-element-cache~ diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el index 72089a9a5..37fcd194c 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -166,6 +166,12 @@ read-write permissions for the user, read-only for everyone else." :package-version '(Org . "9.6") :type 'integer) +(defcustom org-babel-tangle-remove-file-before-write nil + "Prevents the deletion of an existing file before tangle" + :group 'org-babel-tangle + :package-version '(Org . "9.7") + :type 'boolean) + (defun org-babel-find-file-noselect-refresh (file) "Find file ensuring that the latest changes on disk are represented in the file." @@ -313,9 +319,9 @@ matching a regular expression." (compare-buffer-substrings nil nil nil tangle-buf nil nil))))))) - ;; We do not erase, but overwrite previous file - ;; to preserve any existing symlinks. - (write-region nil nil file-name) + (when (and (file-exists-p file-name) org-babel-tangle-remove-file-before-write) + (delete-file file-name)) + (write-region nil nil file-name) (mapc (lambda (mode) (set-file-modes file-name mode)) modes)) (push file-name path-collector)))))) (if (equal arg '(4)) -- 2.43.0 --=-=-=--