emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Terje Larsen <terlar@gmail.com>
To: Bastien <bzg@gnu.org>
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH] ob-plantuml: Support for plantuml as well as the current java+jar solution
Date: Tue, 9 Jun 2020 08:53:02 +0200	[thread overview]
Message-ID: <CAGoWm-Z_-twhLNKn_PmZHYrdmFXEUn6VDCVsFxj99eMmOUowGQ@mail.gmail.com> (raw)
In-Reply-To: <87367ezy1s.fsf@gnu.org>

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

Thank you Bastien,

I didn't get what the updated patch with shorter lines meant, the only
thing I could see difference between that patch and my previous patch
was the line breaks using CR LF instead of LF. I generate my patch
with git format-patch

Here is the updated patch using mapconcat.

Best regards
Terje

On Mon, Jun 1, 2020 at 4:00 PM Bastien <bzg@gnu.org> wrote:
>
> Hello Terje,
>
> > I have now signed the FSF papers. Here is the updated patch on top of
> > current master.
>
> Great, thanks.
>
> > Let me know if all looks good or if I need to make further changes or
> > need to provide something else.
>
> It looks good -- here is an updated patch with shorter lines.
>
> The last change you need to make is to use mapconcat instead
> of string-join, which would require us to load subr-x.el.
>
> Once this is done I'll apply your patch.
>
> Thanks,
>
> --
>  Bastien



-- 
// Terje Larsen

[-- Attachment #2: 0001-ob-plantuml-Add-support-for-plantuml-executable.patch --]
[-- Type: text/x-patch, Size: 5987 bytes --]

From 5a26a6cf2783836bfa16e006607d06a911b97c56 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`.
---
 etc/ORG-NEWS        |  7 ++++
 lisp/ob-plantuml.el | 94 +++++++++++++++++++++++++++++----------------
 2 files changed, 67 insertions(+), 34 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index f313b07fe..93695dd01 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -255,6 +255,13 @@ explicitly:
 In situations where ~org-return~ calls ~newline~, multiple newlines
 can now be inserted with this prefix argument.
 
+*** =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
 *** ~org-table-header-line-mode~
 
diff --git a/lisp/ob-plantuml.el b/lisp/ob-plantuml.el
index 0e1d4eda2..4d10a68f4 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
+  :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)
   "Return a list of PlantUML statements assigning the block's variables.
 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)))
 	 (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)
+				((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 (mapconcat #'identity
+			 (append
+			  (list executable)
+			  executable-args
+			  (pcase (file-name-extension out-file)
+			    ("png" '("-tpng"))
+			    ("svg" '("-tsvg"))
+			    ("eps" '("-teps"))
+			    ("pdf" '("-tpdf"))
+			    ("tex" '("-tlatex"))
+			    ("vdx" '("-tvdx"))
+			    ("xmi" '("-txmi"))
+			    ("scxml" '("-tscxml"))
+			    ("html" '("-thtml"))
+			    ("txt" '("-ttxt"))
+			    ("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.26.2


  reply	other threads:[~2020-06-09  6:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-08 13:26 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 [this message]
2020-08-30 19:49             ` Terje Larsen
2020-09-04 10:38               ` Bastien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAGoWm-Z_-twhLNKn_PmZHYrdmFXEUn6VDCVsFxj99eMmOUowGQ@mail.gmail.com \
    --to=terlar@gmail.com \
    --cc=bzg@gnu.org \
    --cc=emacs-orgmode@gnu.org \
    --subject='Re: [PATCH] ob-plantuml: Support for plantuml as well as the current java+jar solution' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this 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).