mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-12-22 10:26:23 +00:00
evaluate all executables in buffer order on export
* lisp/ob-exp.el (org-babel-exp-non-block-elements): Map over both inline src blocks and call lines on export.
This commit is contained in:
parent
4f5b6317b5
commit
43abeaa488
130
lisp/ob-exp.el
130
lisp/ob-exp.el
@ -34,8 +34,7 @@
|
||||
(defvar org-babel-ref-split-regexp)
|
||||
(declare-function org-babel-lob-get-info "ob-lob" ())
|
||||
(declare-function org-babel-eval-wipe-error-buffer "ob-eval" ())
|
||||
(add-to-list 'org-export-interblocks '(src org-babel-exp-inline-src-blocks))
|
||||
(add-to-list 'org-export-interblocks '(lob org-babel-exp-lob-one-liners))
|
||||
(add-to-list 'org-export-interblocks '(src org-babel-exp-non-block-elements))
|
||||
|
||||
(org-export-blocks-add-block '(src org-babel-exp-src-block nil))
|
||||
|
||||
@ -117,33 +116,73 @@ none ----- do not display either code or results upon export"
|
||||
(nth 1 info)))
|
||||
(org-babel-exp-do-export info 'block hash)))))
|
||||
|
||||
(defun org-babel-exp-inline-src-blocks (start end)
|
||||
"Process inline source blocks between START and END for export.
|
||||
See `org-babel-exp-src-block' for export options, currently the
|
||||
options and are taken from `org-babel-default-inline-header-args'."
|
||||
(defvar org-babel-default-lob-header-args)
|
||||
(defun org-babel-exp-non-block-elements (start end)
|
||||
"Process inline source and call lines between START and END for export."
|
||||
(interactive)
|
||||
(save-excursion
|
||||
(goto-char start)
|
||||
(while (and (< (point) end)
|
||||
(re-search-forward org-babel-inline-src-block-regexp end t))
|
||||
(let* ((info (save-match-data (org-babel-parse-inline-src-block-match)))
|
||||
(params (nth 2 info)))
|
||||
(save-match-data
|
||||
(goto-char (match-beginning 2))
|
||||
(unless (markerp end)
|
||||
(let ((m (make-marker)))
|
||||
(set-marker m end (current-buffer))
|
||||
(setq end m)))
|
||||
(let ((rx (concat "\\(" org-babel-inline-src-block-regexp
|
||||
"\\|" org-babel-lob-one-liner-regexp "\\)")))
|
||||
(while (and (< (point) (marker-position end))
|
||||
(re-search-forward rx end t))
|
||||
(if (save-excursion
|
||||
(goto-char (match-beginning 0))
|
||||
(looking-at org-babel-inline-src-block-regexp))
|
||||
(progn
|
||||
(forward-char 1)
|
||||
(let* ((info (save-match-data
|
||||
(org-babel-parse-inline-src-block-match)))
|
||||
(params (nth 2 info)))
|
||||
(save-match-data
|
||||
(goto-char (match-beginning 2))
|
||||
(unless (org-babel-in-example-or-verbatim)
|
||||
;; expand noweb references in the original file
|
||||
(setf (nth 1 info)
|
||||
(if (and (cdr (assoc :noweb params))
|
||||
(string= "yes" (cdr (assoc :noweb params))))
|
||||
(org-babel-expand-noweb-references
|
||||
info (get-file-buffer org-current-export-file))
|
||||
(nth 1 info)))
|
||||
(let ((code-replacement (save-match-data
|
||||
(org-babel-exp-do-export
|
||||
info 'inline))))
|
||||
(if code-replacement
|
||||
(replace-match code-replacement nil nil nil 1)
|
||||
(org-babel-examplize-region (match-beginning 1)
|
||||
(match-end 1))
|
||||
(forward-char 2)))))))
|
||||
(unless (org-babel-in-example-or-verbatim)
|
||||
;; expand noweb references in the original file
|
||||
(setf (nth 1 info)
|
||||
(if (and (cdr (assoc :noweb params))
|
||||
(string= "yes" (cdr (assoc :noweb params))))
|
||||
(org-babel-expand-noweb-references
|
||||
info (get-file-buffer org-current-export-file))
|
||||
(nth 1 info)))
|
||||
(let ((code-replacement (save-match-data
|
||||
(org-babel-exp-do-export info 'inline))))
|
||||
(if code-replacement
|
||||
(replace-match code-replacement nil nil nil 1)
|
||||
(org-babel-examplize-region (match-beginning 1) (match-end 1))
|
||||
(forward-char 2)))))))))
|
||||
(let* ((lob-info (org-babel-lob-get-info))
|
||||
(inlinep (match-string 11))
|
||||
(inline-start (match-end 11))
|
||||
(inline-end (match-end 0))
|
||||
(rep (let ((lob-info (org-babel-lob-get-info)))
|
||||
(save-match-data
|
||||
(org-babel-exp-do-export
|
||||
(list "emacs-lisp" "results"
|
||||
(org-babel-merge-params
|
||||
org-babel-default-header-args
|
||||
org-babel-default-lob-header-args
|
||||
(org-babel-params-from-properties)
|
||||
(org-babel-parse-header-arguments
|
||||
(org-babel-clean-text-properties
|
||||
(concat ":var results="
|
||||
(mapconcat #'identity
|
||||
(butlast lob-info)
|
||||
" ")))))
|
||||
"" nil (car (last lob-info)))
|
||||
'lob)))))
|
||||
(if inlinep
|
||||
(save-excursion
|
||||
(goto-char inline-start)
|
||||
(delete-region inline-start inline-end)
|
||||
(insert rep))
|
||||
(replace-match rep t t)))))))))
|
||||
|
||||
(defun org-babel-in-example-or-verbatim ()
|
||||
"Return true if point is in example or verbatim code.
|
||||
@ -158,47 +197,6 @@ org-mode text."
|
||||
(org-in-block-p org-list-forbidden-blocks)
|
||||
(org-between-regexps-p "^[ \t]*#\\+begin_src" "^[ \t]*#\\+end_src")))
|
||||
|
||||
(defvar org-babel-default-lob-header-args)
|
||||
(defun org-babel-exp-lob-one-liners (start end)
|
||||
"Process Library of Babel calls between START and END for export.
|
||||
See `org-babel-exp-src-block' for export options. Currently the
|
||||
options are taken from `org-babel-default-header-args'."
|
||||
(interactive)
|
||||
(save-excursion
|
||||
(goto-char start)
|
||||
(unless (markerp end)
|
||||
(let ((m (make-marker)))
|
||||
(set-marker m end (current-buffer))
|
||||
(setq end m)))
|
||||
(while (and (< (point) (marker-position end))
|
||||
(re-search-forward org-babel-lob-one-liner-regexp end t))
|
||||
(unless (org-babel-in-example-or-verbatim)
|
||||
(let* ((lob-info (org-babel-lob-get-info))
|
||||
(inlinep (match-string 11))
|
||||
(inline-start (match-end 11))
|
||||
(inline-end (match-end 0))
|
||||
(rep (let ((lob-info (org-babel-lob-get-info)))
|
||||
(save-match-data
|
||||
(org-babel-exp-do-export
|
||||
(list "emacs-lisp" "results"
|
||||
(org-babel-merge-params
|
||||
org-babel-default-header-args
|
||||
org-babel-default-lob-header-args
|
||||
(org-babel-params-from-properties)
|
||||
(org-babel-parse-header-arguments
|
||||
(org-babel-clean-text-properties
|
||||
(concat ":var results="
|
||||
(mapconcat #'identity
|
||||
(butlast lob-info) " ")))))
|
||||
"" nil (car (last lob-info)))
|
||||
'lob)))))
|
||||
(if inlinep
|
||||
(save-excursion
|
||||
(goto-char inline-start)
|
||||
(delete-region inline-start inline-end)
|
||||
(insert rep))
|
||||
(replace-match rep t t)))))))
|
||||
|
||||
(defun org-babel-exp-do-export (info type &optional hash)
|
||||
"Return a string with the exported content of a code block.
|
||||
The function respects the value of the :exports header argument."
|
||||
|
@ -308,3 +308,29 @@ src_sh{echo 2} blocks on the src_emacs-lisp{"same"} line
|
||||
#+name:
|
||||
[[file:./cv.cls]]
|
||||
|
||||
* in order evaluation on export
|
||||
:PROPERTIES:
|
||||
:exports: results
|
||||
:ID: 96cc7073-97ec-4556-87cf-1f9bffafd317
|
||||
:END:
|
||||
|
||||
First.
|
||||
#+name: foo-for-order-of-evaluation
|
||||
#+begin_src emacs-lisp :var it=1
|
||||
(push it *evaluation-collector*)
|
||||
#+end_src
|
||||
|
||||
Second
|
||||
#+begin_src emacs-lisp
|
||||
(push 2 *evaluation-collector*)
|
||||
#+end_src
|
||||
|
||||
Third src_emacs-lisp{(push 3 *evaluation-collector*)}
|
||||
|
||||
Fourth
|
||||
#+call: foo-for-order-of-evaluation(4)
|
||||
|
||||
Fifth
|
||||
#+begin_src emacs-lisp
|
||||
(push 5 *evaluation-collector*)
|
||||
#+end_src
|
||||
|
@ -103,6 +103,13 @@
|
||||
;; (org-mark-subtree)
|
||||
;; (org-export-as-latex nil)))
|
||||
|
||||
(ert-deftest ob-exp/evaluate-all-executables-in-order ()
|
||||
(org-test-at-id "96cc7073-97ec-4556-87cf-1f9bffafd317"
|
||||
(org-narrow-to-subtree)
|
||||
(let (*evaluation-collector*)
|
||||
(org-export-as-ascii nil nil nil 'string)
|
||||
(should (equal '(5 4 3 2 1) *evaluation-collector*)))))
|
||||
|
||||
(provide 'test-ob-exp)
|
||||
|
||||
;;; test-ob-exp.el ends here
|
||||
|
@ -177,7 +177,6 @@
|
||||
(let ((test-point (point)))
|
||||
(should (fboundp 'org-babel-get-inline-src-block-matches))
|
||||
(should (re-search-forward "src_" nil t)) ;; 1
|
||||
(should (= (+ test-point 138) (match-end 0)))
|
||||
(should (org-babel-get-inline-src-block-matches))
|
||||
(should (re-search-forward "}" nil (point-at-bol))) ;; 1
|
||||
(should-not (org-babel-get-inline-src-block-matches))
|
||||
|
@ -146,6 +146,7 @@ currently executed.")
|
||||
(save-restriction ,@body)))
|
||||
(unless visited-p
|
||||
(kill-buffer to-be-removed))))
|
||||
(def-edebug-spec org-test-at-id (form body))
|
||||
|
||||
(defmacro org-test-in-example-file (file &rest body)
|
||||
"Execute body in the Org-mode example file."
|
||||
|
Loading…
Reference in New Issue
Block a user