Browse Source

Merging master into results: required manual conflict resolution.

results had upgraded to using org-babel-merge-params (although
apparently not yet in org-babel-parse-inline-src-block-match).
Dan Davison 16 years ago
parent
commit
64a5c0e379
6 changed files with 199 additions and 42 deletions
  1. 70 0
      lisp/langs/org-babel-ditaa.el
  2. 52 0
      lisp/langs/org-babel-gnuplot.el
  3. 1 0
      lisp/org-babel-init.el
  4. 0 1
      lisp/org-babel-tangle.el
  5. 18 11
      lisp/org-babel.el
  6. 58 30
      org-babel.org

+ 70 - 0
lisp/langs/org-babel-ditaa.el

@@ -0,0 +1,70 @@
+;;; org-babel-ditaa.el --- org-babel functions for ditaa evaluation
+
+;; 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:
+
+;; Org-Babel support for evaluating ditaa source code.
+;;
+;; This differs from most standard languages in that
+;;
+;; 1) there is no such thing as a "session" in ditaa
+;;
+;; 2) we are generally only going to return results of type "file"
+;;
+;; 3) we are adding the "file" and "cmdline" header arguments
+;;
+;; 4) there are no variables (at least for now)
+
+;;; Code:
+(require 'org-babel)
+
+(org-babel-add-interpreter "ditaa")
+
+(add-to-list 'org-babel-tangle-langs '("ditaa" "ditaa"))
+
+(defvar org-babel-default-header-args:ditaa '((:results . "file"))
+  "Default arguments to use when evaluating a ditaa source block.")
+
+(defun org-babel-execute:ditaa (body params)
+  "Execute a block of Ditaa code with org-babel.  This function is
+called by `org-babel-execute-src-block'."
+  (message "executing Ditaa source code block")
+  (let ((result-params (split-string (or (cdr (assoc :results params)) "")))
+        (out-file (cdr (assoc :file params)))
+        (cmdline (cdr (assoc :cmdline params)))
+        (in-file (make-temp-file "org-babel-ditaa")))
+    (unless (file-exists-p org-ditaa-jar-path)
+      (error (format "Could not find ditaa.jar at %s" org-ditaa-jar-path)))
+    (with-temp-file in-file (insert body))
+    (message (concat "java -jar " org-ditaa-jar-path " " cmdline " " in-file " " out-file))
+    (shell-command (concat "java -jar " org-ditaa-jar-path " " cmdline " " in-file " " out-file))
+    out-file))
+
+(defun org-babel-prep-session:ditaa (session params)
+  (error "Ditaa does not support sessions"))
+
+(provide 'org-babel-ditaa)
+;;; org-babel-ditaa.el ends here

+ 52 - 0
lisp/langs/org-babel-gnuplot.el

@@ -0,0 +1,52 @@
+;;; org-babel-gnuplot.el --- org-babel functions for gnuplot evaluation
+
+;; 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:
+
+;; Org-Babel support for evaluating gnuplot source code.
+;;
+;; This differs from most standard languages in that
+;;
+;; 1) we are generally only going to return results of type "file"
+;;
+;; 2) we are adding the "file" and "cmdline" header arguments
+
+;;; Code:
+(require 'org-babel)
+
+(org-babel-add-interpreter "gnuplot")
+
+(add-to-list 'org-babel-tangle-langs '("gnuplot" "gnuplot"))
+
+(defun org-babel-execute:gnuplot (body params)
+  "Execute a block of Gnuplot code with org-babel.  This function is
+called by `org-babel-execute-src-block'."
+  (message "executing Gnuplot source code block"))
+
+(defun org-babel-prep-session:gnuplot (session params))
+
+(provide 'org-babel-gnuplot)
+;;; org-babel-gnuplot.el ends here

+ 1 - 0
lisp/org-babel-init.el

@@ -58,6 +58,7 @@
 (require 'org-babel-sh)
 (require 'org-babel-sh)
 (require 'org-babel-lisp)
 (require 'org-babel-lisp)
 (require 'org-babel-R)
 (require 'org-babel-R)
+(require 'org-babel-ditaa)
 
 
 (provide 'org-babel-init)
 (provide 'org-babel-init)
 ;;; org-babel-init.el ends here
 ;;; org-babel-init.el ends here

+ 0 - 1
lisp/org-babel-tangle.el

@@ -44,7 +44,6 @@ org-mode formatted FILE.  This function will first export the
 source code using `org-babel-tangle' and then load the resulting
 source code using `org-babel-tangle' and then load the resulting
 file using `load-file'."
 file using `load-file'."
   (let ((loadable-file (first (org-babel-tangle-file file "emacs-lisp"))))
   (let ((loadable-file (first (org-babel-tangle-file file "emacs-lisp"))))
-    (message "loading %s" loadable-file)
     (unless (file-exists-p loadable-file)
     (unless (file-exists-p loadable-file)
       (error "can't load file that doesn't exist"))
       (error "can't load file that doesn't exist"))
     (load-file loadable-file)
     (load-file loadable-file)

+ 18 - 11
lisp/org-babel.el

@@ -307,18 +307,25 @@ of the following form.  (language body header-arguments-alist)"
        (goto-char (match-end 0)))))
        (goto-char (match-end 0)))))
 
 
 (defun org-babel-parse-src-block-match ()
 (defun org-babel-parse-src-block-match ()
-  (list (org-babel-clean-text-properties (match-string 1))
-        (org-babel-strip-protective-commas (org-babel-clean-text-properties (match-string 4)))
-        (org-babel-merge-params org-babel-default-header-args
-				(org-babel-parse-header-arguments
-				 (org-babel-clean-text-properties (or (match-string 3) ""))))))
+(defun org-babel-parse-inline-src-block-match ()
+  (let* ((lang (org-babel-clean-text-properties (match-string 1)))
+         (lang-headers (intern (concat "org-babel-default-header-args:" lang))))
+    (list (org-babel-clean-text-properties (match-string 1))
+        (org-babel-strip-protective-comas (org-babel-clean-text-properties (match-string 4)))
+        (org-babel-merge-params
+         org-babel-default-header-args
+         (if (boundp lang-headers) (eval lang-headers) nil)
+         (org-babel-parse-header-arguments (org-babel-clean-text-properties (or (match-string 3) "")))))))
 
 
 (defun org-babel-parse-inline-src-block-match ()
 (defun org-babel-parse-inline-src-block-match ()
-  (list (org-babel-clean-text-properties (match-string 1))
-        (org-babel-strip-protective-commas (org-babel-clean-text-properties (match-string 4)))
-        (org-combine-plists org-babel-default-inline-header-args
-			    (org-babel-parse-header-arguments
-			     (org-babel-clean-text-properties (or (match-string 3) ""))))))
+  (let* ((lang (org-babel-clean-text-properties (match-string 1)))
+         (lang-headers (intern (concat "org-babel-default-header-args:" lang))))
+    (list lang
+          (org-babel-strip-protective-comas (org-babel-clean-text-properties (match-string 4)))
+          (org-combine-plists
+           org-babel-default-inline-header-args
+           (if (boundp lang-headers) (eval lang-headers) nil)
+           (org-babel-parse-header-arguments (org-babel-clean-text-properties (or (match-string 3) "")))))))
 
 
 (defun org-babel-parse-header-arguments (arg-string)
 (defun org-babel-parse-header-arguments (arg-string)
   "Parse a string of header arguments returning an alist."
   "Parse a string of header arguments returning an alist."
@@ -497,7 +504,7 @@ relies on `org-babel-insert-result'."
 RESULT, and the display being the `file-name-nondirectory' if
 RESULT, and the display being the `file-name-nondirectory' if
 non-nil."
 non-nil."
   (let ((name (file-name-nondirectory result)))
   (let ((name (file-name-nondirectory result)))
-    (concat "[[" result (if name (concat "][" name "]]") "]]"))))
+    (concat "[[file:" result (if name (concat "][" name "]]") "]]"))))
 
 
 (defun org-babel-examplize-region (beg end)
 (defun org-babel-examplize-region (beg end)
   "Comment out region using the ': ' org example quote."
   "Comment out region using the ': ' org example quote."

+ 58 - 30
org-babel.org

@@ -199,7 +199,6 @@ would then be [[#sandbox][the sandbox]].
 #+end_src
 #+end_src
 
 
 
 
-
 * Tasks [29/47]
 * Tasks [29/47]
 ** TODO make tangle files read-only?
 ** TODO make tangle files read-only?
    With a file-local variable setting?
    With a file-local variable setting?
@@ -848,6 +847,11 @@ $0
 
 
 waiting for guidance from those more familiar with yasnippets
 waiting for guidance from those more familiar with yasnippets
 ** DONE LoB: allow output in buffer
 ** DONE LoB: allow output in buffer
+** DONE allow default header arguments by language
+org-babel-default-header-args:lang-name
+
+An example of when this is useful is for languages which always return
+files as their results (e.g. [[*** ditaa][ditaa]], and [[*** gnuplot][gnuplot]]).
 ** DONE singe-function tangling and loading elisp from literate org-mode file [3/3]
 ** DONE singe-function tangling and loading elisp from literate org-mode file [3/3]
 
 
 This function should tangle the org-mode file for elisp, and then call
 This function should tangle the org-mode file for elisp, and then call
@@ -1948,7 +1952,7 @@ This is currently working only with emacs lisp as in the following
 example in the [[* emacs lisp source reference][emacs lisp source reference]].
 example in the [[* emacs lisp source reference][emacs lisp source reference]].
 
 
 
 
-** TODO Add languages [0/5]
+** TODO Add languages [1/6]
 I'm sure there are many more that aren't listed here.  Please add
 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.
 them, and bubble any that you particularly care about up to the top.
 
 
@@ -1961,9 +1965,33 @@ This could probably be added to [[file:lisp/org-babel-script.el][org-babel-scrip
 
 
 *** TODO java
 *** TODO java
 
 
-*** TODO ditaa
+*** DONE ditaa
 (see [[* file result types][file result types]])
 (see [[* file result types][file result types]])
 
 
+#+srcname: implementing-ditaa
+#+begin_src ditaa :results replace :file blue.png :cmdline -r
++---------+
+| cBLU    |
+|         |
+|    +----+
+|    |cPNK|
+|    |    |
++----+----+
+#+end_src
+
+#+resname: implementing-ditaa
+[[file:blue.png][blue.png]]
+
+*** STARTED gnuplot
+(see [[* file result types][file result types]])
+
+- a required =file= header argument
+- a =cmdline= header argument
+- to add variables
+  - scalar variables should be replaced in the body of the gnuplot code
+  - vector variables should be exported to tab-separated files, and
+    the variable names should be replaced with the path to the files
+
 *** TODO dot
 *** TODO dot
 (see [[* file result types][file result types]])
 (see [[* file result types][file result types]])
 
 
@@ -2466,47 +2494,47 @@ of these tests may fail.
 | basic evaluation        |                            |     |             |             | pass |
 | basic evaluation        |                            |     |             |             | pass |
 |-------------------------+----------------------------+-----+-------------+-------------+------|
 |-------------------------+----------------------------+-----+-------------+-------------+------|
 | emacs lisp              | basic-elisp                |     |           5 |           5 | pass |
 | emacs lisp              | basic-elisp                |     |           5 |           5 | pass |
-| shell                   | basic-shell                |     |           6 | 6           | pass |
-| ruby                    | basic-ruby                 |     |   org-babel | org-babel   | pass |
+| shell                   | basic-shell                |     |           6 |           6 | pass |
+| ruby                    | basic-ruby                 |     |   org-babel |   org-babel | pass |
 | python                  | basic-python               |     | hello world | hello world | pass |
 | python                  | basic-python               |     | hello world | hello world | pass |
-| R                       | basic-R                    |     |          13 | 13          | pass |
+| R                       | basic-R                    |     |          13 |          13 | pass |
 |-------------------------+----------------------------+-----+-------------+-------------+------|
 |-------------------------+----------------------------+-----+-------------+-------------+------|
 | tables                  |                            |     |             |             | pass |
 | tables                  |                            |     |             |             | pass |
 |-------------------------+----------------------------+-----+-------------+-------------+------|
 |-------------------------+----------------------------+-----+-------------+-------------+------|
-| emacs lisp              | table-elisp                |     |           3 | 3           | pass |
-| ruby                    | table-ruby                 |     |       1-2-3 | 1-2-3       | pass |
-| python                  | table-python               |     |           5 | 5           | pass |
-| R                       | table-R                    |     |         3.5 | 3.5         | pass |
+| emacs lisp              | table-elisp                |     |           3 |           3 | pass |
+| ruby                    | table-ruby                 |     |       1-2-3 |       1-2-3 | pass |
+| python                  | table-python               |     |           5 |           5 | pass |
+| R                       | table-R                    |     |         3.5 |         3.5 | pass |
 |-------------------------+----------------------------+-----+-------------+-------------+------|
 |-------------------------+----------------------------+-----+-------------+-------------+------|
 | source block references |                            |     |             |             | pass |
 | source block references |                            |     |             |             | pass |
 |-------------------------+----------------------------+-----+-------------+-------------+------|
 |-------------------------+----------------------------+-----+-------------+-------------+------|
-| all languages           | chained-ref-last           |     |       Array | Array       | pass |
+| all languages           | chained-ref-last           |     |       Array |       Array | pass |
 |-------------------------+----------------------------+-----+-------------+-------------+------|
 |-------------------------+----------------------------+-----+-------------+-------------+------|
 | source block functions  |                            |     |             |             | pass |
 | source block functions  |                            |     |             |             | pass |
 |-------------------------+----------------------------+-----+-------------+-------------+------|
 |-------------------------+----------------------------+-----+-------------+-------------+------|
-| emacs lisp              | defun-fibb                 |     |       fibbd | fibbd       | pass |
-| run over                | Fibonacci                  |   0 |           1 | 1           | pass |
-| a                       | Fibonacci                  |   1 |           1 | 1           | pass |
-| variety                 | Fibonacci                  |   2 |           2 | 2           | pass |
-| of                      | Fibonacci                  |   3 |           3 | 3           | pass |
-| different               | Fibonacci                  |   4 |           5 | 5           | pass |
-| arguments               | Fibonacci                  |   5 |           8 | 8           | pass |
+| emacs lisp              | defun-fibb                 |     |       fibbd |       fibbd | pass |
+| run over                | Fibonacci                  |   0 |           1 |           1 | pass |
+| a                       | Fibonacci                  |   1 |           1 |           1 | pass |
+| variety                 | Fibonacci                  |   2 |           2 |           2 | pass |
+| of                      | Fibonacci                  |   3 |           3 |           3 | pass |
+| different               | Fibonacci                  |   4 |           5 |           5 | pass |
+| arguments               | Fibonacci                  |   5 |           8 |           8 | pass |
 |-------------------------+----------------------------+-----+-------------+-------------+------|
 |-------------------------+----------------------------+-----+-------------+-------------+------|
 | bugs and tasks          |                            |     |             |             | pass |
 | bugs and tasks          |                            |     |             |             | pass |
-|-------------------------+----------------------------+-----+-------------+-------------+------| |  | 
-| simple ruby arrays      | ruby-array-test            |     |           3 | 3           |      |
-| R number evaluation     | bug-R-number-evaluation    |     |           2 |             |      |
-| multi-line ruby blocks  | multi-line-ruby-test       |     |           2 |             |      |
-| forcing vector results  | test-forced-vector-results |     |       Array |             |      |
 |-------------------------+----------------------------+-----+-------------+-------------+------|
 |-------------------------+----------------------------+-----+-------------+-------------+------|
-| sessions                |                            |     |             |             |      |
+| simple ruby arrays      | ruby-array-test            |     |           3 |           3 | pass |
+| R number evaluation     | bug-R-number-evaluation    |     |           2 |           2 | pass |
+| multi-line ruby blocks  | multi-line-ruby-test       |     |           2 |           2 | pass |
+| forcing vector results  | test-forced-vector-results |     |       Array |       Array | pass |
+|-------------------------+----------------------------+-----+-------------+-------------+------|
+| sessions                |                            |     |             |             | pass |
 |-------------------------+----------------------------+-----+-------------+-------------+------|
 |-------------------------+----------------------------+-----+-------------+-------------+------|
-| set ruby session        | set-ruby-session-var       |     |        :set |             |      |
-| get from ruby session   | get-ruby-session-var       |     |           3 |             |      |
-| set python session      | set-python-session-var     |     |         set |             |      |
-| get from python session | get-python-session-var     |     |           4 |             |      |
-| set R session           | set-R-session-var          |     |         set |             |      |
-| get from R session      | get-R-session-var          |     |           5 |             |      |
+| set ruby session        | set-ruby-session-var       |     |        :set |        :set | pass |
+| get from ruby session   | get-ruby-session-var       |     |           3 |           3 | pass |
+| set python session      | set-python-session-var     |     |         set |         set | pass |
+| get from python session | get-python-session-var     |     |           4 |           4 | pass |
+| set R session           | set-R-session-var          |     |         set |         set | pass |
+| get from R session      | get-R-session-var          |     |           5 |           5 | pass |
 #+TBLFM: $5='(if (= (length $3) 1) (progn (message (format "running %S" '(sbe $2 (n $3)))) (sbe $2 (n $3))) (sbe $2))::$6='(if (string= $4 $5) "pass" (format "expected %S but was %S" $4 $5))
 #+TBLFM: $5='(if (= (length $3) 1) (progn (message (format "running %S" '(sbe $2 (n $3)))) (sbe $2 (n $3))) (sbe $2))::$6='(if (string= $4 $5) "pass" (format "expected %S but was %S" $4 $5))
 
 
 ** basic tests
 ** basic tests