Commit | Line | Data |
---|---|---|
86fbb8ca CD |
1 | ;;; ob-ditaa.el --- org-babel functions for ditaa evaluation |
2 | ||
ba318903 | 3 | ;; Copyright (C) 2009-2014 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) | |
37 | ||
38 | ;;; Code: | |
39 | (require 'ob) | |
bdebdb64 | 40 | (require 'org-compat) |
86fbb8ca CD |
41 | |
42 | (defvar org-babel-default-header-args:ditaa | |
8223b1d2 BG |
43 | '((:results . "file") |
44 | (:exports . "results") | |
45 | (:java . "-Dfile.encoding=UTF-8")) | |
86fbb8ca CD |
46 | "Default arguments for evaluating a ditaa source block.") |
47 | ||
271672fa BG |
48 | (defcustom org-ditaa-jar-path (expand-file-name |
49 | "ditaa.jar" | |
50 | (file-name-as-directory | |
51 | (expand-file-name | |
52 | "scripts" | |
53 | (file-name-as-directory | |
54 | (expand-file-name | |
55 | "../contrib" | |
56 | (file-name-directory (org-find-library-dir "org"))))))) | |
57 | "Path to the ditaa jar executable." | |
58 | :group 'org-babel | |
59 | :type 'string) | |
60 | ||
61 | (defcustom org-babel-ditaa-java-cmd "java" | |
62 | "Java executable to use when evaluating ditaa blocks." | |
63 | :group 'org-babel | |
64 | :type 'string) | |
65 | ||
66 | (defcustom org-ditaa-eps-jar-path | |
67 | (expand-file-name "DitaaEps.jar" (file-name-directory org-ditaa-jar-path)) | |
68 | "Path to the DitaaEps.jar executable." | |
69 | :group 'org-babel | |
70 | :version "24.4" | |
71 | :package-version '(Org . "8.0") | |
72 | :type 'string) | |
73 | ||
8223b1d2 BG |
74 | (defcustom org-ditaa-jar-option "-jar" |
75 | "Option for the ditaa jar file. | |
76 | Do not leave leading or trailing spaces in this string." | |
77 | :group 'org-babel | |
78 | :version "24.1" | |
79 | :type 'string) | |
80 | ||
86fbb8ca CD |
81 | (defun org-babel-execute:ditaa (body params) |
82 | "Execute a block of Ditaa code with org-babel. | |
83 | This function is called by `org-babel-execute-src-block'." | |
afe98dfa | 84 | (let* ((result-params (split-string (or (cdr (assoc :results params)) ""))) |
666ffc7e SM |
85 | (out-file (let ((el (cdr (assoc :file params)))) |
86 | (or el | |
87 | (error | |
88 | "ditaa code block requires :file header argument")))) | |
afe98dfa | 89 | (cmdline (cdr (assoc :cmdline params))) |
3ab2c837 | 90 | (java (cdr (assoc :java params))) |
afe98dfa | 91 | (in-file (org-babel-temp-file "ditaa-")) |
271672fa BG |
92 | (eps (cdr (assoc :eps params))) |
93 | (cmd (concat org-babel-ditaa-java-cmd | |
94 | " " java " " org-ditaa-jar-option " " | |
afe98dfa | 95 | (shell-quote-argument |
271672fa BG |
96 | (expand-file-name |
97 | (if eps org-ditaa-eps-jar-path org-ditaa-jar-path))) | |
afe98dfa CD |
98 | " " cmdline |
99 | " " (org-babel-process-file-name in-file) | |
271672fa BG |
100 | " " (org-babel-process-file-name out-file))) |
101 | (pdf-cmd (when (and (or (string= (file-name-extension out-file) "pdf") | |
102 | (cdr (assoc :pdf params)))) | |
103 | (concat | |
104 | "epstopdf" | |
105 | " " (org-babel-process-file-name (concat in-file ".eps")) | |
106 | " -o=" (org-babel-process-file-name out-file))))) | |
86fbb8ca CD |
107 | (unless (file-exists-p org-ditaa-jar-path) |
108 | (error "Could not find ditaa.jar at %s" org-ditaa-jar-path)) | |
109 | (with-temp-file in-file (insert body)) | |
afe98dfa | 110 | (message cmd) (shell-command cmd) |
271672fa | 111 | (when pdf-cmd (message pdf-cmd) (shell-command pdf-cmd)) |
3ab2c837 | 112 | nil)) ;; signal that output has already been written to file |
86fbb8ca CD |
113 | |
114 | (defun org-babel-prep-session:ditaa (session params) | |
115 | "Return an error because ditaa does not support sessions." | |
116 | (error "Ditaa does not support sessions")) | |
117 | ||
118 | (provide 'ob-ditaa) | |
119 | ||
5b409b39 | 120 | |
86fbb8ca CD |
121 | |
122 | ;;; ob-ditaa.el ends here |