Commit | Line | Data |
---|---|---|
86fbb8ca CD |
1 | ;;; ob-ditaa.el --- org-babel functions for ditaa evaluation |
2 | ||
ab422c4d | 3 | ;; Copyright (C) 2009-2013 Free Software Foundation, Inc. |
86fbb8ca CD |
4 | |
5 | ;; Author: Eric Schulte | |
6 | ;; Keywords: literate programming, reproducible research | |
7 | ;; Homepage: http://orgmode.org | |
86fbb8ca CD |
8 | |
9 | ;; This file is part of GNU Emacs. | |
10 | ||
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. | |
15 | ||
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. | |
20 | ||
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/>. | |
23 | ||
24 | ;;; Commentary: | |
25 | ||
26 | ;; Org-Babel support for evaluating ditaa source code. | |
27 | ;; | |
28 | ;; This differs from most standard languages in that | |
29 | ;; | |
30 | ;; 1) there is no such thing as a "session" in ditaa | |
31 | ;; | |
32 | ;; 2) we are generally only going to return results of type "file" | |
33 | ;; | |
34 | ;; 3) we are adding the "file" and "cmdline" header arguments | |
35 | ;; | |
36 | ;; 4) there are no variables (at least for now) | |
8223b1d2 BG |
37 | ;; |
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 | |
86fbb8ca CD |
40 | |
41 | ;;; Code: | |
42 | (require 'ob) | |
bdebdb64 | 43 | (require 'org-compat) |
86fbb8ca | 44 | |
8223b1d2 BG |
45 | (defvar org-ditaa-jar-path) ;; provided by org-exp-blocks |
46 | ||
86fbb8ca | 47 | (defvar org-babel-default-header-args:ditaa |
8223b1d2 BG |
48 | '((:results . "file") |
49 | (:exports . "results") | |
50 | (:java . "-Dfile.encoding=UTF-8")) | |
86fbb8ca CD |
51 | "Default arguments for evaluating a ditaa source block.") |
52 | ||
8223b1d2 BG |
53 | (defcustom org-ditaa-jar-option "-jar" |
54 | "Option for the ditaa jar file. | |
55 | Do not leave leading or trailing spaces in this string." | |
56 | :group 'org-babel | |
57 | :version "24.1" | |
58 | :type 'string) | |
59 | ||
86fbb8ca CD |
60 | (defun org-babel-execute:ditaa (body params) |
61 | "Execute a block of Ditaa code with org-babel. | |
62 | This function is called by `org-babel-execute-src-block'." | |
afe98dfa | 63 | (let* ((result-params (split-string (or (cdr (assoc :results params)) ""))) |
3ab2c837 BG |
64 | (out-file ((lambda (el) |
65 | (or el | |
66 | (error | |
67 | "ditaa code block requires :file header argument"))) | |
68 | (cdr (assoc :file params)))) | |
afe98dfa | 69 | (cmdline (cdr (assoc :cmdline params))) |
3ab2c837 | 70 | (java (cdr (assoc :java params))) |
afe98dfa | 71 | (in-file (org-babel-temp-file "ditaa-")) |
8223b1d2 | 72 | (cmd (concat "java " java " " org-ditaa-jar-option " " |
afe98dfa CD |
73 | (shell-quote-argument |
74 | (expand-file-name org-ditaa-jar-path)) | |
75 | " " cmdline | |
76 | " " (org-babel-process-file-name in-file) | |
77 | " " (org-babel-process-file-name out-file)))) | |
86fbb8ca CD |
78 | (unless (file-exists-p org-ditaa-jar-path) |
79 | (error "Could not find ditaa.jar at %s" org-ditaa-jar-path)) | |
80 | (with-temp-file in-file (insert body)) | |
afe98dfa | 81 | (message cmd) (shell-command cmd) |
3ab2c837 | 82 | nil)) ;; signal that output has already been written to file |
86fbb8ca CD |
83 | |
84 | (defun org-babel-prep-session:ditaa (session params) | |
85 | "Return an error because ditaa does not support sessions." | |
86 | (error "Ditaa does not support sessions")) | |
87 | ||
88 | (provide 'ob-ditaa) | |
89 | ||
5b409b39 | 90 | |
86fbb8ca CD |
91 | |
92 | ;;; ob-ditaa.el ends here |