diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2018-10-11 00:01:50 +0200 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2018-10-11 00:01:50 +0200 |
commit | 2fda33bfef319654b46879056ff56a64259920e4 (patch) | |
tree | 172d3f66daf59d4457bb2499fa65f25bb0184a9a | |
parent | 0df6d9f782ea43239ddb418c4dd632a37ed4b63f (diff) | |
download | org-mode-2fda33bfef319654b46879056ff56a64259920e4.tar.gz |
ob-tangle: Fix tangling order
* lisp/ob-tangle.el (org-babel-tangle-collect-blocks): Preserver order
of code blocks from the source document.
* testing/lisp/test-ob-tangle.el (ob-tangle/block-order): New test.
Reported-by: Kaushal Modi <kaushal.modi@gmail.com>
<http://lists.gnu.org/r/emacs-orgmode/2018-10/msg00062.html>
-rw-r--r-- | lisp/ob-tangle.el | 3 | ||||
-rw-r--r-- | testing/lisp/test-ob-tangle.el | 45 |
2 files changed, 47 insertions, 1 deletions
diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el index d78c90b..57798f8 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -407,7 +407,8 @@ can be used to limit the collected code blocks by target file." (if by-lang (setcdr by-lang (cons block (cdr by-lang))) (push (cons src-lang (list block)) blocks))))))) ;; Ensure blocks are in the correct order. - (mapcar (lambda (b) (cons (car b) (nreverse (cdr b)))) blocks))) + (mapcar (lambda (b) (cons (car b) (nreverse (cdr b)))) + (nreverse blocks)))) (defun org-babel-tangle-single-block (block-counter &optional only-this-block) "Collect the tangled source for current block. diff --git a/testing/lisp/test-ob-tangle.el b/testing/lisp/test-ob-tangle.el index 560cc6c..1dfd1a9 100644 --- a/testing/lisp/test-ob-tangle.el +++ b/testing/lisp/test-ob-tangle.el @@ -222,6 +222,51 @@ another block (buffer-string))) (delete-file "test-ob-tangle.org")))))) +(ert-deftest ob-tangle/block-order () + "Test order of tangled blocks." + ;; Order per language. + (should + (equal '("1" "2") + (let ((file (make-temp-file "org-tangle-"))) + (unwind-protect + (progn + (org-test-with-temp-text-in-file + (format "#+property: header-args :tangle %S +#+begin_src emacs-lisp +1 +#+end_src + +#+begin_src emacs-lisp +2 +#+end_src" + file) + (org-babel-tangle)) + (with-temp-buffer + (insert-file-contents file) + (org-split-string (buffer-string)))) + (delete-file file))))) + ;; Order per source block. + (should + (equal '("1" "2") + (let ((file (make-temp-file "org-tangle-"))) + (unwind-protect + (progn + (org-test-with-temp-text-in-file + (format "#+property: header-args :tangle %S +#+begin_src foo +1 +#+end_src + +#+begin_src bar +2 +#+end_src" + file) + (org-babel-tangle)) + (with-temp-buffer + (insert-file-contents file) + (org-split-string (buffer-string)))) + (delete-file file)))))) + (provide 'test-ob-tangle) ;;; test-ob-tangle.el ends here |