Merge from emacs-23; up to 2010-06-15T03:34:12Z!rgm@gnu.org.
[bpt/emacs.git] / lisp / org / ob-plantuml.el
CommitLineData
afe98dfa
CD
1;;; ob-plantuml.el --- org-babel functions for plantuml evaluation
2
73b0cd50 3;; Copyright (C) 2010-2011 Free Software Foundation, Inc.
afe98dfa
CD
4
5;; Author: Zhang Weize
6;; Keywords: literate programming, reproducible research
7;; Homepage: http://orgmode.org
acedf35c 8;; Version: 7.4
afe98dfa
CD
9
10;; This file is part of GNU Emacs.
11
12;; GNU Emacs is free software: you can redistribute it and/or modify
13;; it under the terms of the GNU General Public License as published by
14;; the Free Software Foundation, either version 3 of the License, or
15;; (at your option) any later version.
16
17;; GNU Emacs is distributed in the hope that it will be useful,
18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;; GNU General Public License for more details.
21
22;; You should have received a copy of the GNU General Public License
23;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24
25;;; Commentary:
26
27;; Org-Babel support for evaluating plantuml script.
28;;
29;; Inspired by Ian Yang's org-export-blocks-format-plantuml
30;; http://www.emacswiki.org/emacs/org-export-blocks-format-plantuml.el
31
32;;; Requirements:
33
34;; plantuml | http://plantuml.sourceforge.net/
35;; plantuml.jar | `org-plantuml-jar-path' should point to the jar file
36
37;;; Code:
38(require 'ob)
39(require 'ob-eval)
40
41(defvar org-babel-default-header-args:plantuml
42 '((:results . "file") (:exports . "results"))
43 "Default arguments for evaluating a plantuml source block.")
44
45(defcustom org-plantuml-jar-path nil
46 "Path to the plantuml.jar file."
47 :group 'org-babel
48 :type 'string)
49
50(defun org-babel-execute:plantuml (body params)
51 "Execute a block of plantuml code with org-babel.
52This function is called by `org-babel-execute-src-block'."
53 (let* ((result-params (split-string (or (cdr (assoc :results params)) "")))
54 (out-file (or (cdr (assoc :file params))
55 (error "plantuml requires a \":file\" header argument")))
56 (cmdline (cdr (assoc :cmdline params)))
57 (in-file (org-babel-temp-file "plantuml-"))
58 (cmd (if (not org-plantuml-jar-path)
59 (error "`org-plantuml-jar-path' is not set")
60 (concat "java -jar "
61 (shell-quote-argument
62 (expand-file-name org-plantuml-jar-path))
63 (if (string= (file-name-extension out-file) "svg")
64 " -tsvg" "")
65 " -p " cmdline " < "
66 (org-babel-process-file-name in-file)
67 " > "
68 (org-babel-process-file-name out-file)))))
69 (unless (file-exists-p org-plantuml-jar-path)
70 (error "Could not find plantuml.jar at %s" org-plantuml-jar-path))
71 (with-temp-file in-file (insert (concat "@startuml\n" body "\n@enduml")))
72 (message "%s" cmd) (org-babel-eval cmd "")
73 out-file))
74
75(defun org-babel-prep-session:plantuml (session params)
76 "Return an error because plantuml does not support sessions."
77 (error "Plantuml does not support sessions"))
78
79(provide 'ob-plantuml)
80
afe98dfa
CD
81
82;;; ob-plantuml.el ends here