From mboxrd@z Thu Jan 1 00:00:00 1970 From: Terje Larsen Subject: Re: [PATCH] ob-plantuml: Support for plantuml as well as the current java+jar solution Date: Sun, 24 Nov 2019 23:29:32 +0100 Message-ID: <87h82sucvn.fsf@gmail.com> References: <874kzeijnz.fsf@gmail.com> <87k17p4oi5.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:55131) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iZ0O1-0005ZZ-Px for emacs-orgmode@gnu.org; Sun, 24 Nov 2019 17:29:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iZ0O0-00027F-5y for emacs-orgmode@gnu.org; Sun, 24 Nov 2019 17:29:45 -0500 Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]:39865) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iZ0Nz-00026B-QL for emacs-orgmode@gnu.org; Sun, 24 Nov 2019 17:29:44 -0500 Received: by mail-lf1-x133.google.com with SMTP id f18so9417677lfj.6 for ; Sun, 24 Nov 2019 14:29:43 -0800 (PST) Received: from beetle ([185.176.246.120]) by smtp.gmail.com with ESMTPSA id 129sm2526647lfj.86.2019.11.24.14.29.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Nov 2019 14:29:40 -0800 (PST) In-Reply-To: <87k17p4oi5.fsf@nicolasgoaziou.fr> (Nicolas Goaziou's message of "Sun, 24 Nov 2019 10:22:58 +0100") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Nicolas Goaziou writes: Hello and thank you for the feedback, made me learn a few things and make some improvements. I have made the suggested changes (see attachment). --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-ob-plantuml-Add-support-for-plantuml-executable.patch Content-Description: Updated version of ob-plantuml patch >From e3c46993714234c0290f3100683cbec3c0d5f056 Mon Sep 17 00:00:00 2001 From: Terje Larsen 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 | 5 +++ lisp/ob-plantuml.el | 94 +++++++++++++++++++++++++++++---------------- 2 files changed, 65 insertions(+), 34 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 689a07871..2cce7dd41 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -19,6 +19,11 @@ just as if it was at outline level 0. Inheritance for properties will work also for this level. In other words; defining things in a property drawer before the first headline will make them "inheritable" for all headlines. +*** Babel +**** 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. Executable mode can be configured via: +=org-plantuml-executable-path= and =org-plantuml-executable-args=. * Version 9.3 diff --git a/lisp/ob-plantuml.el b/lisp/ob-plantuml.el index 09c9a3334..aeea1802f 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 @@ -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) + ((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 + (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.24.0 --=-=-= Content-Type: text/plain > Could you rebase it on top of "next" branch and add an entry in > ORG-NEWS, section "Org 9.4" about it? > I didn't find a section Org 9.4, so I put it under the section Version Next. Thank you for your help. Best regards, Terje --=-=-=--