Merge branch 'origin-maint'

Conflicts:
	lisp/ob-exp.el
	testing/examples/babel.org
This commit is contained in:
Eric Schulte 2012-01-23 10:46:03 -07:00
commit d3538624e7
4 changed files with 98 additions and 66 deletions

View File

@ -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))
@ -116,32 +115,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 (org-babel-noweb-p params :export)
(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.
@ -156,47 +196,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."

View File

@ -307,3 +307,30 @@ and another
# I am inside the code block
<<noweb-no-export-and-exports-both-1>>
#+END_SRC
* 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

View File

@ -224,6 +224,13 @@ elements in the final html."
(should (string-match (regexp-quote "noweb-no-export-and-exports-both-1")
html)))))
(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

View File

@ -241,7 +241,6 @@ this is simple"
(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))