From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.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 sM/WIXLvt2UwRQAA62LTzQ:P1 (envelope-from ) for ; Mon, 29 Jan 2024 19:33:22 +0100 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id sM/WIXLvt2UwRQAA62LTzQ (envelope-from ) for ; Mon, 29 Jan 2024 19:33:22 +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=1706553202; 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; bh=Bun+4evZEu2CzrEeuKAUPZH7az7JRi4XrTCUw59zGDI=; b=HCVtJpYk0FIvQeC+fkDE7LnSEkH/pWoMf1onKVDpSFjLsi4TTdKHlVSe1Vd+0XHg0vlVQ1 lQxEome3K1Gn8dNNKtu/2AfAoZmVzh1HlBkfuOnFD6f+futBx993W8t+zcLnC1l+ruBNkO 4pLoYEtSbkxaw6SyHh+QZ/Xi7F9Piam/i9yb7PQ/VG0wrkfMn7JRz2oqVvBnmsgm+N6Vp/ jaYje2DoCjBQkgfTYMU3GinZMrriNES4dKwy9wN6ZYm7+KXDbE6iJumM1yLo+/WVCmHIJX 5FT3LuMIEsN4Aj9pZj23odGfSKCf8X7slxSeX7W1oFLQ5Mkl10inwr19GJCQmg== 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=1706553202; a=rsa-sha256; cv=none; b=VVunn2RieW3bsz1f5ep4pSQqR+Frv/0zvaV82HqRrEL9Qoi5LCxzDTkmqF3PPEdeMp0sp7 sWk4GhlhAzfgLWkdUNNTxTSSD7vJ6ZXRPMtrFTnNthcE6Kxl4sdTWJb5NMRkP9TkIl0Uvo 6T2c3bS14wGkcmY0aR5Rbp6xIMtutm3J5R6AORIdFT97aWDPzFw6yy0DkYfADq/+iW87no eUYVy+EMeoaopNQ8wuchWYQVr9eZ1N6VmWSMPVwBTrlByhWQtJrcYrZmZaATAVA4hFx1V5 Xqx3gTHHSqYXWAUTxI6+VrTCdJhp7X1tb7zOsDsYRQvU+Lsr9p+gh7k15vvoAA== 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 325EA26D0A for ; Mon, 29 Jan 2024 19:33:22 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rUWR4-0005uT-15; Mon, 29 Jan 2024 13:32:46 -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 1rUWR0-0005u0-EZ for emacs-orgmode@gnu.org; Mon, 29 Jan 2024 13:32:43 -0500 Received: from mxout014.mail.hostpoint.ch ([2a00:d70:0:e::314]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rUWQy-00021F-BC for emacs-orgmode@gnu.org; Mon, 29 Jan 2024 13:32:42 -0500 Received: from [10.0.2.46] (helo=asmtp013.mail.hostpoint.ch) by mxout014.mail.hostpoint.ch with esmtps (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.97.1 (FreeBSD)) (envelope-from ) id 1rUWQp-00000000Pnm-3rnU; Mon, 29 Jan 2024 19:32:31 +0100 Received: from [2a02:21b4:c40c:1000:141c:e41c:22be:2fe4] (helo=BERGAMOTTE) by asmtp013.mail.hostpoint.ch with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.97.1 (FreeBSD)) (envelope-from ) id 1rUWQp-000000005Lr-2q12; Mon, 29 Jan 2024 19:32:31 +0100 X-Authenticated-Sender-Id: olivier.lischer@liolin.ch References: <877cjzhjtg.fsf@liolin.ch> <87wmryelfo.fsf@localhost> <878r49i78e.fsf@liolin.ch> <87le89qi2c.fsf@localhost> User-agent: mu4e 1.10.8; emacs 29.1 From: Olivier Lischer To: Ihor Radchenko Cc: emacs-orgmode@gnu.org Subject: Re: [PATCH] ob-tangle: Add flag to optionally remove files before writing Date: Mon, 29 Jan 2024 19:32:33 +0100 In-reply-to: <87le89qi2c.fsf@localhost> Message-ID: <87y1c8dm65.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::314; envelope-from=olivier.lischer@liolin.ch; helo=mxout014.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.76 X-Spam-Score: -6.76 X-Migadu-Queue-Id: 325EA26D0A X-Migadu-Scanner: mx12.migadu.com X-TUID: xhJtUvow+7r9 --=-=-= Content-Type: text/plain Ihor Radchenko writes: > Olivier Lischer writes: > >>> Thanks for the patch, but may you please explain why introducing such >>> variable is useful? >> >> Sure. >> >> I configure all my .dotfiles in an Org mode file and tangle the >> configuration in the right places. The tangled files are all >> read-only to prevent accidentally editing of the "right" configuration >> file. With the current tangling mechanism, this results in a "Permission >> denied" error because the function writes to a read-only file. In a >> earlier version this use case was possible because the file was >> recreated before writing to it. > > Thanks for the explanation! > > I suggest changing your patch, setting the default value of > `org-babel-tangle-remove-file-before-write' to 'auto. > This will keep the current behaviour but fall back to delete + write new > file when the tangle target is read-only. > That will avoid feature regression. I changed the path as you proposed. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-ob-tangle-Add-flag-to-optionally-remove-files-before.patch >From a464592f622ba42732a5449d2c4db51f1975444a 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 | 14 ++++++++++---- 2 files changed, 14 insertions(+), 4 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..64b7c2cf8 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -141,7 +141,7 @@ controlled by the :comments header argument." :version "24.1" :type 'string) -(defcustom org-babel-tangle-uncomment-comments nil +(defcustom org-babel-tangle-uncomment-comments 'auto "Inhibits automatic commenting and addition of trailing newline of tangle comments. Use `org-babel-tangle-comment-format-beg' and `org-babel-tangle-comment-format-end' to customize the format @@ -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 --=-=-=--