1 ;;; ob-plantuml.el --- Babel Functions for Plantuml -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2010-2017 Free Software Foundation, Inc.
6 ;; Keywords: literate programming, reproducible research
7 ;; Homepage: http://orgmode.org
9 ;; This file is part of GNU Emacs.
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.
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.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
26 ;; Org-Babel support for evaluating plantuml script.
28 ;; Inspired by Ian Yang's org-export-blocks-format-plantuml
29 ;; http://www.emacswiki.org/emacs/org-export-blocks-format-plantuml.el
33 ;; plantuml | http://plantuml.sourceforge.net/
34 ;; plantuml.jar | `org-plantuml-jar-path' should point to the jar file
39 (defvar org-babel-default-header-args
:plantuml
40 '((:results .
"file") (:exports .
"results"))
41 "Default arguments for evaluating a plantuml source block.")
43 (defcustom org-plantuml-jar-path
""
44 "Path to the plantuml.jar file."
49 (defun org-babel-variable-assignments:plantuml
(params)
50 "Return a list of PlantUML statements assigning the block's variables.
51 PARAMS is a property list of source block parameters, which may
52 contain multiple entries for the key `:var'. `:var' entries in PARAMS
53 are expected to be scalar variables."
56 (format "!define %s %s"
58 (replace-regexp-in-string "\"" "" (cdr pair
))))
59 (org-babel--get-vars params
)))
61 (defun org-babel-plantuml-make-body (body params
)
62 "Return PlantUML input string.
63 BODY is the content of the source block and PARAMS is a property list
64 of source block parameters. This function relies on the
65 `org-babel-expand-body:generic' function to extract `:var' entries
66 from PARAMS and on the `org-babel-variable-assignments:plantuml'
67 function to convert variables to PlantUML assignments."
70 (org-babel-expand-body:generic
71 body params
(org-babel-variable-assignments:plantuml params
))
74 (defun org-babel-execute:plantuml
(body params
)
75 "Execute a block of plantuml code with org-babel.
76 This function is called by `org-babel-execute-src-block'."
77 (let* ((out-file (or (cdr (assq :file params
))
78 (error "PlantUML requires a \":file\" header argument")))
79 (cmdline (cdr (assq :cmdline params
)))
80 (in-file (org-babel-temp-file "plantuml-"))
81 (java (or (cdr (assq :java params
)) ""))
82 (full-body (org-babel-plantuml-make-body body params
))
83 (cmd (if (string= "" org-plantuml-jar-path
)
84 (error "`org-plantuml-jar-path' is not set")
85 (concat "java " java
" -jar "
87 (expand-file-name org-plantuml-jar-path
))
88 (if (string= (file-name-extension out-file
) "png")
90 (if (string= (file-name-extension out-file
) "svg")
92 (if (string= (file-name-extension out-file
) "eps")
94 (if (string= (file-name-extension out-file
) "pdf")
96 (if (string= (file-name-extension out-file
) "vdx")
98 (if (string= (file-name-extension out-file
) "xmi")
100 (if (string= (file-name-extension out-file
) "scxml")
102 (if (string= (file-name-extension out-file
) "html")
104 (if (string= (file-name-extension out-file
) "txt")
106 (if (string= (file-name-extension out-file
) "utxt")
109 (org-babel-process-file-name in-file
)
111 (org-babel-process-file-name out-file
)))))
112 (unless (file-exists-p org-plantuml-jar-path
)
113 (error "Could not find plantuml.jar at %s" org-plantuml-jar-path
))
114 (with-temp-file in-file
(insert full-body
))
115 (message "%s" cmd
) (org-babel-eval cmd
"")
116 nil
)) ;; signal that output has already been written to file
118 (defun org-babel-prep-session:plantuml
(_session _params
)
119 "Return an error because plantuml does not support sessions."
120 (error "Plantuml does not support sessions"))
122 (provide 'ob-plantuml
)
126 ;;; ob-plantuml.el ends here