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
1 changed files with 16 additions and 8 deletions

View File

@ -940,25 +940,33 @@ code ---- the results are extracted in the syntax of the source
(when (member "file" result-params)
(setq result (org-babel-result-to-file 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 (member "value" result-params)
(message "No result returned by source block")
(message "Source block produced no output"))
(if (and result-params (member "silent" result-params))
(progn (message (replace-regexp-in-string "%" "%%" (format "%S" result)))
result)
(progn
(message (replace-regexp-in-string "%" "%%" (format "%S" result)))
result)
(when (and (stringp result) ;; ensure results end in a newline
(not (or (string-equal (substring result -1) "\n")
(string-equal (substring result -1) "\r"))))
(setq result (concat result "\n")))
(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
(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
(if results-switches (concat " " results-switches) ""))
(cond
@ -1069,7 +1077,7 @@ parameters when merging lists."
(let ((results-exclusive-groups
'(("file" "vector" "table" "scalar" "raw" "org"
"html" "latex" "code" "pp")
("replace" "silent")
("replace" "silent" "append" "prepend")
("output" "value")))
(exports-exclusive-groups
'(("code" "results" "both" "none")))