diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el index 78b6f99f7..b8669f0b9 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 8b35115c6..62414b41c 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