From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mats Kindahl Subject: [PATCH] Using org babel for generating ASCII art using PlantUML Date: Sat, 09 Mar 2013 22:37:01 +0100 Message-ID: <513BAB7D.1000603@oracle.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------050407050405020009010209" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:37322) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UERS2-00036x-B4 for emacs-orgmode@gnu.org; Sat, 09 Mar 2013 16:37:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UERS0-00052E-Uv for emacs-orgmode@gnu.org; Sat, 09 Mar 2013 16:37:10 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:19369) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UERS0-0004z9-Op for emacs-orgmode@gnu.org; Sat, 09 Mar 2013 16:37:08 -0500 Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r29Lb6PD025419 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sat, 9 Mar 2013 21:37:06 GMT Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r29Lb5EH022047 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sat, 9 Mar 2013 21:37:06 GMT Received: from abhmt113.oracle.com (abhmt113.oracle.com [141.146.116.65]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id r29Lb503029612 for ; Sat, 9 Mar 2013 15:37:05 -0600 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-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org This is a multi-part message in MIME format. --------------050407050405020009010209 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Hi all, I find the PlantUML support very useful to generate diagrams when presenting designs, but unfortunately, I quite frequently have to send simple descriptions requiring ASCII only. Since PlantUML support generation of ASCII-art diagrams, I updated the org babel PlantUML support to generate ASCII art in place when no :file parameter is provided. Patch is attached. Just my few cents, Mats Kindahl -- Senior Principal Software Developer Oracle, MySQL Department --------------050407050405020009010209 Content-Type: text/x-diff; name="plantuml-ascii-art.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="plantuml-ascii-art.diff" diff --git a/lisp/ob-plantuml.el b/lisp/ob-plantuml.el index c17d444..b4e2b01 100644 --- a/lisp/ob-plantuml.el +++ b/lisp/ob-plantuml.el @@ -37,7 +37,7 @@ (require 'ob) (defvar org-babel-default-header-args:plantuml - '((:results . "file") (:exports . "results")) + '((:exports . "results")) "Default arguments for evaluating a plantuml source block.") (defcustom org-plantuml-jar-path nil @@ -46,33 +46,43 @@ :version "24.1" :type 'string) +(defvar org-babel-plantuml-ext-alist + '(("svg" . "-tsvg") + ("eps" . "-teps") + ("atxt" . "-txt") + ("png" . "")) + "Switch to use for different file name extensions.") + +(defun org-babel-plantuml-switch (filename) + (concat " " + (if filename + (let ((ext (file-name-extension filename))) + (or (cdr (assoc ext org-babel-plantuml-ext-alist)) + (error "Unrecognized file name extension '%s'" ext))) + "-txt"))) + (defun org-babel-execute:plantuml (body params) "Execute a block of plantuml code with org-babel. This function is called by `org-babel-execute-src-block'." (let* ((result-params (split-string (or (cdr (assoc :results params)) ""))) - (out-file (or (cdr (assoc :file params)) - (error "PlantUML requires a \":file\" header argument"))) + (out-file (cdr (assoc :file params))) (cmdline (cdr (assoc :cmdline params))) - (in-file (org-babel-temp-file "plantuml-")) (java (or (cdr (assoc :java params)) "")) (cmd (if (not 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) "svg") - " -tsvg" "") - (if (string= (file-name-extension out-file) "eps") - " -teps" "") - " -p " cmdline " < " - (org-babel-process-file-name in-file) - " > " - (org-babel-process-file-name out-file))))) + (org-babel-plantuml-switch out-file) + " -p " cmdline + (if out-file + (concat " > " (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 (concat "@startuml\n" body "\n@enduml"))) - (message "%s" cmd) (org-babel-eval cmd "") - nil)) ;; signal that output has already been written to file + (message "%s" cmd) + (let ((result (org-babel-eval cmd (concat "@startuml\n" body "\n@enduml")))) + (if (string= result "") nil result)))) (defun org-babel-prep-session:plantuml (session params) "Return an error because plantuml does not support sessions." --------------050407050405020009010209--