From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id GPaxIXUUaGNqQgAAbAwnHQ (envelope-from ) for ; Sun, 06 Nov 2022 21:09:25 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id QGbAIHUUaGOMYQAAG6o9tA (envelope-from ) for ; Sun, 06 Nov 2022 21:09:25 +0100 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 E453211C19 for ; Sun, 6 Nov 2022 21:09:23 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1orlwM-0004ov-7o; Sun, 06 Nov 2022 15:08:22 -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 1orlwJ-0004ok-Nz for emacs-orgmode@gnu.org; Sun, 06 Nov 2022 15:08:20 -0500 Received: from lyrion.ch ([202.61.204.114] helo=mail.lyrion.ch) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1orlwH-0007Ha-6z for emacs-orgmode@gnu.org; Sun, 06 Nov 2022 15:08:19 -0500 Received: from lyrion.ch (unknown [10.0.0.5]) by mail.lyrion.ch (Postfix) with ESMTP id 9522B2D875; Sun, 6 Nov 2022 20:08:08 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.lyrion.ch 9522B2D875 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lyrion.ch; s=mail; t=1667765292; bh=61wuMeyO1U61tbNsFkLwlstqI+uC/V81pAxbutSyEDI=; h=From:To:Cc:Subject:Date:From; b=Cc1kSMQ2YccfgyJBzIAnm3H47JY6TQUzqoeVzszSd6gHKX7PPukyZG0BUQf5yVcnA fk1QJJLNZYHSUqVoEjhK/W1O5V6KZTUj2UrYkBuNrzFfZtY7+HGomqjyCMzJrkw68v NJuej1/tSV2cfNzVXPNEMDkKO3i/U/Blld7Ryj3MUEEt3Pxr0YdXDYP2qg3LUJeIyr hbnFQX2D80HSdDcuMOtSpBp5PJTerZD4EStZYQWXvNo1q7gOQpLhl3r663/qN/QOxR 5V9+WQu+NFpLHHxEhL9sYm3n2UWBuRH88rJqvpUQUXvFHmARaXNLsmwhz6zGizCTSe gFQRPk9ppqbog== Received: from localhost.localdomain ([213.54.13.202]) by lyrion.ch with ESMTPSA id +MkZHygUaGPUwQAAYxOsgw (envelope-from ); Sun, 06 Nov 2022 20:08:08 +0000 From: Daniel Ziltener To: emacs-orgmode@gnu.org Cc: Daniel Ziltener Subject: [PATCH] lisp/ob-tangle.el, lisp/ob-core.el: Add strip-tangle Date: Sun, 6 Nov 2022 21:08:06 +0100 Message-Id: <20221106200806.24967-1-dziltener@lyrion.ch> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: none client-ip=202.61.204.114; envelope-from=dziltener@lyrion.ch; helo=mail.lyrion.ch X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1667765365; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=61wuMeyO1U61tbNsFkLwlstqI+uC/V81pAxbutSyEDI=; b=HIg24+tMQhRrDDKsb4fjt8586bOBGcvPEEqYjk5MAC+W15VARvdudIIdHHqEsB1ZSdIjoq VqRIVdPVisX74PDu3sFseFhdkl+DHLRZFkOxWJiMC8OxHTQhBwQl9br/grT1MwMQpLJMOU yRUQM1dBUOud4cJ9jd4Dha5WzwNg7l3AfirpMseO+ABDa/rpZzO8hjJBmjI8QF/FwoZOir YifV6G+m/3qdYSdnpQLLqsyKLDQ4c2lN40iA8OcCurGkkhhdM73aLr229a9iAUMW2Ok/B2 hWxmxB87XSe2v52NUsNPramfZtKZJ0zwL6i8pw12731KgEktXywYrP86z40XVA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1667765365; a=rsa-sha256; cv=none; b=DQcwYfawhXGaslhtNuR93iHeqiU8aLiILgSFr43I9jqTbRghfQNiFDvmNZPfKwl3BYN3K9 /FbVu2vrC8JHT1lAvsuChWdckFlDFochbMH7s7NoBm+SKCDo/4Ln15wzPtMYoX3J9MzoxB NcdMAW2YvXzjwavfwTP5r+ybo9cbWXPj+DevOXbZLQNvt3t5necGzE3bPb7vIqKr4gAx50 knGLU2HU9LnA39ZlhYxtsz5G+i7JgpGuPugiSdkRTw4NKFAlztPyV8ZKrYPMMgZqUjqDN+ LRBbZsnANWRVWChr17r6yWQ3wC7oHn+d6k/e6RfQiP4x7iIom0TxjJqVcva7Pg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none ("invalid DKIM record") header.d=lyrion.ch header.s=mail header.b=Cc1kSMQ2; 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" X-Migadu-Spam-Score: -1.30 Authentication-Results: aspmx1.migadu.com; dkim=none ("invalid DKIM record") header.d=lyrion.ch header.s=mail header.b=Cc1kSMQ2; 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" X-Migadu-Queue-Id: E453211C19 X-Spam-Score: -1.30 X-Migadu-Scanner: scn1.migadu.com X-TUID: VxPvKM5cLxjY * lisp/ob-tangle.el (org-babel-tangle-single-block): strip noweb tags from block if :noweb has been set to strip-tangle. * lisp/ob-core.el (org-babel-common-header-args-w-values): add "strip-tangle" as new allowed value. * lisp/ob-core.el (org-babel-noweb-p): add "strip-tangle" at the appropriate positions. * testing/lisp/test-ob-tangle.el (ob-tangle/strip-tangle): add new test case for "strip-tangle". * doc/org-manual.org (Noweb Reference Syntax): adjust documentation for the noweb header argument. * etc/ORG-NEWS: add entry for new header argument value. This patch adds the "strip-tangle" option for the :noweb header argument. This strips the noweb tags before tangling the block. This can be useful for e.g. testing purposes where one wants to use a block as test case that can be both run inline as well as tangled into a file for automated testing. --- doc/org-manual.org | 6 ++++++ etc/ORG-NEWS | 5 +++++ lisp/ob-core.el | 8 ++++---- lisp/ob-tangle.el | 4 +++- testing/lisp/test-ob-tangle.el | 26 ++++++++++++++++++++++++++ 5 files changed, 44 insertions(+), 5 deletions(-) diff --git a/doc/org-manual.org b/doc/org-manual.org index b3071ec6d..90fd950dc 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -18998,6 +18998,12 @@ tangled, or exported. Expansion of noweb syntax references in the body of the code block when tangling. No expansion when evaluating or exporting. +- =strip-tangle= :: + + Expansion of noweb syntax references in the body of the code block + when evaluating or exporting. Removes noweb syntax references + when exporting. + - =no-export= :: Expansion of noweb syntax references in the body of the code block diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index b542da34b..ca1944614 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -228,6 +228,11 @@ commands. =:noweb-prefix= can be set to =no= to prevent the prefix characters from being repeated when expanding a multiline noweb reference. +*** New =:noweb= babel header argument value =strip-tangle= + +=:noweb= can be set to =strip-tangle= to strip the noweb syntax references +before tangling. + *** New LaTeX source block backend using =engraved-faces-latex= When ~org-latex-src-block-backend~ is set to ~engraved~, diff --git a/lisp/ob-core.el b/lisp/ob-core.el index a1c11e6ca..22d60cfe6 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -415,7 +415,7 @@ then run `org-babel-switch-to-session'." (mkdirp . ((yes no))) (no-expand) (noeval) - (noweb . ((yes no tangle no-export strip-export))) + (noweb . ((yes no tangle strip-tangle no-export strip-export))) (noweb-ref . :any) (noweb-sep . :any) (noweb-prefix . ((no yes))) @@ -2885,9 +2885,9 @@ parameters when merging lists." "Check if PARAMS require expansion in CONTEXT. CONTEXT may be one of :tangle, :export or :eval." (let ((allowed-values (cl-case context - (:tangle '("yes" "tangle" "no-export" "strip-export")) - (:eval '("yes" "no-export" "strip-export" "eval")) - (:export '("yes"))))) + (:tangle '("yes" "tangle" "no-export" "strip-export" "strip-tangle")) + (:eval '("yes" "no-export" "strip-export" "eval" "strip-tangle")) + (:export '("yes" "strip-tangle"))))) (cl-some (lambda (v) (member v allowed-values)) (split-string (or (cdr (assq :noweb params)) ""))))) diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el index 2da92efaf..ad027ccd0 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -536,7 +536,9 @@ non-nil, return the full association list to be used by (body ;; Run the tangle-body-hook. (let ((body (if (org-babel-noweb-p params :tangle) - (org-babel-expand-noweb-references info) + (if (string= "strip-tangle" (cdr (assq :noweb (nth 2 info)))) + (replace-regexp-in-string (org-babel-noweb-wrap) "" (nth 1 info)) + (org-babel-expand-noweb-references info)) (nth 1 info)))) (with-temp-buffer (insert diff --git a/testing/lisp/test-ob-tangle.el b/testing/lisp/test-ob-tangle.el index a0003ee40..2a6e4b1dd 100644 --- a/testing/lisp/test-ob-tangle.el +++ b/testing/lisp/test-ob-tangle.el @@ -510,6 +510,32 @@ another block (org-split-string (buffer-string)))) (delete-file file)))))) +(ert-deftest ob-tangle/strip-tangle () + "Test if strip-tangle works correctly when tangling noweb code blocks." + (should + (equal '("1") + (let ((file (make-temp-file "org-tangle-"))) + (unwind-protect + (progn + (org-test-with-temp-text-in-file + (format " +#+name: block1 +#+begin_src elisp +2 +#+end_src + +#+begin_src elisp :noweb strip-tangle :tangle %s +1<> +#+end_src +" file) + (let ((org-babel-noweb-error-all-langs nil) + (org-babel-noweb-error-langs nil)) + (org-babel-tangle))) + (with-temp-buffer + (insert-file-contents file) + (org-split-string (buffer-string)))) + (delete-file file)))))) + (ert-deftest ob-tangle/detangle-false-positive () "Test handling of false positive link during detangle." (let (buffer) -- 2.38.1