1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-11-22 07:09:47 +00:00

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.
This commit is contained in:
Nicolas Goaziou 2012-10-15 22:29:30 +02:00
parent a67ed0f59d
commit 0920e60c01
2 changed files with 22 additions and 7 deletions

View File

@ -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.

View File

@ -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