org-capture: Fix :jump-+to-captured when `org-capture-bookmark' is nil
[org-mode.git] / lisp / ob-plantuml.el
blobe90021a52ae9600a3f0903ad49b6f543e77078ef
1 ;;; ob-plantuml.el --- Babel Functions for Plantuml -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2010-2017 Free Software Foundation, Inc.
5 ;; Author: Zhang Weize
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 <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
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
31 ;;; Requirements:
33 ;; plantuml | http://plantuml.sourceforge.net/
34 ;; plantuml.jar | `org-plantuml-jar-path' should point to the jar file
36 ;;; Code:
37 (require 'ob)
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."
45 :group 'org-babel
46 :version "24.1"
47 :type 'string)
49 (defun org-babel-execute:plantuml (body params)
50 "Execute a block of plantuml code with org-babel.
51 This function is called by `org-babel-execute-src-block'."
52 (let* ((out-file (or (cdr (assq :file params))
53 (error "PlantUML requires a \":file\" header argument")))
54 (cmdline (cdr (assq :cmdline params)))
55 (in-file (org-babel-temp-file "plantuml-"))
56 (java (or (cdr (assq :java params)) ""))
57 (cmd (if (string= "" org-plantuml-jar-path)
58 (error "`org-plantuml-jar-path' is not set")
59 (concat "java " java " -jar "
60 (shell-quote-argument
61 (expand-file-name org-plantuml-jar-path))
62 (if (string= (file-name-extension out-file) "png")
63 " -tpng" "")
64 (if (string= (file-name-extension out-file) "svg")
65 " -tsvg" "")
66 (if (string= (file-name-extension out-file) "eps")
67 " -teps" "")
68 (if (string= (file-name-extension out-file) "pdf")
69 " -tpdf" "")
70 (if (string= (file-name-extension out-file) "vdx")
71 " -tvdx" "")
72 (if (string= (file-name-extension out-file) "xmi")
73 " -txmi" "")
74 (if (string= (file-name-extension out-file) "scxml")
75 " -tscxml" "")
76 (if (string= (file-name-extension out-file) "html")
77 " -thtml" "")
78 (if (string= (file-name-extension out-file) "txt")
79 " -ttxt" "")
80 (if (string= (file-name-extension out-file) "utxt")
81 " -utxt" "")
82 " -p " cmdline " < "
83 (org-babel-process-file-name in-file)
84 " > "
85 (org-babel-process-file-name out-file)))))
86 (unless (file-exists-p org-plantuml-jar-path)
87 (error "Could not find plantuml.jar at %s" org-plantuml-jar-path))
88 (with-temp-file in-file (insert (concat "@startuml\n" body "\n@enduml")))
89 (message "%s" cmd) (org-babel-eval cmd "")
90 nil)) ;; signal that output has already been written to file
92 (defun org-babel-prep-session:plantuml (_session _params)
93 "Return an error because plantuml does not support sessions."
94 (error "Plantuml does not support sessions"))
96 (provide 'ob-plantuml)
100 ;;; ob-plantuml.el ends here