From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:1008:1e59::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id SA+qFxEcnGVQbgEAkFu2QA (envelope-from ) for ; Mon, 08 Jan 2024 17:00:17 +0100 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id 6JgNEhEcnGVQbwAA62LTzQ (envelope-from ) for ; Mon, 08 Jan 2024 17:00:17 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=ZKkoO+fn; 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"; dmarc=pass (policy=none) header.from=posteo.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1704729617; 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:dkim-signature; bh=CeD4GKTiNwry2U5WSgQuqlhFQF+uNp2GkwW+3KG8iFg=; b=rRfIzyXMF/lyJPWg7D88BnDgpXDRdaeEpGxyseMkwv9nmeFiD73ZmKLl6XOmXKcZixVgrG uXcLnexYFEdQ+aStT0wQkQs7A7UeC+LCNNNGxOWhEAqnUQX7aWeudLT22FQVTxur/mUs0Y ainR1yE53cKuMdAoxsP9MmjResO+KmmsdbyZV77FZ0FO6bGDNALH0r/D8s4YxwIrOWSQJ/ B0iHnVGAxMIMwGhYaX8MyfIMm7ve4FhVrL8L+EXWglieX8FO+2PVGAXRitqtH+GGhXLA/J jbwUOutNeqWJRX1dHYRQWA5JCasINXzb3QgB/8xmtUNU0LDP7EtUajUB5pHeUg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1704729617; a=rsa-sha256; cv=none; b=mxwUknA3gDkvovPfDMtj6U5kplzD1aGEQH+WZKBpMboy3EL9alTeHDMTozItPsyXXRqiKO r4fETnYgFWEdiTnaB+y/ja2Kaw3KiZcl6eHahbtNqn3kKFmCf8VeJOtpsZIMtXHffNVumo BmGj37DML3G3CZNk9QHoFBK4Svw8ZyHyYWy+keOjnogyT3tGq3o+e6mTWeSR6VASk84Dzr PQYlU2CPxQ3LVFwelGrDtzurSFBvGRyPonvH41wdR3YftfgfI+lDnfTFJyayFfT+RyuS7D DJbRx5sSRENyUwskhMYq85v5kIDxG9RGNT0Fmof1ltoYxbHPkauxzd2UgR5Lrw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=ZKkoO+fn; 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"; dmarc=pass (policy=none) header.from=posteo.net 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 0357A580F2 for ; Mon, 8 Jan 2024 17:00:16 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rMs1v-0002vm-Jj; Mon, 08 Jan 2024 10:59:11 -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 1rMs1q-0002vW-So for emacs-orgmode@gnu.org; Mon, 08 Jan 2024 10:59:07 -0500 Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rMs1l-0002o0-6a for emacs-orgmode@gnu.org; Mon, 08 Jan 2024 10:59:04 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 09EA5240101 for ; Mon, 8 Jan 2024 16:58:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1704729539; bh=JfNJ0BgqZUblwyRSWMpM4/aRnssl55SlbOjfeJ3znRg=; h=From:To:Subject:Date:Message-ID:MIME-Version:From; b=ZKkoO+fnpV12E11wMcdGO0U+4/4aK8tOPAj5NVkygE9CKESQapTD2o/TvFrBXRRnb 9zPtbFYrwyKdphR8/huYttJZ2EQSP9cUnbooUqos5fqzzr0niuRygYv51fMwJIZGQd gxSpmttlQdfqztnaZM4LpU5bS+HakgDgTqbhy7PTHlKw/YR/jEHBkKhW9rXN2HLQCx 4MsXRQdesHn5jPqucrxw0EQExjScnSttlT41rFHfEG5hsO7hDFxN1n0hFuhvieIhq6 MJlLr4b++KJY1nFxYEMP9X8NVQ3EFLdq1qlSVORMNJU2Wth6Ud1ikXBIOjkHzqqfY7 5I13ZUaTm+LzQ== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4T7zJL1tybz6tvb for ; Mon, 8 Jan 2024 16:58:58 +0100 (CET) From: Ihor Radchenko To: emacs-orgmode@gnu.org Subject: [PATCH] org-babel-tangle: Do not allow tangling into self Date: Mon, 08 Jan 2024 16:02:11 +0000 Message-ID: <87le8zyfss.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.66; envelope-from=yantar92@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -9.50 X-Spam-Score: -9.50 X-Migadu-Queue-Id: 0357A580F2 X-Migadu-Scanner: mx11.migadu.com X-TUID: 145CF2uoHTZD --=-=-= Content-Type: text/plain Hello, We currently allow tangle to shoot its own foot: file.org: #+begin_src org :tangle file.org Overwrite me. #+end_src The attached patch makes Org throw an error in such scenario. I am almost sure that it is not going to break anyone's workflow. Or will it?.. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-org-babel-tangle-Do-not-allow-tangling-into-self.patch >From e2b0913930119737bac69d17738d0ebb44f999f7 Mon Sep 17 00:00:00 2001 Message-ID: From: Ihor Radchenko Date: Mon, 8 Jan 2024 16:58:24 +0100 Subject: [PATCH] org-babel-tangle: Do not allow tangling into self * lisp/ob-tangle.el (org-babel-tangle): Throw an error when trying to tangle into the org file we tangle from. * etc/ORG-NEWS (It is no longer allowed to tangle into the same file as Org source): Document the breaking change. --- etc/ORG-NEWS | 12 ++++++++++++ lisp/ob-tangle.el | 10 +++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index b808357d8..a8d14673c 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -13,6 +13,18 @@ Please send Org bug reports to mailto:emacs-orgmode@gnu.org. * Version 9.7 (not released yet) ** Important announcements and breaking changes +*** It is no longer allowed to tangle into the same file as Org source + +Previously, =file.org= with the following contents + +: #+begin_src org :tangle file.org +: Text +: #+end_src + +would overwrite itself. + +Now, an error is thrown. + *** ~org-agenda-search-headline-for-time~ now ignores all the timestamp in headings Previously, ~org-agenda-search-headline-for-time~ made Org agenda diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el index 933a3eba1..914f4b7b6 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -256,7 +256,8 @@ (defun org-babel-tangle (&optional arg target-file lang-re) (when (equal arg '(16)) (or (cdr (assq :tangle (nth 2 (org-babel-get-src-block-info 'no-eval)))) (user-error "Point is not in a source code block")))) - path-collector) + path-collector + (source-file buffer-file-name)) (mapc ;; map over file-names (lambda (by-fn) (let ((file-name (car by-fn))) @@ -313,6 +314,13 @@ (defun org-babel-tangle (&optional arg target-file lang-re) (compare-buffer-substrings nil nil nil tangle-buf nil nil))))))) + (when (equal (if (file-name-absolute-p file-name) + file-name + (expand-file-name file-name)) + (if (file-name-absolute-p source-file) + source-file + (expand-file-name source-file))) + (error "Not allowed to tangle into the same file as self")) ;; We do not erase, but overwrite previous file ;; to preserve any existing symlinks. (write-region nil nil file-name) -- 2.42.0 --=-=-= Content-Type: text/plain -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at --=-=-=--