[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org 5e0c5c186d: org-babel: Add new "strip-tangle" :nowe
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org 5e0c5c186d: org-babel: Add new "strip-tangle" :noweb argument value |
Date: |
Sun, 6 Nov 2022 21:57:52 -0500 (EST) |
branch: externals/org
commit 5e0c5c186dc151a2a2447a52c57f0db5b501a17b
Author: Daniel Ziltener <dziltener@lyrion.ch>
Commit: Ihor Radchenko <yantar92@posteo.net>
org-babel: Add new "strip-tangle" :noweb argument value
* 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.
TINYCHANGE
---
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 b3071ec6dc..90fd950dc3 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 b542da34be..ca19446147 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 a1c11e6ca1..22d60cfe60 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 2da92efaf2..ad027ccd06 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 a0003ee408..2a6e4b1dd1 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<<block1>>
+#+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)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/org 5e0c5c186d: org-babel: Add new "strip-tangle" :noweb argument value,
ELPA Syncer <=