ob-exp: Fix block evaluation when results are before the block
* lisp/ob-exp.el (org-export-blocks-preprocess): Fix block evaluation when results are before the block.
This commit is contained in:
parent
f51c405920
commit
343b648994
|
@ -230,12 +230,14 @@ this template."
|
||||||
(let ((element (save-match-data (org-element-at-point))))
|
(let ((element (save-match-data (org-element-at-point))))
|
||||||
(when (eq (org-element-type element) 'src-block)
|
(when (eq (org-element-type element) 'src-block)
|
||||||
(let* ((block-start (copy-marker (match-beginning 0)))
|
(let* ((block-start (copy-marker (match-beginning 0)))
|
||||||
(match-start (copy-marker
|
(match-start
|
||||||
(org-element-property :begin element)))
|
(copy-marker (org-element-property :begin element)))
|
||||||
|
(element-end
|
||||||
|
(copy-marker (org-element-property :end element)))
|
||||||
;; Make sure we don't remove any blank lines after
|
;; Make sure we don't remove any blank lines after
|
||||||
;; the block when replacing it.
|
;; the block when replacing it.
|
||||||
(match-end (save-excursion
|
(block-end (save-excursion
|
||||||
(goto-char (org-element-property :end element))
|
(goto-char element-end)
|
||||||
(skip-chars-backward " \r\t\n")
|
(skip-chars-backward " \r\t\n")
|
||||||
(copy-marker (line-end-position))))
|
(copy-marker (line-end-position))))
|
||||||
(indentation (org-get-indentation))
|
(indentation (org-get-indentation))
|
||||||
|
@ -256,13 +258,12 @@ this template."
|
||||||
;; should remove the block.
|
;; should remove the block.
|
||||||
(let ((replacement (progn (goto-char block-start)
|
(let ((replacement (progn (goto-char block-start)
|
||||||
(org-babel-exp-src-block headers))))
|
(org-babel-exp-src-block headers))))
|
||||||
(cond ((not replacement) (goto-char match-end))
|
(cond ((not replacement) (goto-char block-end))
|
||||||
((equal replacement "")
|
((equal replacement "")
|
||||||
(delete-region (org-element-property :begin element)
|
(delete-region match-start element-end))
|
||||||
(org-element-property :end element)))
|
|
||||||
(t
|
(t
|
||||||
(goto-char match-start)
|
(goto-char match-start)
|
||||||
(delete-region (point) match-end)
|
(delete-region (point) block-end)
|
||||||
(insert replacement)
|
(insert replacement)
|
||||||
(if preserve-indent
|
(if preserve-indent
|
||||||
;; Indent only the code block markers.
|
;; Indent only the code block markers.
|
||||||
|
@ -271,12 +272,14 @@ this template."
|
||||||
(goto-char match-start)
|
(goto-char match-start)
|
||||||
(indent-line-to indentation))
|
(indent-line-to indentation))
|
||||||
;; Indent everything.
|
;; Indent everything.
|
||||||
(indent-code-rigidly match-start (point) indentation)))))
|
(indent-code-rigidly
|
||||||
|
match-start (point) indentation)))))
|
||||||
(setq start (point))
|
(setq start (point))
|
||||||
;; Cleanup markers.
|
;; Cleanup markers.
|
||||||
(set-marker block-start nil)
|
(set-marker block-start nil)
|
||||||
(set-marker match-start nil)
|
(set-marker block-end nil)
|
||||||
(set-marker match-end nil)))))
|
(set-marker match-start nil)
|
||||||
|
(set-marker element-end nil)))))
|
||||||
;; Eventually execute all non-block Babel elements between last
|
;; Eventually execute all non-block Babel elements between last
|
||||||
;; src-block and end of buffer.
|
;; src-block and end of buffer.
|
||||||
(org-babel-exp-non-block-elements start (point-max)))))
|
(org-babel-exp-non-block-elements start (point-max)))))
|
||||||
|
|
Loading…
Reference in New Issue