emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Mats Kindahl <mats.kindahl@oracle.com>
To: emacs-orgmode@gnu.org
Subject: [PATCH] Using org babel for generating ASCII art using PlantUML
Date: Sat, 09 Mar 2013 22:37:01 +0100	[thread overview]
Message-ID: <513BAB7D.1000603@oracle.com> (raw)

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

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


[-- Attachment #2: plantuml-ascii-art.diff --]
[-- Type: text/x-diff, Size: 2655 bytes --]

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."

             reply	other threads:[~2013-03-09 21:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-09 21:37 Mats Kindahl [this message]
2013-03-09 23:23 ` Eric Schulte
2013-03-10  7:13   ` Mats Kindahl
2013-04-05 17:05 ` Bastien
2013-04-05 18:57   ` Mats Kindahl
2013-04-06 20:37     ` 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=513BAB7D.1000603@oracle.com \
    --to=mats.kindahl@oracle.com \
    --cc=emacs-orgmode@gnu.org \
    --subject='Re: [PATCH] Using org babel for generating ASCII art using PlantUML' \
    /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).