Revert "Fix org-store-link in GNUS messages with date"
[org-mode.git] / lisp / ob-plantuml.el
blob5159f6aada304a13d26e033d84c148a1ea10ff0c
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.4
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 (defcustom org-plantuml-jar-path nil
46 "Path to the plantuml.jar file."
47 :group 'org-babel
48 :type 'string)
50 (defun org-babel-execute:plantuml (body params)
51 "Execute a block of plantuml code with org-babel.
52 This 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 nil)) ;; signal that output has already been written to file
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"))
79 (provide 'ob-plantuml)
81 ;; arch-tag: 451f50c5-e779-407e-ad64-70e0e8f161d1
83 ;;; ob-plantuml.el ends here