From 6ca0934ead974bb301e9a2fffd7fa342a9571032 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Tue, 18 Aug 2009 17:55:10 -0600 Subject: [PATCH] DONE new results types (org, html, latex) --- lisp/org-babel.el | 62 +++++++++++++++------- org-babel.org | 151 +++++++++++++++++++++++++++++++++--------------------- 2 files changed, 137 insertions(+), 76 deletions(-) diff --git a/lisp/org-babel.el b/lisp/org-babel.el index 6ad06695..b492df6d 100644 --- a/lisp/org-babel.el +++ b/lisp/org-babel.el @@ -492,13 +492,24 @@ 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 option, simply insert the results after the - source block +replace - (default option) insert results after the source block + replacing any previously inserted results -replace - insert results after the source block replacing any - previously inserted results +silent -- no results are inserted -silent -- no results are inserted" +raw ----- results are added directly to the org-mode file. This + is a good option if you code block will output org-mode + formatted text. + +org ----- this is the same as the 'raw' option + +html ---- results are added inside of a #+BEGIN_HTML block. This + is a good option if you code block will output html + formatted text. + +latex --- results are added inside of a #+BEGIN_LATEX block. + This is a good option if you code block will output + latex formatted text." (if (stringp result) (progn (setq result (org-babel-clean-text-properties result)) @@ -522,10 +533,14 @@ silent -- no results are inserted" (if (stringp result) ;; assume the result is a table if it's not a string (if (member "file" insert) (insert result) - (if (or (member "raw" insert) (member "org" insert)) - (progn (save-excursion (insert result)) - (if (org-at-table-p) (org-cycle))) - (org-babel-examplize-region (point) (progn (insert result) (point))))) + (if (member "html" insert) + (insert (format "#+BEGIN_HTML\n%s#+END_HTML\n" result)) + (if (member "latex" insert) + (insert (format "#+BEGIN_LaTeX\n%s#+END_LaTeX\n" result)) + (if (or (member "raw" insert) (member "org" insert)) + (progn (save-excursion (insert result)) + (if (org-at-table-p) (org-cycle))) + (org-babel-examplize-region (point) (progn (insert result) (point))))))) (progn (insert (concat (orgtbl-to-orgtbl @@ -553,12 +568,20 @@ relies on `org-babel-insert-result'." (save-excursion (if (org-at-table-p) (progn (goto-char (org-table-end)) (forward-line 1) (point)) - (let ((case-fold-search nil)) - (if (looking-at "#\\+begin_example") - (search-forward "#+end_example" nil t) - (progn (while (looking-at "\\(: \\|\\[\\[\\)") - (forward-line 1)) - (forward-line 1)))) + (let ((case-fold-search t)) + (cond + ((looking-at "#\\+begin_latex") + (search-forward "#+end_latex" nil t) + (forward-line 2)) + ((looking-at "#\\+begin_html") + (search-forward "#+end_html" nil t) + (forward-line 2)) + ((looking-at "#\\+begin_example") + (search-forward "#+end_example" nil t) + (forward-line 2)) + (t (progn (while (looking-at "\\(: \\|\\[\\[\\)") + (forward-line 1)) + (forward-line 1))))) (point)))) (defun org-babel-result-to-file (result) @@ -621,10 +644,11 @@ parameters when merging lists." ref (match-string 2 (cdr pair)) vars (cons (cons var ref) (assq-delete-all var vars))))) (:results - (setq results (e-merge '(("file" "vector" "scalar") - ("replace" "silent") - ("output" "value")) - results (split-string (cdr pair))))) + (setq results (e-merge + '(("file" "vector" "scalar" "raw" "org" "html" "latex") + ("replace" "silent") + ("output" "value")) + results (split-string (cdr pair))))) (:exports (setq exports (e-merge '(("code" "results" "both")) exports (split-string (cdr pair))))) diff --git a/org-babel.org b/org-babel.org index 4d81010b..c4ab68d7 100644 --- a/org-babel.org +++ b/org-babel.org @@ -218,68 +218,12 @@ would then be [[#sandbox][the sandbox]]. #+end_src -* Tasks [42/64] +* Tasks [43/63] ** TODO source-name visible in LaTeX and html exports Maybe this should be done in backend specific manners. The listings package may provide for naming a source-code block... -** STARTED new results types (org, html, latex) - Thanks to Tom Short for this recommendation. - - - raw or org :: in which case the results are implemented raw, unquoted - into the org-mode file. This would also handle links as - source block output. - - html :: the results are inserted inside of a #+BEGIN_HTML block - - latex :: the results are inserted inside of a #+BEGIN_LATEX block - - It might look like: -: #+begin_src R :session *R* :results org -: cat("***** This is a table\n") -: cat("| 1 | 2 | 3 |\n") -: cat("[[http://google.com][Google it here]]\n" -: #+end_src -: -: #+resname: -: ***** This is a table -: | 1 | 2 | 3 | -[[http://google.com][: Google it here]] - -We actually might want to remove the =#+resname= line if the results -type is org-mode, not sure... Either way I don't think there is a -good way to capture/remove org type results. - -*** raw - -Added a =raw= results header argument, which will insert the results -of a source-code block into an org buffer un-escaped. Also, if the -results look like a table, then the table will be aligned. - -#+srcname: raw-table-demonstration -#+begin_src ruby :results output raw - puts "| root | square |" - puts "|---" - 10.times do |n| - puts "| #{n} | #{n*n} |" - end -#+end_src - -#+resname: -| root | square | -|------+--------| -| 0 | 0 | -| 1 | 1 | -| 2 | 4 | -| 3 | 9 | -| 4 | 16 | -| 5 | 25 | -| 6 | 36 | -| 7 | 49 | -| 8 | 64 | -| 9 | 81 | -** PROPOSED raise elisp error when source-blocks return errors -Not sure how/if this would work, but it may be desirable. - ** PROPOSED allow `anonymous' function block with function call args? My question here is simply whether we're going to allow #+begin_src python(arg=ref) @@ -1248,6 +1192,99 @@ to the command if BUFF is not given.) 2) The function is called inside of a =write.table= function call writing the results to a table 3) The table is read using =org-table-import= +** DONE new results types (org, html, latex) + Thanks to Tom Short for this recommendation. + + - raw or org :: in which case the results are implemented raw, unquoted + into the org-mode file. This would also handle links as + source block output. + - html :: the results are inserted inside of a #+BEGIN_HTML block + - latex :: the results are inserted inside of a #+BEGIN_LATEX block + + It might look like: +: #+begin_src R :session *R* :results org +: cat("***** This is a table\n") +: cat("| 1 | 2 | 3 |\n") +: cat("[[http://google.com][Google it here]]\n" +: #+end_src +: +: #+resname: +: ***** This is a table +: | 1 | 2 | 3 | +[[http://google.com][: Google it here]] + +We actually might want to remove the =#+resname= line if the results +type is org-mode, not sure... Either way I don't think there is a +good way to capture/remove org type results. + +*** LaTeX +#+srcname: latex-results +#+begin_src emacs-lisp :results latex +"this should be inside of a LaTeX block" +#+end_src + +#+resname: +#+BEGIN_LaTeX +this should be inside of a LaTeX block +#+END_LaTeX + +*** Html +#+srcname: html-results +#+begin_src emacs-lisp :results html +"this should be inside of a HTML block + + + +and more + + + +is long" +#+end_src + +#+resname: +#+BEGIN_HTML +this should be inside of a HTML block + + + +and more + + + +is long +#+END_HTML + +*** raw + +Added a =raw= results header argument, which will insert the results +of a source-code block into an org buffer un-escaped. Also, if the +results look like a table, then the table will be aligned. + +#+srcname: raw-table-demonstration +#+begin_src ruby :results output raw + puts "| root | square |" + puts "|---" + 10.times do |n| + puts "| #{n} | #{n*n} |" + end +#+end_src + +#+resname: +| root | square | +|------+--------| +| 0 | 0 | +| 1 | 1 | +| 2 | 4 | +| 3 | 9 | +| 4 | 16 | +| 5 | 25 | +| 6 | 36 | +| 7 | 49 | +| 8 | 64 | +| 9 | 81 | + +Not sure how/if this would work, but it may be desirable. ** DONE org-bable-tangle: no default extension if one already exists ** DONE take default values for header args from properties Use file-wide and subtree wide properties to set default values for -- 2.11.4.GIT