More tweaks of skeleton documentation wrt \n behavior at bol/eol.
[bpt/emacs.git] / lisp / org / ob-plantuml.el
CommitLineData
afe98dfa
CD
1;;; ob-plantuml.el --- org-babel functions for plantuml evaluation
2
ba318903 3;; Copyright (C) 2010-2014 Free Software Foundation, Inc.
afe98dfa
CD
4
5;; Author: Zhang Weize
6;; Keywords: literate programming, reproducible research
7;; Homepage: http://orgmode.org
afe98dfa
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 plantuml script.
27;;
28;; Inspired by Ian Yang's org-export-blocks-format-plantuml
29;; http://www.emacswiki.org/emacs/org-export-blocks-format-plantuml.el
30
31;;; Requirements:
32
33;; plantuml | http://plantuml.sourceforge.net/
34;; plantuml.jar | `org-plantuml-jar-path' should point to the jar file
35
36;;; Code:
37(require 'ob)
afe98dfa
CD
38
39(defvar org-babel-default-header-args:plantuml
40 '((:results . "file") (:exports . "results"))
41 "Default arguments for evaluating a plantuml source block.")
42
73d3db82 43(defcustom org-plantuml-jar-path ""
afe98dfa
CD
44 "Path to the plantuml.jar file."
45 :group 'org-babel
372d7b21 46 :version "24.1"
afe98dfa
CD
47 :type 'string)
48
49(defun org-babel-execute:plantuml (body params)
50 "Execute a block of plantuml code with org-babel.
51This function is called by `org-babel-execute-src-block'."
52 (let* ((result-params (split-string (or (cdr (assoc :results params)) "")))
53 (out-file (or (cdr (assoc :file params))
8223b1d2 54 (error "PlantUML requires a \":file\" header argument")))
afe98dfa
CD
55 (cmdline (cdr (assoc :cmdline params)))
56 (in-file (org-babel-temp-file "plantuml-"))
2a88ee23 57 (java (or (cdr (assoc :java params)) ""))
73d3db82 58 (cmd (if (string= "" org-plantuml-jar-path)
afe98dfa 59 (error "`org-plantuml-jar-path' is not set")
2a88ee23 60 (concat "java " java " -jar "
afe98dfa
CD
61 (shell-quote-argument
62 (expand-file-name org-plantuml-jar-path))
63 (if (string= (file-name-extension out-file) "svg")
64 " -tsvg" "")
3ab2c837
BG
65 (if (string= (file-name-extension out-file) "eps")
66 " -teps" "")
afe98dfa
CD
67 " -p " cmdline " < "
68 (org-babel-process-file-name in-file)
69 " > "
70 (org-babel-process-file-name out-file)))))
71 (unless (file-exists-p org-plantuml-jar-path)
72 (error "Could not find plantuml.jar at %s" org-plantuml-jar-path))
73 (with-temp-file in-file (insert (concat "@startuml\n" body "\n@enduml")))
74 (message "%s" cmd) (org-babel-eval cmd "")
3ab2c837 75 nil)) ;; signal that output has already been written to file
afe98dfa
CD
76
77(defun org-babel-prep-session:plantuml (session params)
78 "Return an error because plantuml does not support sessions."
79 (error "Plantuml does not support sessions"))
80
81(provide 'ob-plantuml)
82
5b409b39 83
afe98dfa
CD
84
85;;; ob-plantuml.el ends here