From 937e1aa981ffadf3c0051919a01d9b83bfa799ea Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Sun, 16 Aug 2009 21:14:22 -0600 Subject: [PATCH 01/14] now better at inserting wrapping comments, and using org-src-lang-modes --- lisp/org-babel-tangle.el | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lisp/org-babel-tangle.el b/lisp/org-babel-tangle.el index 3cf34e4f7..02f77a9a6 100644 --- a/lisp/org-babel-tangle.el +++ b/lisp/org-babel-tangle.el @@ -78,7 +78,11 @@ exported source code blocks by language." (lambda (by-lang) (let* ((lang (car by-lang)) (specs (cdr by-lang)) - (lang-f (intern (concat lang "-mode"))) + (lang-f (intern (concat + (or (plist-get org-src-lang-modes + (intern (concat ":" lang))) + lang) + "-mode"))) (lang-specs (cdr (assoc lang org-babel-tangle-langs))) (ext (first lang-specs)) (she-bang (second lang-specs)) @@ -108,7 +112,8 @@ exported source code blocks by language." (when she-bang (insert (concat she-bang "\n"))) (when commentable (comment-region - (point) (progn (insert "generated by org-babel-tangle") (point)))) + (point) (progn (insert "generated by org-babel-tangle") (point))) + (move-end-of-line nil)) (org-babel-spec-to-string spec) (append-to-file nil nil file-name)) ;; update counter @@ -161,7 +166,8 @@ form (link source-name params body)" (flet ((insert-comment (text) (when commentable - (comment-region (point) (progn (insert text) (point)))))) + (comment-region (point) (progn (insert text) (point))) + (move-end-of-line nil)))) (let ((link (first spec)) (source-name (second spec)) (body (fourth spec)) @@ -193,12 +199,14 @@ the source-code block which holds BODY." (setq new-body (concat new-body text)))) (with-temp-buffer (insert body) (goto-char (point-min)) - (funcall (intern (concat lang "-mode"))) + (funcall (intern (concat (or (plist-get org-src-lang-modes + (intern (concat ":" lang))) + lang) "-mode"))) (setq index (point)) (while (and (re-search-forward "<<\\(.+\\)>>" nil t)) (save-match-data (setf source-name (match-string 1))) ;; add interval to new-body - (goto-char (match-end 0)) + (goto-char (match-end 0)) (move-end-of-line nil) (nb-add (buffer-substring index (point))) (setq index (point)) ;; if found, add body of referenced source-block From 50e29c200d2a8f7c9038af4145e933437081e708 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Sun, 16 Aug 2009 21:17:16 -0600 Subject: [PATCH 02/14] recursively expanding nested noweb references --- lisp/org-babel-tangle.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lisp/org-babel-tangle.el b/lisp/org-babel-tangle.el index 02f77a9a6..6298ddbd3 100644 --- a/lisp/org-babel-tangle.el +++ b/lisp/org-babel-tangle.el @@ -216,7 +216,8 @@ the source-code block which holds BODY." (if point (save-excursion (goto-char point) - (concat "\n" (second (org-babel-get-src-block-info)))) + (concat "\n" (org-babel-expand-noweb-references + (org-babel-get-src-block-info)))) ""))))) (nb-add (buffer-substring index (point-max))))) new-body)) From 1626ebcdc813a72903a2ac28fb283ce61582f1d1 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Sun, 16 Aug 2009 22:29:33 -0600 Subject: [PATCH 03/14] TODO failing to write srcname to resname when evaluating a named block --- org-babel.org | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/org-babel.org b/org-babel.org index d4f555713..264fa495d 100644 --- a/org-babel.org +++ b/org-babel.org @@ -2875,7 +2875,8 @@ dot("$(2a,0)$",(2,0),N+E); *** DONE sh -* Bugs [37/41] +* Bugs [37/42] +** TODO failing to write srcname to resname when evaluating a named block ** DONE Python session evaluation bug The following block evaluates correctly with :session none (set :results to output), but fails with session-based evaluation From aad23f414075a70bddc7c6613507921358549112 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Mon, 17 Aug 2009 10:01:50 -0600 Subject: [PATCH 04/14] adding new bug (ob-exp.el is stripping indentation from source-code blocks) --- org-babel.org | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/org-babel.org b/org-babel.org index 264fa495d..7b7952668 100644 --- a/org-babel.org +++ b/org-babel.org @@ -2875,7 +2875,10 @@ dot("$(2a,0)$",(2,0),N+E); *** DONE sh -* Bugs [37/42] +* Bugs [37/43] +** TODO stripping indentation from source-code blocks +This is a problem in [[file:lisp/org-babel-exp.el][org-babel-exp.el]]. + ** TODO failing to write srcname to resname when evaluating a named block ** DONE Python session evaluation bug The following block evaluates correctly with :session none From 5ae3234bae6ac054fb7bae99419477d3a1a87a1d Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Mon, 17 Aug 2009 12:19:25 -0600 Subject: [PATCH 05/14] org-babel-exp is now using the newer org-exp-blocks.el block definition methods --- lisp/org-babel-exp.el | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lisp/org-babel-exp.el b/lisp/org-babel-exp.el index abf7d487a..f2060b773 100644 --- a/lisp/org-babel-exp.el +++ b/lisp/org-babel-exp.el @@ -31,16 +31,17 @@ ;;; Code: (require 'org-babel) (require 'org-exp-blocks) -(add-to-list 'org-export-blocks '(src org-babel-exp-src-blocks)) +(org-export-blocks-add-block '(src org-babel-exp-src-blocks nil)) (add-to-list 'org-export-interblocks '(src org-babel-exp-inline-src-blocks)) (defun org-babel-exp-src-blocks (body &rest headers) "Process src block for export. Depending on the 'export' headers argument in replace the source code block with... -both ---- the default, display the code and the results +both ---- display the code and the results -code ---- display the code inside the block but do not process +code ---- the default, display the code inside the block but do + not process results - process the block and replace it with the results of execution @@ -48,7 +49,7 @@ results - process the block and replace it with the results of none ----- do not display either code or results upon export" (interactive) (unless headers (error "org-babel can't process a source block without knowing the source code")) - (message "org-babel processing...") + (message "org-babel-exp processing...") (let ((lang (car headers)) (params (org-babel-parse-header-arguments (mapconcat #'identity (cdr headers) " ")))) (org-babel-exp-do-export lang body params))) @@ -70,12 +71,12 @@ options and are taken from `org-babel-defualt-inline-header-args'." (defun org-babel-exp-do-export (lang body params &optional inline) (case (intern (or (cdr (assoc :exports params)) "code")) - ('none "") - ('code (org-babel-exp-code body lang params inline)) - ('results (org-babel-exp-results body lang params inline)) - ('both (concat (org-babel-exp-code body lang params inline) - "\n\n" - (org-babel-exp-results body lang params inline))))) + ('none "") + ('code (org-babel-exp-code body lang params inline)) + ('results (org-babel-exp-results body lang params inline)) + ('both (concat (org-babel-exp-code body lang params inline) + "\n\n" + (org-babel-exp-results body lang params inline))))) (defun org-babel-exp-code (body lang params &optional inline) (if inline From 57a9464d3ab9b9d0cae6e3fe3deb9f6e7aa306d1 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Mon, 17 Aug 2009 14:39:34 -0600 Subject: [PATCH 06/14] added the SASS css generation language (see http://sass-lang.com/) --- lisp/langs/org-babel-sass.el | 68 ++++++++++++++++++++++++++++++++++++ org-babel.org | 19 +++++++++- 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 lisp/langs/org-babel-sass.el diff --git a/lisp/langs/org-babel-sass.el b/lisp/langs/org-babel-sass.el new file mode 100644 index 000000000..d20e91da8 --- /dev/null +++ b/lisp/langs/org-babel-sass.el @@ -0,0 +1,68 @@ +;;; org-babel-sass.el --- org-babel functions for the sass css generation language + +;; Copyright (C) 2009 Eric Schulte + +;; Author: Eric Schulte +;; Keywords: literate programming, reproducible research +;; Homepage: http://orgmode.org +;; Version: 0.01 + +;;; License: + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3, or (at your option) +;; any later version. +;; +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. + +;;; Commentary: + +;; For more information on sass see http://sass-lang.com/ +;; +;; This accepts a 'file' header argument which is the target of the +;; compiled sass. The default output type for sass evaluation is +;; either file (if a 'file' header argument was given) or scalar if no +;; such header argument was supplied. +;; +;; A 'cmdline' header argument can be supplied to pass arguments to +;; the sass command line. + +;;; Requirements: + +;; - sass-mode :: http://github.com/nex3/haml/blob/master/extra/sass-mode.el + +;;; Code: +(require 'org-babel) +(require 'sass-mode) + +(org-babel-add-interpreter "sass") + +(add-to-list 'org-babel-tangle-langs '("sass" "sass")) + +(defun org-babel-execute:sass (body params) + "Execute a block of Sass code with org-babel. This function is +called by `org-babel-execute-src-block'." + (message "executing Sass source code block") + (let* ((result-params (split-string (or (cdr (assoc :results params)) ""))) + (file (cdr (assoc :file params))) + (out-file (or file (make-temp-file "org-babel-sass-out"))) + (cmdline (cdr (assoc :cmdline params))) + (in-file (make-temp-file "org-babel-sass-in")) + (cmd (concat "sass " (or cmdline "") in-file " " out-file))) + (with-temp-file in-file (insert body)) (shell-command cmd) + (or file (with-temp-buffer (insert-file-contents out-file) (buffer-string))))) + +(defun org-babel-prep-session:sass (session params) + (error "Sass does not support sessions")) + +(provide 'org-babel-sass) +;;; org-babel-sass.el ends here diff --git a/org-babel.org b/org-babel.org index 7b7952668..0e803568d 100644 --- a/org-babel.org +++ b/org-babel.org @@ -2635,7 +2635,7 @@ This is currently working only with emacs lisp as in the following example in the [[* emacs lisp source reference][emacs lisp source reference]]. -** TODO Add languages [10/14] +** TODO Add languages [11/15] I'm sure there are many more that aren't listed here. Please add them, and bubble any that you particularly care about up to the top. @@ -2702,6 +2702,23 @@ Things left to do | "information_schema" | | "test" | +*** DONE SASS +Sass is a very nice extension of CSS, which is much nicer to read and +write (see [[http://sass-lang.com/][sass-lang]]). + +#+srcname: sass-example +#+begin_src sass :file stylesheet.css :results file + #me + position: absolute + top: 1em + left: 1em + .head + text-align: center +#+end_src + +#+resname: +[[file:stylesheet.css][stylesheet.css]] + *** DONE CSS trivial [[file:lisp/langs/org-babel-css.el][org-babel-css.el]] From 41f4401c84a25e281064b0cf1ae1b75f64581f17 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Mon, 17 Aug 2009 15:27:47 -0600 Subject: [PATCH 07/14] adding ob-sass to the optional languages in "getting started" configuration --- org-babel-worg.org | 1 + 1 file changed, 1 insertion(+) diff --git a/org-babel-worg.org b/org-babel-worg.org index 12c3ea71f..0b1cc427b 100644 --- a/org-babel-worg.org +++ b/org-babel-worg.org @@ -71,6 +71,7 @@ ;; (require 'org-babel-ocaml) ;; ocaml, and tuareg-mode ;; (require 'org-babel-python) ;; python, and python-mode ;; (require 'org-babel-ruby) ;; ruby, irb, ruby-mode, and inf-ruby mode + ;; (require 'org-babel-sass) ;; sass, sass-mode ;; (require 'org-babel-sql) ;; none ;; ;; Once you've activated languages, load the library of babel for From e56bed5fc8abf616b560fec78f4a1fe5e03ce7e6 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Tue, 18 Aug 2009 13:37:18 -0600 Subject: [PATCH 08/14] adding org-src-lang-modes as place holder until something comparable makes it's way into the org core --- lisp/org-babel-tangle.el | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lisp/org-babel-tangle.el b/lisp/org-babel-tangle.el index 6298ddbd3..b0450e62c 100644 --- a/lisp/org-babel-tangle.el +++ b/lisp/org-babel-tangle.el @@ -39,6 +39,15 @@ shebang(#!) line to use when writing out the language to file, and an optional flag indicating that the language is not commentable.") +;; This is just a place holder until this variable (or comparable) is +;; inserted into org-mode +(defcustom org-src-lang-modes + '(:ocaml "tuareg") + "Property list mapping languages to their major mode. +The key is the language name, the value is the string that should +be inserted as the name of the major mode." + :type 'plist) + (defun org-babel-load-file (file) "Load the contents of the Emacs Lisp source code blocks in the org-mode formatted FILE. This function will first export the From 9538905e57af9b59fdb3208f73773dbbb055d19a Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Tue, 18 Aug 2009 13:48:18 -0600 Subject: [PATCH 09/14] tiny tweak --- org-babel-worg.org | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org-babel-worg.org b/org-babel-worg.org index 0b1cc427b..aba1ac39e 100644 --- a/org-babel-worg.org +++ b/org-babel-worg.org @@ -354,7 +354,7 @@ to coexist and cooperate inside of a single document. :END: #+begin_quote -Let us change our traditional attitude to the con- struction of +Let us change our traditional attitude to the construction of programs: Instead of imagining that our main task is to instruct a /computer/ what to do, let us concentrate rather on explaining to /human beings/ what we want a computer to do. From 00ce2a5e25ace08e276232cee604383d52b50a47 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Tue, 18 Aug 2009 14:07:19 -0600 Subject: [PATCH 10/14] adding an elisp function for transposing a matrix --- library-of-babel.org | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/library-of-babel.org b/library-of-babel.org index 27fce86b6..6518c81c5 100644 --- a/library-of-babel.org +++ b/library-of-babel.org @@ -52,6 +52,24 @@ plot(data) ** Gnuplot +* Table/Matrix manipulation + +Elegant lisp code for transposing a matrix. + +#+tblname: transpose-example +| 1 | 2 | 3 | +| 4 | 5 | 6 | + +#+srcname: transpose +#+begin_src emacs-lisp :var table=transpose-example + (apply #'mapcar* #'list table) +#+end_src + +#+resname: +| 1 | 4 | +| 2 | 5 | +| 3 | 6 | + * Misc #+srcname: python-identity(a=1) #+begin_src python From cbdd953993ff5e083256cb0eca8d5f2dbe67658f Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Tue, 18 Aug 2009 17:22:16 -0600 Subject: [PATCH 11/14] DONE org-bable-tangle: no default extension if one already exists --- lisp/org-babel-tangle.el | 4 +++- org-babel.org | 13 ++----------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/lisp/org-babel-tangle.el b/lisp/org-babel-tangle.el index b0450e62c..f2043edea 100644 --- a/lisp/org-babel-tangle.el +++ b/lisp/org-babel-tangle.el @@ -106,7 +106,9 @@ exported source code blocks by language." ((> (length tangle) 0) tangle)) target-file)) (file-name (when base-name - (concat base-name "." ext)))) + (if (string= base-name + (file-name-sans-extension base-name)) + (concat base-name "." ext) base-name)))) ;; ;; debugging ;; (message "tangle=%S base-name=%S file-name=%S" ;; tangle base-name file-name) diff --git a/org-babel.org b/org-babel.org index 0e803568d..4d81010b5 100644 --- a/org-babel.org +++ b/org-babel.org @@ -218,8 +218,7 @@ would then be [[#sandbox][the sandbox]]. #+end_src -* Tasks [41/64] -** TODO org-bable-tangle: no default extension if one already exists +* Tasks [42/64] ** TODO source-name visible in LaTeX and html exports Maybe this should be done in backend specific manners. @@ -278,7 +277,6 @@ results look like a table, then the table will be aligned. | 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. @@ -323,7 +321,6 @@ but with preference given to update the source-code blocks timestamp. If the user edits the contents of a source-code block directly I can think of no efficient way of maintaining the timestamp. - ** TODO make tangle files read-only? With a file-local variable setting, yea that makes sense. Maybe the header should reference the related org-mode file. @@ -633,7 +630,6 @@ org-mode core **** DONE a hook called when the src edit buffer is created This should be implemented in the org-mode core - ** TODO resolve references to other org buffers/files This would allow source blocks to call upon tables, source-blocks, and results in other org buffers/files. @@ -721,7 +717,6 @@ above would have a couple of points in its favour: In interactive use we might want to allow the user to choose between screen and file output. In non-interactive use such as export, it would be file output (subject to the :exports directives). - ** TODO Finalise behaviour regarding vector/scalar output *** DONE Stop spaces causing vector output This simple example of multilingual chaining produces vector output if @@ -845,7 +840,6 @@ du -sc ~/* #+begin_src emacs-lisp :var sizes=sizes :results replace (mapcar #'car sizes) #+end_src - ** TODO command line execution Allow source code blocks to be called form the command line. This will be easy using the =sbe= function in [[file:lisp/org-babel-table.el][org-babel-table.el]]. @@ -878,7 +872,6 @@ we should color these blocks differently *** TODO refine html exportation should use a span class, and should show original source in tool-tip - ** TODO LoB: re-implement plotting and analysis functions from org-R I'll do this soon, now that we things are a bit more settled and we have column names in R. @@ -1064,7 +1057,6 @@ tabel Another example is in the [[*operations%20in%20on%20tables][grades example]]. - ** DEFERRED use textConnection to pass tsv to R? When passing args from the org buffer to R, the following route is used: arg in buffer -> elisp -> tsv on file -> data frame in R. I @@ -1179,7 +1171,6 @@ I have no idea how this could work... edit out some lines, and then convert it to org-babel format for posterity. Same for a shell session either in a *shell* buffer, or pasted from another terminal emulator. And python of course. - ** DEFERRED improve the source-block snippet any real improvement seems somewhat beyond the ability of yasnippet for now. @@ -1257,7 +1248,7 @@ 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 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 header args. From 6ca0934ead974bb301e9a2fffd7fa342a9571032 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Tue, 18 Aug 2009 17:55:10 -0600 Subject: [PATCH 12/14] 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 6ad06695c..b492df6d3 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 4d81010b5..c4ab68d7c 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 From 20dd65f2ddaa2a105e8bf1530463933ba467acb0 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Tue, 18 Aug 2009 17:55:59 -0600 Subject: [PATCH 13/14] DONE stripping indentation from source-code blocks this fix has been applied to org-mode --- org-babel.org | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/org-babel.org b/org-babel.org index c4ab68d7c..8b5e25688 100644 --- a/org-babel.org +++ b/org-babel.org @@ -2920,8 +2920,8 @@ dot("$(2a,0)$",(2,0),N+E); *** DONE sh -* Bugs [37/43] -** TODO stripping indentation from source-code blocks +* Bugs [38/43] +** DONE stripping indentation from source-code blocks This is a problem in [[file:lisp/org-babel-exp.el][org-babel-exp.el]]. ** TODO failing to write srcname to resname when evaluating a named block From 101a1141cdfdd02fb53f413bc5f6a0ca5071ffa7 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Tue, 18 Aug 2009 18:25:07 -0600 Subject: [PATCH 14/14] DONE failing to write srcname to resname when evaluating a named block --- lisp/org-babel.el | 24 +++++++++++++++++------- org-babel.org | 14 ++++++++++++-- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/lisp/org-babel.el b/lisp/org-babel.el index b492df6d3..5453ecfaa 100644 --- a/lisp/org-babel.el +++ b/lisp/org-babel.el @@ -272,10 +272,16 @@ concerned with creating elisp versions of results. " This function is analogous to org-babel-lob-get-info. For both functions, after they are called, (match-string 1) matches the -function name, and (match-string 2) matches the function +function name, and (match-string 3) matches the function arguments inside the parentheses. I think perhaps these functions should be renamed to bring out this similarity, perhaps involving -the word 'call'." +the word 'call'. + +Currently the function `org-babel-get-src-block-function-args' +relies on the match-data from a match in this function. I think +splitting a match and the use of it's data is bad form, and we +should re-work these two functions, perhaps combining them into +one function which returns more data than just the name. [Eric]" (let ((case-fold-search t) (head (org-babel-where-is-src-block-head))) (if head @@ -283,7 +289,10 @@ the word 'call'." (goto-char head) (if (save-excursion (forward-line -1) - (looking-at "#\\+srcname:[ \f\t\n\r\v]*\\([^ ()\f\t\n\r\v]+\\)\(\\(.*\\)\)")) + ;; the second match of this regexp is used later to + ;; find arguments in the "functional" style, where + ;; they are passed as part of the source name line + (looking-at "#\\+srcname:[ \f\t\n\r\v]*\\([^ ()\f\t\n\r\v]+\\)\\(\(\\(.*\\)\)\\|\\)")) (org-babel-clean-text-properties (match-string 1))))))) (defun org-babel-get-src-block-info () @@ -302,7 +311,7 @@ of the following form. (language body header-arguments-alist)" (defun org-babel-get-src-block-function-args () (when (org-babel-get-src-block-name) (mapcar (lambda (ref) (cons :var ref)) - (org-babel-ref-split-args (match-string 2))))) + (org-babel-ref-split-args (match-string 3))))) (defmacro org-babel-map-source-blocks (file &rest body) "Evaluate BODY forms on each source-block in FILE." @@ -434,7 +443,7 @@ buffer or nil if no such result exists." (goto-char (point-min)) (when (re-search-forward ;; ellow end-of-buffer in following regexp? (concat "#\\+resname:[ \t]*" (regexp-quote name) "[ \t\n\f\v\r]") nil t) - (move-beginning-of-line 1) (point)))) + (move-beginning-of-line 0) (point)))) (defun org-babel-where-is-src-block-result (&optional insert) "Return the point at the beginning of the result of the current @@ -447,7 +456,7 @@ line. If no result exists for this block then create a (name (if on-lob-line (org-babel-lob-get-info) (org-babel-get-src-block-name))) (head (unless on-lob-line (org-babel-where-is-src-block-head))) end) (when head (goto-char head)) - (or (and name (message name) (org-babel-find-named-result name)) + (or (and name (org-babel-find-named-result name)) (and (or on-lob-line (re-search-forward "#\\+end_src" nil t)) (progn (move-end-of-line 1) (if (eobp) (insert "\n") (forward-char 1)) @@ -455,7 +464,8 @@ line. If no result exists for this block then create a (or (progn ;; either an unnamed #+resname: line already exists (re-search-forward "[^ \f\t\n\r\v]" nil t) (move-beginning-of-line 1) (looking-at "#\\+resname:")) - (when insert ;; or (with optional insert) we need to back up and make one ourselves + ;; or (with optional insert) we need to back up and make one ourselves + (when insert (goto-char end) (open-line 2) (forward-char 1) (insert (concat "#+resname:" (if name (concat " " name)))) (move-beginning-of-line 1) t))) diff --git a/org-babel.org b/org-babel.org index 8b5e25688..93f9805db 100644 --- a/org-babel.org +++ b/org-babel.org @@ -2920,11 +2920,21 @@ dot("$(2a,0)$",(2,0),N+E); *** DONE sh -* Bugs [38/43] +* Bugs [39/43] ** DONE stripping indentation from source-code blocks This is a problem in [[file:lisp/org-babel-exp.el][org-babel-exp.el]]. -** TODO failing to write srcname to resname when evaluating a named block +** DONE failing to write srcname to resname when evaluating a named block + +#+srcname: please-name-my-result +#+begin_src emacs-lisp +"I'm the result" +#+end_src + +#+resname: please-name-my-result +: I'm the result + + ** DONE Python session evaluation bug The following block evaluates correctly with :session none (set :results to output), but fails with session-based evaluation