emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] ob-plantuml: Support for plantuml as well as the current java+jar solution
@ 2019-11-08 13:26 Terje Larsen
  2019-11-24  9:22 ` Nicolas Goaziou
  2020-02-12 17:30 ` Bastien
  0 siblings, 2 replies; 11+ messages in thread
From: Terje Larsen @ 2019-11-08 13:26 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 604 bytes --]

I have been missing this feature for a while and noticed it had already
been requested before (2014), See:
https://lists.gnu.org/archive/html/emacs-orgmode/2016-08/msg00105.html

With this patch you can switch between using jar or plantuml. The idea
partly stemmed from plantuml-mode and my inability to use the default
implementation. You can see the implementation for plantuml-mode here:
https://github.com/skuro/plantuml-mode/pull/102/files

My patch is available here:
https://code.orgmode.org/terlar/org-mode/commit/fbe245c0b09513ee5a6d3b189e112708b9d08da0

And also see attached within this mail.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ob-plantuml-Add-support-for-plantuml-executable.patch --]
[-- Type: text/x-patch, Size: 5657 bytes --]

From fbe245c0b09513ee5a6d3b189e112708b9d08da0 Mon Sep 17 00:00:00 2001
From: Terje Larsen <terlar@gmail.com>
Date: Fri, 8 Nov 2019 10:25:49 +0100
Subject: [PATCH] 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`.
---
 lisp/ob-plantuml.el | 94 +++++++++++++++++++++++++++++----------------
 1 file changed, 60 insertions(+), 34 deletions(-)

diff --git a/lisp/ob-plantuml.el b/lisp/ob-plantuml.el
index 09c9a3334..388d9f1b9 100644
--- a/lisp/ob-plantuml.el
+++ b/lisp/ob-plantuml.el
@@ -31,7 +31,7 @@
 ;;; Requirements:
 
 ;; 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:
 (require 'ob)
@@ -46,6 +46,31 @@
   :version "24.1"
   :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
+  :version "24.1"
+  :type 'symbol
+  :options '(jar plantuml))
+
+(defcustom org-plantuml-executable-path "plantuml"
+  "Path to the PlantUML executable."
+  :group 'org-babel
+  :version "24.1"
+  :type 'string)
+
+(defcustom org-plantuml-executable-args (list "-headless")
+  "The arguments passed to plantuml executable when executing PlantUML."
+  :group 'org-babel
+  :version "24.1"
+  :type '(repeat string))
+
 (defun org-babel-variable-assignments:plantuml (params)
   "Return a list of PlantUML statements assigning the block's variables.
 PARAMS is a property list of source block parameters, which may
@@ -82,40 +107,41 @@ This function is called by `org-babel-execute-src-block'."
 	 (cmdline (cdr (assq :cmdline params)))
 	 (in-file (org-babel-temp-file "plantuml-"))
 	 (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)
+				(t (cond ((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))
-	 (cmd (if (string= "" org-plantuml-jar-path)
-		  (error "`org-plantuml-jar-path' is not set")
-		(concat "java " java " -jar "
-			(shell-quote-argument
-			 (expand-file-name org-plantuml-jar-path))
-			(if (string= (file-name-extension out-file) "png")
-			    " -tpng" "")
-			(if (string= (file-name-extension out-file) "svg")
-			    " -tsvg" "")
-			(if (string= (file-name-extension out-file) "eps")
-			    " -teps" "")
-			(if (string= (file-name-extension out-file) "pdf")
-			    " -tpdf" "")
-			(if (string= (file-name-extension out-file) "tex")
-			    " -tlatex" "")
-			(if (string= (file-name-extension out-file) "vdx")
-			    " -tvdx" "")
-			(if (string= (file-name-extension out-file) "xmi")
-			    " -txmi" "")
-			(if (string= (file-name-extension out-file) "scxml")
-			    " -tscxml" "")
-			(if (string= (file-name-extension out-file) "html")
-			    " -thtml" "")
-			(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))
+	 (cmd (string-join
+	       (append
+		(list executable)
+		executable-args
+		(cond ((string= (file-name-extension out-file) "png") '("-tpng"))
+		      ((string= (file-name-extension out-file) "svg") '("-tsvg"))
+		      ((string= (file-name-extension out-file) "eps") '("-teps"))
+		      ((string= (file-name-extension out-file) "pdf") '("-tpdf"))
+		      ((string= (file-name-extension out-file) "tex") '("-tlatex"))
+		      ((string= (file-name-extension out-file) "vdx") '("-tvdx"))
+		      ((string= (file-name-extension out-file) "xmi") '("-txmi"))
+		      ((string= (file-name-extension out-file) "scxml") '("-tscxml"))
+		      ((string= (file-name-extension out-file) "html") '("-thtml"))
+		      ((string= (file-name-extension out-file) "txt") '("-ttxt"))
+		      ((string= (file-name-extension out-file) "utxt") '("-utxt")))
+		(list
+		 "-p"
+		 cmdline
+		 "<"
+		 (org-babel-process-file-name in-file)
+		 ">"
+		 (org-babel-process-file-name out-file)))
+	       " ")))
     (with-temp-file in-file (insert full-body))
     (message "%s" cmd) (org-babel-eval cmd "")
     nil)) ;; signal that output has already been written to file
-- 
2.23.0


[-- Attachment #3: Type: text/plain, Size: 54 bytes --]


Hope this helps someone.

Best regards,
Terje Larsen

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-09-04 10:39 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-08 13:26 [PATCH] ob-plantuml: Support for plantuml as well as the current java+jar solution Terje Larsen
2019-11-24  9:22 ` Nicolas Goaziou
2019-11-24 22:29   ` Terje Larsen
2020-02-12 17:30 ` Bastien
2020-02-16 13:20   ` Terje Larsen
2020-02-16 23:29     ` Bastien
2020-05-26 19:29       ` Terje Larsen
2020-06-01 13:59         ` Bastien
2020-06-09  6:53           ` Terje Larsen
2020-08-30 19:49             ` Terje Larsen
2020-09-04 10:38               ` Bastien

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).