Merge branch 'master' of git+ssh://repo.or.cz/srv/git/org-mode
[org-mode.git] / lisp / ob-plantuml.el
blobb1814cfe65a992d836535480d103ee00e984f52b
1 ;;; ob-plantuml.el --- org-babel functions for plantuml evaluation
3 ;; Copyright (C) 2010 Free Software Foundation, Inc.
5 ;; Author: Zhang Weize
6 ;; Keywords: literate programming, reproducible research
7 ;; Homepage: http://orgmode.org
8 ;; Version: 7.01trans
10 ;; This file is part of GNU Emacs.
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.
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.
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/>.
25 ;;; Commentary:
27 ;; Org-Babel support for evaluating plantuml script.
29 ;; Inspired by Ian Yang's org-export-blocks-format-plantuml
30 ;; http://www.emacswiki.org/emacs/org-export-blocks-format-plantuml.el
32 ;;; Requirements:
34 ;; plantuml | http://plantuml.sourceforge.net/
35 ;; plantuml.jar | `org-plantuml-jar-path' should point to the jar file
37 ;;; Code:
38 (require 'ob)
39 (require 'ob-eval)
41 (defvar org-babel-default-header-args:plantuml
42 '((:results . "file") (:exports . "results"))
43 "Default arguments for evaluating a plantuml source block.")
45 (defun org-babel-expand-body:plantuml (body params &optional processed-params)
46 "Expand BODY according to PARAMS, return the expanded body." body)
48 (defcustom org-plantuml-jar-path nil
49 "Path to the plantuml.jar file."
50 :group 'org-babel
51 :type 'string)
53 (defun org-babel-execute:plantuml (body params)
54 "Execute a block of plantuml code with org-babel.
55 This function is called by `org-babel-execute-src-block'."
56 (let* ((result-params (split-string (or (cdr (assoc :results params)) "")))
57 (out-file (or (cdr (assoc :file params))
58 (error "plantuml requires a \":file\" header argument")))
59 (cmdline (cdr (assoc :cmdline params)))
60 (in-file (org-babel-temp-file "plantuml-"))
61 (cmd (if (not org-plantuml-jar-path)
62 (error "`org-plantuml-jar-path' is not set")
63 (concat "java -jar "
64 (shell-quote-argument
65 (expand-file-name org-plantuml-jar-path))
66 " -p " cmdline " < "
67 (shell-quote-argument
68 (expand-file-name in-file))
69 " > "
70 (shell-quote-argument
71 (expand-file-name out-file))))))
72 (unless (file-exists-p org-plantuml-jar-path)
73 (error "Could not find plantuml.jar at %s" org-plantuml-jar-path))
74 (with-temp-file in-file (insert (concat "@startuml\n" body "\n@enduml")))
75 (message "%s" cmd) (org-babel-eval cmd "")
76 out-file))
78 (defun org-babel-prep-session:plantuml (session params)
79 "Return an error because plantuml does not support sessions."
80 (error "Plantuml does not support sessions"))
82 (provide 'ob-plantuml)
84 ;; arch-tag: 451f50c5-e779-407e-ad64-70e0e8f161d1
86 ;;; ob-plantuml.el ends here