diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2017-12-23 13:58:25 +0100 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2017-12-23 13:58:25 +0100 |
commit | d9125e435f09128bf9593fa598c3fc8a9c48c8d0 (patch) | |
tree | 807ad4b1f34ba582780a43ac3181cc8b261ba6f7 | |
parent | bac8d25441448d69764d55624f1ee21da28157a7 (diff) | |
download | org-mode-d9125e435f09128bf9593fa598c3fc8a9c48c8d0.tar.gz |
Fix recursive Noweb expansion
* lisp/ob-core.el (org-babel-expand-noweb-references): Recursive Noweb
expansion obey to :noweb parameter.
* testing/lisp/test-ob.el (test-ob/noweb-expansion): Add tests.
Fixes: 17523
-rw-r--r-- | lisp/ob-core.el | 14 | ||||
-rw-r--r-- | testing/lisp/test-ob.el | 38 |
2 files changed, 46 insertions, 6 deletions
diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 3ce6c9e..442a17d 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -2760,14 +2760,16 @@ block but are passed literally to the \"example-block\"." (if org-babel-use-quick-and-dirty-noweb-expansion (while (re-search-forward rx nil t) (let* ((i (org-babel-get-src-block-info 'light)) - (body (org-babel-expand-noweb-references i)) + (body (if (org-babel-noweb-p (nth 2 i) :eval) + (org-babel-expand-noweb-references i) + (nth 1 i))) (sep (or (cdr (assq :noweb-sep (nth 2 i))) "\n")) (full (if comment (let ((cs (org-babel-tangle-comment-links i))) - (concat (funcall c-wrap (car cs)) "\n" - body "\n" - (funcall c-wrap (cadr cs)))) + (concat (funcall c-wrap (car cs)) "\n" + body "\n" + (funcall c-wrap (cadr cs)))) body))) (setq expansion (cons sep (cons full expansion))))) (org-babel-map-src-blocks nil @@ -2776,7 +2778,9 @@ block but are passed literally to the \"example-block\"." (when (equal (or (cdr (assq :noweb-ref (nth 2 i))) (nth 4 i)) source-name) - (let* ((body (org-babel-expand-noweb-references i)) + (let* ((body (if (org-babel-noweb-p (nth 2 i) :eval) + (org-babel-expand-noweb-references i) + (nth 1 i))) (sep (or (cdr (assq :noweb-sep (nth 2 i))) "\n")) (full (if comment diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index 3e8f485..ffc493c 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -722,7 +722,43 @@ x #+begin_src sh :noweb-sep \"\" (+ 1 1) #+end_src" - (org-babel-expand-noweb-references))))) + (org-babel-expand-noweb-references)))) + ;; Handle recursive expansion. + (should + (equal "baz" + (org-test-with-temp-text " +#+begin_src emacs-lisp :noweb yes<point> + <<foo>> +#+end_src + +#+name: foo +#+begin_src emacs-lisp :noweb yes + <<bar>> +#+end_src + +#+name: bar +#+begin_src emacs-lisp + baz +#+end_src" + (org-babel-expand-noweb-references)))) + ;; During recursive expansion, obey to `:noweb' property. + (should + (equal "<<bar>>" + (org-test-with-temp-text " +#+begin_src emacs-lisp :noweb yes<point> + <<foo>> +#+end_src + +#+name: foo +#+begin_src emacs-lisp :noweb no + <<bar>> +#+end_src + +#+name: bar +#+begin_src emacs-lisp + baz +#+end_src" + (org-babel-expand-noweb-references))))) (ert-deftest test-ob/splitting-variable-lists-in-references () (org-test-with-temp-text "" |