emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Robert McIntyre <rlm@mit.edu>
To: emacs-orgmode@gnu.org
Subject: [PATCH] Adding support for :results output for clojure src blocks.
Date: Tue, 12 Jul 2011 23:56:56 -0400	[thread overview]
Message-ID: <CABqqNd0f8R1mnK-EqsFasppguBU5ygy2iGTCYULhyT8tqTC7YA@mail.gmail.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 223 bytes --]

This small patch handles :results output for clojure src blocks by using
clojure's with-out-str function.

Please let me know if I've done anything wrong as this is my first patch to
org-mode.

sincerely,
--Robert McIntyre

[-- Attachment #1.2: Type: text/html, Size: 251 bytes --]

[-- Attachment #2: ob-clojure.el.diff --]
[-- Type: text/x-patch, Size: 1300 bytes --]

diff --git a/lisp/ob-clojure.el b/lisp/ob-clojure.el
index a72b14c..00013b8 100644
--- a/lisp/ob-clojure.el
+++ b/lisp/ob-clojure.el
@@ -62,16 +62,22 @@
 			     vars "\n      ")
 			    "]\n" body ")")
 		  body))))
-    (if (or (member "code" result-params)
-	    (member "pp" result-params))
-	(format
-	 (concat
-	  "(let [org-mode-print-catcher (java.io.StringWriter.)] "
-	  "(clojure.pprint/with-pprint-dispatch clojure.pprint/%s-dispatch "
-	  "(clojure.pprint/pprint (do %s) org-mode-print-catcher) "
-	  "(str org-mode-print-catcher)))")
-	 (if (member "code" result-params) "code" "simple") body)
-      body)))
+    (cond 
+     ((or (member "code" result-params)
+	  (member "pp" result-params))
+      (format
+       (concat
+	"(let [org-mode-print-catcher (java.io.StringWriter.)] "
+	"(clojure.pprint/with-pprint-dispatch clojure.pprint/%s-dispatch "
+	"(clojure.pprint/pprint (do %s) org-mode-print-catcher) "
+	"(str org-mode-print-catcher)))")
+       (if (member "code" result-params) "code" "simple") body))
+     ;; if (:results output), collect printed output 
+     ((member "output" result-params)
+      (format "(clojure.core/with-out-str %s)" body))
+     (t body))))
+
+
 
 (defun org-babel-execute:clojure (body params)
   "Execute a block of Clojure code with Babel."

             reply	other threads:[~2011-07-13  3:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-13  3:56 Robert McIntyre [this message]
2011-07-13  9:00 ` [PATCH] Adding support for :results output for clojure src blocks Bastien
2011-07-13 17:48   ` Eric Schulte
2011-07-14 15:49     ` Bastien
2011-07-16 13:09     ` 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=CABqqNd0f8R1mnK-EqsFasppguBU5ygy2iGTCYULhyT8tqTC7YA@mail.gmail.com \
    --to=rlm@mit.edu \
    --cc=emacs-orgmode@gnu.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).