summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2012-10-15 22:29:30 +0200
committerNicolas Goaziou <n.goaziou@gmail.com>2012-10-15 22:29:30 +0200
commit0920e60c01432a7d5e5bd63ffcf224bdb1ebc4b8 (patch)
treef969ba194e14971ba70b43e173ba2916af9a573c
parenta67ed0f59d42ffc688820571f64104aeb534722e (diff)
downloadorg-mode-0920e60c01432a7d5e5bd63ffcf224bdb1ebc4b8.tar.gz
ob-exp: Fix removal of block results when exporting
* lisp/ob-exp.el (org-export-blocks-preprocess): Results of an evaluated code block can be inserted within the blank lines after the block. Hence, if the block has to be removed, delete everything down to the first non-blank line after the end of block closing string, instead of removing everything down to the very end of the block. * testing/lisp/test-ob-exp.el: Add test.
-rw-r--r--lisp/ob-exp.el17
-rw-r--r--testing/lisp/test-ob-exp.el12
2 files changed, 22 insertions, 7 deletions
diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el
index 78b6f99..b8669f0 100644
--- a/lisp/ob-exp.el
+++ b/lisp/ob-exp.el
@@ -248,13 +248,12 @@ this template."
(when (eq (org-element-type element) 'src-block)
(let* ((match-start (copy-marker (match-beginning 0)))
(begin (copy-marker (org-element-property :begin element)))
- (end (copy-marker (org-element-property :end element)))
;; Make sure we don't remove any blank lines after
;; the block when replacing it.
(block-end (save-excursion
- (goto-char end)
- (skip-chars-backward " \r\t\n")
- (copy-marker (line-end-position))))
+ (goto-char (org-element-property :end element))
+ (skip-chars-backward " \r\t\n")
+ (copy-marker (line-end-position))))
(ind (org-get-indentation))
(headers
(cons
@@ -273,8 +272,13 @@ this template."
;; should remove the block.
(let ((replacement (progn (goto-char match-start)
(org-babel-exp-src-block headers))))
- (cond ((not replacement) (goto-char end))
- ((equal replacement "") (delete-region begin end))
+ (cond ((not replacement) (goto-char block-end))
+ ((equal replacement "")
+ (delete-region begin
+ (progn (goto-char block-end)
+ (skip-chars-forward " \r\t\n")
+ (if (eobp) (point)
+ (line-beginning-position)))))
(t
(goto-char match-start)
(delete-region (point) block-end)
@@ -291,7 +295,6 @@ this template."
;; Cleanup markers.
(set-marker match-start nil)
(set-marker begin nil)
- (set-marker end nil)
(set-marker block-end nil)))))
;; Eventually execute all non-block Babel elements between last
;; src-block and end of buffer.
diff --git a/testing/lisp/test-ob-exp.el b/testing/lisp/test-ob-exp.el
index 8b35115..62414b4 100644
--- a/testing/lisp/test-ob-exp.el
+++ b/testing/lisp/test-ob-exp.el
@@ -273,6 +273,18 @@ elements in the final html."
(should (string-match (regexp-quote (format nil "%S" '(:foo :bar)))
ascii)))))
+(ert-deftest ob-exp/blocks-with-spaces ()
+ "Test expansion of blocks followed by blank lines."
+ (should
+ (equal "#+RESULTS:\n: 3\n\n\n"
+ (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp :exports results
+\(+ 1 2)
+#+END_SRC\n\n\n"
+ (let ((org-current-export-file (current-buffer)))
+ (org-export-blocks-preprocess)
+ (buffer-string))))))
+
+
(provide 'test-ob-exp)
;;; test-ob-exp.el ends here