From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.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 iBeMLuaMWWMBsgAAbAwnHQ (envelope-from ) for ; Wed, 26 Oct 2022 21:39:18 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id IP+KLeaMWWMXwQAAG6o9tA (envelope-from ) for ; Wed, 26 Oct 2022 21:39:18 +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 329FB385AF for ; Wed, 26 Oct 2022 21:39:18 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onmDz-0001m3-Ua; Wed, 26 Oct 2022 15:38:03 -0400 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 1onmDy-0001hH-Lw for emacs-orgmode@gnu.org; Wed, 26 Oct 2022 15:38:02 -0400 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 1onmDw-0005RF-2U for emacs-orgmode@gnu.org; Wed, 26 Oct 2022 15:38:02 -0400 Received: from unknown34c93dcc173a.localdomain (dynamic-077-011-043-249.77.11.pool.telefonica.de [77.11.43.249]) by mail.lyrion.ch (Postfix) with ESMTPA id E02B02A8DF; Wed, 26 Oct 2022 19:37:53 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.lyrion.ch E02B02A8DF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lyrion.ch; s=mail; t=1666813078; bh=E6Cq0ygbHeKTPZsPgIpsYrw0TSDZSzBmiNSVXcrbxKU=; h=From:To:Cc:Subject:Date:From; b=PdgKnJ8nRij/1zYwuv9Kq/1Da2tC9KLJbN5ala0saDB1LlQ8wxEvYY6YyJ8pEoDEY nFuc2ci7PcFTdPLv4dKnlDyDDmc8CONuS7itH9BzRESxiaLob1dEWu99Rrpt89ba78 y7IdFU9zPF0Yzsl7k68dC0qu/926viTeURxHTBqH6q5TuhUIq/jg7z4N22iYdtPI0i FF+uf0MYtxZKJtOSo2rDTyLEGEJZrUEoBG/lka+XdbzuITaKqT7GmRR0dK3wYupUfk paQinz/4U+6QZK7302ubsWIvTEIqHCCAItwnsajGZWl0fncWkbJXv/+9rctnYiuNAA AZPT1DdNr9bQw== From: dziltener@lyrion.ch To: emacs-orgmode@gnu.org Cc: Daniel Ziltener Subject: [PATCH] lisp/ob-tangle.el, lisp/ob-core.el: Add strip-tangle noweb option Date: Wed, 26 Oct 2022 21:37:33 +0200 Message-Id: <20221026193733.14725-1-dziltener@lyrion.ch> X-Mailer: git-send-email 2.35.3 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: , Sender: "Emacs-orgmode" Errors-To: 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=1666813158; 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=E6Cq0ygbHeKTPZsPgIpsYrw0TSDZSzBmiNSVXcrbxKU=; b=kGSWoLv9p1qv2oDFLGZ1Ld52iAealthAxqAIUmGPuylGEsC1+/OogRizxc9g3kDhuJo8Hs nZ2FXGVi2TVx2E/IV6Bwp43HeQ/9t4qiPRVkHOJGPDEuq1ipXhOmwB/AySD0QTyRbahYay LH0jOS8CJlpid8PF6C72S8yqBXblbsPiTJFpudDWWU0l7nVPQHf1rZ2Fmu7lPF9DQUn81H 72Il2EVww9HfC6c55Ab7ZUhcdzHhS2E8SDrQZ/A1rOk+CmXjRksKI9eOwftvgkEYGleJuT icKCsUi/axhFd0x0vfUeqcewht2ck9SJhT+R7h+p1OY3l79CbSZYWHwzLOk46A== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1666813158; a=rsa-sha256; cv=none; b=CRQsoahbeR83DqRB969qyVvFJCdjazGkQYmHDDNKPsDArANOCytkfWxqnfNGuPcT36UJTl 3uf+QeW3+Cql2sXTfLompMtXHC+tSusY27AEsHjMYALR3hepHRwUcb7SUXZV37Lj7L/NA3 CldNCHcXMwCnus49W279mzimcWR8jzB81xwFkRDkWtISjVt0DjGysDD0qzXNcOU4mF0vvP ZW/GKhtCbU2LPKMy6yOEOQ4k56XBmtVbW3ePFu/4OcKVc9xICSAh4vtL+DF/+EEYZgWXwr GVH7hquF3Gzx4M0RLkyOOUb1kEu1uz5qF5Ya58dkOIwaC2qVuBVQCsaRaeV7gA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none ("invalid DKIM record") header.d=lyrion.ch header.s=mail header.b=PdgKnJ8n; 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: 0.28 Authentication-Results: aspmx1.migadu.com; dkim=none ("invalid DKIM record") header.d=lyrion.ch header.s=mail header.b=PdgKnJ8n; 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: 329FB385AF X-Spam-Score: 0.28 X-Migadu-Scanner: scn1.migadu.com X-TUID: vX057c81MxDp From: Daniel Ziltener * ob-tangle.el, ob-core.el, test-ob-tangle.el, org-manual.org: Add a "strip-tangle" noweb option to strip the noweb tags when tangling, but keep and expand them otherwise. --- doc/org-manual.org | 6 ++++++ lisp/ob-core.el | 6 +++--- lisp/ob-tangle.el | 4 +++- testing/lisp/test-ob-tangle.el | 27 +++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/doc/org-manual.org b/doc/org-manual.org index 18a050069..cb85f4702 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -18993,6 +18993,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 tangling. + - =no-export= :: Expansion of noweb syntax references in the body of the code block diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 518831ec6..ae77182ef 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -2880,9 +2880,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..d9d847195 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..455745e5c 100644 --- a/testing/lisp/test-ob-tangle.el +++ b/testing/lisp/test-ob-tangle.el @@ -510,6 +510,33 @@ 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.35.3