1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-11-27 07:37:25 +00:00

added optional insertion of results...

from the description of litorgy-insert-result:

   Insert RESULT into the current buffer after the end of the
current source block.  With optional argument INSERT controls
insertion of results in the org-mode file.  INSERT can take the
following values...

t ------ the default options, simply insert the results after the
         source block

replace - insert results after the source block replacing any
          previously inserted results

silent -- no results are inserted
This commit is contained in:
Eric Schulte 2009-04-01 15:46:55 -07:00
parent e770100002
commit 3657836968
2 changed files with 50 additions and 23 deletions

View File

@ -107,7 +107,7 @@ prefix don't dump results into buffer."
(setq result (funcall cmd body params))
(if arg
(message (format "%S" result))
(litorgy-insert-result result (assoc :replace params)))))
(litorgy-insert-result result (cdr (assoc :results params))))))
(defun litorgy-eval-buffer (&optional arg)
"Replace EVAL snippets in the entire buffer."
@ -146,28 +146,38 @@ form. (language body header-arguments-alist)"
(cons (intern (concat ":" (match-string 1 arg))) (match-string 2 arg))))
(split-string (concat " " arg-string) "[ \f\t\n\r\v]+:"))))
(defun litorgy-insert-result (result &optional replace)
(defun litorgy-insert-result (result &optional insert)
"Insert RESULT into the current buffer after the end of the
current source block. With optional argument REPLACE replace any
existing results currently located after the source block."
(if replace (litorgy-remove-result (listp result)))
current source block. With optional argument INSERT controls
insertion of results in the org-mode file. INSERT can take the
following values...
t ------ the default options, simply insert the results after the
source block
replace - insert results after the source block replacing any
previously inserted results
silent -- no results are inserted"
(if (string-equal insert "replace") (litorgy-remove-result (listp result)))
(if (= (length result) 0)
(message "no result returned by source block")
(when (and (stringp result)
(not (or (string-equal (substring result -1) "\n")
(string-equal (substring result -1) "\r"))))
(setq result (concat result "\n")))
(save-excursion
(re-search-forward "^#\\+end_src" nil t) (open-line 1) (forward-char 2)
(if (stringp result)
(litorgy-examplize-region (point) (progn (insert result) (point)))
(progn
(insert ;; for now lets assume the result is a table if it's not a string
(concat (orgtbl-to-orgtbl
(if (consp (car result)) result (list result))
'(:fmt (lambda (cell) (format "%S" cell)))) "\n"))
(forward-line -1)
(org-cycle))))))
(unless (string-equal insert "silent")
(when (and (stringp result)
(not (or (string-equal (substring result -1) "\n")
(string-equal (substring result -1) "\r"))))
(setq result (concat result "\n")))
(save-excursion
(re-search-forward "^#\\+end_src" nil t) (open-line 1) (forward-char 2)
(if (stringp result) ;; assume the result is a table if it's not a string
(litorgy-examplize-region (point) (progn (insert result) (point)))
(progn
(insert
(concat (orgtbl-to-orgtbl
(if (consp (car result)) result (list result))
'(:fmt (lambda (cell) (format "%S" cell)))) "\n"))
(forward-line -1)
(org-cycle)))))))
(defun litorgy-remove-result (&optional table)
"Remove the result following the current source block. If

View File

@ -17,7 +17,7 @@
*** TODO ability to select which of multiple R sessions is being used
(like ess-switch-process in .R buffers)
** TODO a header argument specifying silent evaluation (no output)
** DONE a header argument specifying silent evaluation (no output)
This would be useful across all types of source block. Currently
there is a =:replace t= option to control output, this could be
generalized to an =:output= option which could take the following
@ -25,8 +25,10 @@ options (maybe more)
- =t= :: this would be the default, and would simply insert the
results after the source block
- =:replace= :: to replace any results which may already be there
- =nil= :: this would inhibit any insertion of the results
- =replace= :: to replace any results which may already be there
- =silent= :: this would inhibit any insertion of the results
This is now implemented see the example in the [[* silent evaluation][sandbox]]
* Bugs
@ -217,6 +219,21 @@ x
** silent evaluation
#+begin_src ruby
:im_the_results
#+end_src
#+begin_src ruby :results silent
:im_the_results
#+end_src
#+begin_src ruby :results replace
:im_the_results
#+end_src
* COMMENT Commentary
I'm seeing this as like commit notes, and a place for less formal
communication of the goals of our changes.