Merge branch 'master' into max-sticky-agenda
[org-mode.git] / lisp / ob-ditaa.el
blobae7794b659c5699b083f3352330e99e469bc29c8
1 ;;; ob-ditaa.el --- org-babel functions for ditaa evaluation
3 ;; Copyright (C) 2009-2012 Free Software Foundation, Inc.
5 ;; Author: Eric Schulte
6 ;; Keywords: literate programming, reproducible research
7 ;; Homepage: http://orgmode.org
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;; Org-Babel support for evaluating ditaa source code.
28 ;; This differs from most standard languages in that
30 ;; 1) there is no such thing as a "session" in ditaa
32 ;; 2) we are generally only going to return results of type "file"
34 ;; 3) we are adding the "file" and "cmdline" header arguments
36 ;; 4) there are no variables (at least for now)
38 ;; 5) it depends on a variable defined in org-exp-blocks (namely
39 ;; `org-ditaa-jar-path') so be sure you have org-exp-blocks loaded
41 ;;; Code:
42 (require 'ob)
44 (defvar org-ditaa-jar-path) ;; provided by org-exp-blocks
46 (defvar org-babel-default-header-args:ditaa
47 '((:results . "file")
48 (:exports . "results")
49 (:java . "-Dfile.encoding=UTF-8"))
50 "Default arguments for evaluating a ditaa source block.")
52 (defcustom org-ditaa-jar-option "-jar"
53 "Option for the ditaa jar file.
54 Do not leave leading or trailing spaces in this string."
55 :group 'org-babel
56 :version "24.1"
57 :type 'string)
59 (defun org-babel-execute:ditaa (body params)
60 "Execute a block of Ditaa code with org-babel.
61 This function is called by `org-babel-execute-src-block'."
62 (let* ((result-params (split-string (or (cdr (assoc :results params)) "")))
63 (out-file ((lambda (el)
64 (or el
65 (error
66 "ditaa code block requires :file header argument")))
67 (cdr (assoc :file params))))
68 (cmdline (cdr (assoc :cmdline params)))
69 (java (cdr (assoc :java params)))
70 (in-file (org-babel-temp-file "ditaa-"))
71 (cmd (concat "java " java " " org-ditaa-jar-option " "
72 (shell-quote-argument
73 (expand-file-name org-ditaa-jar-path))
74 " " cmdline
75 " " (org-babel-process-file-name in-file)
76 " " (org-babel-process-file-name out-file))))
77 (unless (file-exists-p org-ditaa-jar-path)
78 (error "Could not find ditaa.jar at %s" org-ditaa-jar-path))
79 (with-temp-file in-file (insert body))
80 (message cmd) (shell-command cmd)
81 nil)) ;; signal that output has already been written to file
83 (defun org-babel-prep-session:ditaa (session params)
84 "Return an error because ditaa does not support sessions."
85 (error "Ditaa does not support sessions"))
87 (provide 'ob-ditaa)
91 ;;; ob-ditaa.el ends here