0
0
Fork 1
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-09-29 20:07:46 +00:00

babel: updating results in place and adding prepend' and append' :results options

Thanks to Graham Smith for pointing out the need for in-place
  results updates

* contrib/babel/lisp/org-babel.el (org-babel-merge-params): adding
  append and prepend as exclusive options to the :results header
  argument

  (org-babel-insert-result): now updating results in place, and
  honoring the `prepend' and `append' :results header arguments
This commit is contained in:
Eric Schulte 2010-06-07 16:50:59 -07:00
parent 599c8a7114
commit 93ab492464

View file

@ -940,25 +940,33 @@ code ---- the results are extracted in the syntax of the source
(when (member "file" result-params) (when (member "file" result-params)
(setq result (org-babel-result-to-file result)))) (setq result (org-babel-result-to-file result))))
(unless (listp result) (setq result (format "%S" result)))) (unless (listp result) (setq result (format "%S" result))))
(if (and result-params (member "replace" result-params)
(not (member "silent" result-params)))
(org-babel-remove-result info))
(if (= (length result) 0) (if (= (length result) 0)
(if (member "value" result-params) (if (member "value" result-params)
(message "No result returned by source block") (message "No result returned by source block")
(message "Source block produced no output")) (message "Source block produced no output"))
(if (and result-params (member "silent" result-params)) (if (and result-params (member "silent" result-params))
(progn (message (replace-regexp-in-string "%" "%%" (format "%S" result))) (progn
result) (message (replace-regexp-in-string "%" "%%" (format "%S" result)))
result)
(when (and (stringp result) ;; ensure results end in a newline (when (and (stringp result) ;; ensure results end in a newline
(not (or (string-equal (substring result -1) "\n") (not (or (string-equal (substring result -1) "\n")
(string-equal (substring result -1) "\r")))) (string-equal (substring result -1) "\r"))))
(setq result (concat result "\n"))) (setq result (concat result "\n")))
(save-excursion (save-excursion
(let ((existing-result (org-babel-where-is-src-block-result t info hash)) (let ((existing-result (org-babel-where-is-src-block-result
t info hash))
(results-switches (results-switches
(cdr (assoc :results_switches (third info)))) beg) (cdr (assoc :results_switches (third info)))) beg)
(when existing-result (goto-char existing-result) (forward-line 1)) (when existing-result
(goto-char existing-result)
(forward-line 1)
(cond
((member "replace" result-params)
(delete-region (point) (org-babel-result-end)))
((member "append" result-params)
(goto-char (org-babel-result-end)))
((member "prepend" result-params) ;; already there
)))
(setq results-switches (setq results-switches
(if results-switches (concat " " results-switches) "")) (if results-switches (concat " " results-switches) ""))
(cond (cond
@ -1069,7 +1077,7 @@ parameters when merging lists."
(let ((results-exclusive-groups (let ((results-exclusive-groups
'(("file" "vector" "table" "scalar" "raw" "org" '(("file" "vector" "table" "scalar" "raw" "org"
"html" "latex" "code" "pp") "html" "latex" "code" "pp")
("replace" "silent") ("replace" "silent" "append" "prepend")
("output" "value"))) ("output" "value")))
(exports-exclusive-groups (exports-exclusive-groups
'(("code" "results" "both" "none"))) '(("code" "results" "both" "none")))