emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Using org babel for generating ASCII art using PlantUML
@ 2013-03-09 21:37 Mats Kindahl
  2013-03-09 23:23 ` Eric Schulte
  2013-04-05 17:05 ` Bastien
  0 siblings, 2 replies; 6+ messages in thread
From: Mats Kindahl @ 2013-03-09 21:37 UTC (permalink / raw)
  To: emacs-orgmode

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

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

end of thread, other threads:[~2013-04-06 20:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-09 21:37 [PATCH] Using org babel for generating ASCII art using PlantUML Mats Kindahl
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

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