summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Schulte <eric.schulte@gmx.com>2012-02-01 08:17:08 -0700
committerEric Schulte <eric.schulte@gmx.com>2012-02-01 08:19:29 -0700
commita3e5f97ee7ba27473b25f7e42e317e74629ce2d6 (patch)
tree0217bcf4e7450c8fbdd2f11e381eed58fa43f9b0
parent4b59c36b035948e6336fd0a7e311e80f338aa6af (diff)
downloadorg-mode-a3e5f97ee7ba27473b25f7e42e317e74629ce2d6.tar.gz
New strip-export noweb header argument value
* lisp/ob-exp.el (org-babel-exp-src-block): Strip noweb references on export when "strip-export". * lisp/ob.el (org-babel-common-header-args-w-values): New noweb header value. (org-babel-merge-params): New noweb header value. (org-babel-noweb-p): New noweb header value. * testing/examples/babel.org (an): Testing new noweb header value. * testing/lisp/test-ob-exp.el (ob-exp/noweb-strip-export-ensure-strips): Testing new noweb header value. * doc/org.texi (noweb): Document new noweb header value.
-rw-r--r--doc/org.texi8
-rw-r--r--lisp/ob-exp.el11
-rw-r--r--lisp/ob.el12
-rw-r--r--testing/examples/babel.org14
-rw-r--r--testing/lisp/test-ob-exp.el9
5 files changed, 43 insertions, 11 deletions
diff --git a/doc/org.texi b/doc/org.texi
index 952f740..eb164bd 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -13609,8 +13609,8 @@ interpreted language.
The @code{:noweb} header argument controls expansion of ``noweb'' syntax
references (see @ref{Noweb reference syntax}) when the code block is
evaluated, tangled, or exported. The @code{:noweb} header argument can have
-one of four values: @code{no}, @code{yes}, @code{tangle}, or
-@code{no-export}.
+one of the five values: @code{no}, @code{yes}, @code{tangle}, or
+@code{no-export} @code{strip-export}.
@itemize @bullet
@item @code{no}
@@ -13627,6 +13627,10 @@ not be expanded when the code block is evaluated or exported.
``Noweb'' syntax references in the body of the code block will be expanded
before the block is evaluated or tangled. However, ``noweb'' syntax
references will not be expanded when the code block is exported.
+@item @code{strip-export}
+``Noweb'' syntax references in the body of the code block will be expanded
+before the block is evaluated or tangled. However, ``noweb'' syntax
+references will not be removed when the code block is exported.
@end itemize
@subsubheading Noweb prefix lines
diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el
index 442a9f1..f0fd3f4 100644
--- a/lisp/ob-exp.el
+++ b/lisp/ob-exp.el
@@ -109,10 +109,13 @@ none ----- do not display either code or results upon export"
(setf hash (org-babel-sha1-hash info)))
;; expand noweb references in the original file
(setf (nth 1 info)
- (if (org-babel-noweb-p (nth 2 info) :export)
- (org-babel-expand-noweb-references
- info (get-file-buffer org-current-export-file))
- (nth 1 info)))
+ (if (string= "strip-export" (cdr (assoc :noweb (nth 2 info))))
+ (replace-regexp-in-string
+ (org-babel-noweb-wrap) "" (nth 1 info))
+ (if (org-babel-noweb-p (nth 2 info) :export)
+ (org-babel-expand-noweb-references
+ info (get-file-buffer org-current-export-file))
+ (nth 1 info))))
(org-babel-exp-do-export info 'block hash)))))
(defcustom org-babel-exp-call-line-template
diff --git a/lisp/ob.el b/lisp/ob.el
index 49b542a..e1a495c 100644
--- a/lisp/ob.el
+++ b/lisp/ob.el
@@ -398,7 +398,7 @@ then run `org-babel-pop-to-session'."
(mkdirp . ((yes no)))
(no-expand)
(noeval)
- (noweb . ((yes no tangle)))
+ (noweb . ((yes no tangle no-export strip-export)))
(noweb-ref . :any)
(noweb-sep . :any)
(padline . ((yes no)))
@@ -2086,8 +2086,10 @@ parameters when merging lists."
(:tangle ;; take the latest -- always overwrite
(setq tangle (or (list (cdr pair)) tangle)))
(:noweb
- (setq noweb (e-merge '(("yes" "no" "tangle" "no-export")) noweb
- (split-string (or (cdr pair) "")))))
+ (setq noweb (e-merge
+ '(("yes" "no" "tangle" "no-export" "strip-export"))
+ noweb
+ (split-string (or (cdr pair) "")))))
(:cache
(setq cache (e-merge '(("yes" "no")) cache
(split-string (or (cdr pair) "")))))
@@ -2128,8 +2130,8 @@ CONTEXT may be one of :tangle, :export or :eval."
(car as)
(intersect (cdr as) bs)))))
(intersect (case context
- (:tangle '("yes" "tangle" "no-export"))
- (:eval '("yes" "no-export"))
+ (:tangle '("yes" "tangle" "no-export" "strip-export"))
+ (:eval '("yes" "no-export" "strip-export"))
(:export '("yes")))
(split-string (or (cdr (assoc :noweb params)) "")))))
diff --git a/testing/examples/babel.org b/testing/examples/babel.org
index 200e03c..4d89707 100644
--- a/testing/examples/babel.org
+++ b/testing/examples/babel.org
@@ -341,3 +341,17 @@ Fifth
:END:
Here is a call line with more than just the results exported.
#+call: double(8)
+* strip noweb references on export
+ :PROPERTIES:
+ :ID: 8e7bd234-99b2-4b14-8cd6-53945e409775
+ :END:
+
+#+name: strip-export-1
+#+BEGIN_SRC sh :exports none
+ i="10"
+#+END_SRC
+
+#+BEGIN_SRC sh :noweb strip-export :exports code :results silent
+ <<strip-export-1>>
+ echo "1$i"
+#+END_SRC
diff --git a/testing/lisp/test-ob-exp.el b/testing/lisp/test-ob-exp.el
index 8cdfba4..d88017e 100644
--- a/testing/lisp/test-ob-exp.el
+++ b/testing/lisp/test-ob-exp.el
@@ -240,6 +240,15 @@ elements in the final html."
(should (string-match "16" html))
(should (string-match "special-token" html)))))
+(ert-deftest ob-exp/noweb-strip-export-ensure-strips ()
+ (org-test-at-id "8e7bd234-99b2-4b14-8cd6-53945e409775"
+ (org-narrow-to-subtree)
+ (org-babel-next-src-block 2)
+ (should (= 110 (org-babel-execute-src-block)))
+ (let ((ascii (org-export-as-ascii nil nil nil 'string t)))
+ (should-not (string-match (regexp-quote "<<strip-export-1>>") ascii))
+ (should-not (string-match (regexp-quote "i=\"10\"") ascii)))))
+
(provide 'test-ob-exp)
;;; test-ob-exp.el ends here