ob-plantuml: Add support for plantuml executable
* lisp/ob-plantuml (org-babel-variable-assignments:plantuml): Support using plantuml executable instead of jar. Some systems come with an executable for plantuml instead of a specific JAR file. This adds support for two different modes: - jar :: using java together with a JAR (previous behavior) - plantuml :: using a PlantUML executable The PlantUML executable can be configured via `org-plantuml-executable-path` and also the arguments that will be given via `org-plantuml-executable-args`.
This commit is contained in:
parent
416b97b5ca
commit
186371eac7
|
@ -266,6 +266,13 @@ can now be inserted with this prefix argument.
|
||||||
Source code block header argument =:file-mode= can set file
|
Source code block header argument =:file-mode= can set file
|
||||||
permissions if =:file= argument is provided.
|
permissions if =:file= argument is provided.
|
||||||
|
|
||||||
|
*** =ob-plantuml=: now supports using PlantUML executable to generate diagrams
|
||||||
|
|
||||||
|
Set =org-plantuml-exec-mode= to ='plantuml= in order to use the
|
||||||
|
executable instead of JAR. When using an executable it is also
|
||||||
|
possible to configure executable location as well as arguments via:
|
||||||
|
=org-plantuml-executable-path= and =org-plantuml-executable-args=.
|
||||||
|
|
||||||
** New commands
|
** New commands
|
||||||
*** ~org-table-header-line-mode~
|
*** ~org-table-header-line-mode~
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
;;; Requirements:
|
;;; Requirements:
|
||||||
|
|
||||||
;; plantuml | http://plantuml.sourceforge.net/
|
;; plantuml | http://plantuml.sourceforge.net/
|
||||||
;; plantuml.jar | `org-plantuml-jar-path' should point to the jar file
|
;; plantuml.jar | `org-plantuml-jar-path' should point to the jar file (when exec mode is `jar')
|
||||||
|
|
||||||
;;; Code:
|
;;; Code:
|
||||||
(require 'ob)
|
(require 'ob)
|
||||||
|
@ -46,6 +46,31 @@
|
||||||
:version "24.1"
|
:version "24.1"
|
||||||
:type 'string)
|
:type 'string)
|
||||||
|
|
||||||
|
(defcustom org-plantuml-exec-mode 'jar
|
||||||
|
"Method to use for PlantUML diagram generation.
|
||||||
|
`jar' means to use java together with the JAR.
|
||||||
|
The JAR can be configured via `org-plantuml-jar-path'.
|
||||||
|
|
||||||
|
`plantuml' means to use the PlantUML executable.
|
||||||
|
The executable can be configured via `org-plantuml-executable-path'.
|
||||||
|
You can also configure extra arguments via `org-plantuml-executable-args'."
|
||||||
|
:group 'org-babel
|
||||||
|
:package-version '(Org . "9.4")
|
||||||
|
:type 'symbol
|
||||||
|
:options '(jar plantuml))
|
||||||
|
|
||||||
|
(defcustom org-plantuml-executable-path "plantuml"
|
||||||
|
"File name of the PlantUML executable."
|
||||||
|
:group 'org-babel
|
||||||
|
:package-version '(Org . "9.4")
|
||||||
|
:type 'string)
|
||||||
|
|
||||||
|
(defcustom org-plantuml-executable-args (list "-headless")
|
||||||
|
"The arguments passed to plantuml executable when executing PlantUML."
|
||||||
|
:group 'org-babel
|
||||||
|
:package-version '(Org . "9.4")
|
||||||
|
:type '(repeat string))
|
||||||
|
|
||||||
(defun org-babel-variable-assignments:plantuml (params)
|
(defun org-babel-variable-assignments:plantuml (params)
|
||||||
"Return a list of PlantUML statements assigning the block's variables.
|
"Return a list of PlantUML statements assigning the block's variables.
|
||||||
PARAMS is a property list of source block parameters, which may
|
PARAMS is a property list of source block parameters, which may
|
||||||
|
@ -83,40 +108,41 @@ This function is called by `org-babel-execute-src-block'."
|
||||||
(cmdline (cdr (assq :cmdline params)))
|
(cmdline (cdr (assq :cmdline params)))
|
||||||
(in-file (org-babel-temp-file "plantuml-"))
|
(in-file (org-babel-temp-file "plantuml-"))
|
||||||
(java (or (cdr (assq :java params)) ""))
|
(java (or (cdr (assq :java params)) ""))
|
||||||
|
(executable (cond ((eq org-plantuml-exec-mode 'plantuml) org-plantuml-executable-path)
|
||||||
|
(t "java")))
|
||||||
|
(executable-args (cond ((eq org-plantuml-exec-mode 'plantuml) org-plantuml-executable-args)
|
||||||
|
((string= "" org-plantuml-jar-path)
|
||||||
|
(error "`org-plantuml-jar-path' is not set"))
|
||||||
|
((not (file-exists-p org-plantuml-jar-path))
|
||||||
|
(error "Could not find plantuml.jar at %s" org-plantuml-jar-path))
|
||||||
|
(t (list java
|
||||||
|
"-jar"
|
||||||
|
(shell-quote-argument (expand-file-name org-plantuml-jar-path))))))
|
||||||
(full-body (org-babel-plantuml-make-body body params))
|
(full-body (org-babel-plantuml-make-body body params))
|
||||||
(cmd (if (string= "" org-plantuml-jar-path)
|
(cmd (mapconcat #'identity
|
||||||
(error "`org-plantuml-jar-path' is not set")
|
(append
|
||||||
(concat "java " java " -jar "
|
(list executable)
|
||||||
(shell-quote-argument
|
executable-args
|
||||||
(expand-file-name org-plantuml-jar-path))
|
(pcase (file-name-extension out-file)
|
||||||
(if (string= (file-name-extension out-file) "png")
|
("png" '("-tpng"))
|
||||||
" -tpng" "")
|
("svg" '("-tsvg"))
|
||||||
(if (string= (file-name-extension out-file) "svg")
|
("eps" '("-teps"))
|
||||||
" -tsvg" "")
|
("pdf" '("-tpdf"))
|
||||||
(if (string= (file-name-extension out-file) "eps")
|
("tex" '("-tlatex"))
|
||||||
" -teps" "")
|
("vdx" '("-tvdx"))
|
||||||
(if (string= (file-name-extension out-file) "pdf")
|
("xmi" '("-txmi"))
|
||||||
" -tpdf" "")
|
("scxml" '("-tscxml"))
|
||||||
(if (string= (file-name-extension out-file) "tex")
|
("html" '("-thtml"))
|
||||||
" -tlatex" "")
|
("txt" '("-ttxt"))
|
||||||
(if (string= (file-name-extension out-file) "vdx")
|
("utxt" '("-utxt")))
|
||||||
" -tvdx" "")
|
(list
|
||||||
(if (string= (file-name-extension out-file) "xmi")
|
"-p"
|
||||||
" -txmi" "")
|
cmdline
|
||||||
(if (string= (file-name-extension out-file) "scxml")
|
"<"
|
||||||
" -tscxml" "")
|
(org-babel-process-file-name in-file)
|
||||||
(if (string= (file-name-extension out-file) "html")
|
">"
|
||||||
" -thtml" "")
|
(org-babel-process-file-name out-file)))
|
||||||
(if (string= (file-name-extension out-file) "txt")
|
" ")))
|
||||||
" -ttxt" "")
|
|
||||||
(if (string= (file-name-extension out-file) "utxt")
|
|
||||||
" -utxt" "")
|
|
||||||
" -p " cmdline " < "
|
|
||||||
(org-babel-process-file-name in-file)
|
|
||||||
" > "
|
|
||||||
(org-babel-process-file-name out-file)))))
|
|
||||||
(unless (file-exists-p org-plantuml-jar-path)
|
|
||||||
(error "Could not find plantuml.jar at %s" org-plantuml-jar-path))
|
|
||||||
(with-temp-file in-file (insert full-body))
|
(with-temp-file in-file (insert full-body))
|
||||||
(message "%s" cmd) (org-babel-eval cmd "")
|
(message "%s" cmd) (org-babel-eval cmd "")
|
||||||
nil)) ;; signal that output has already been written to file
|
nil)) ;; signal that output has already been written to file
|
||||||
|
|
Loading…
Reference in New Issue