Skip to content

Instantly share code, notes, and snippets.

@hiredman
Created July 1, 2013 16:06
Show Gist options
  • Select an option

  • Save hiredman/5902187 to your computer and use it in GitHub Desktop.

Select an option

Save hiredman/5902187 to your computer and use it in GitHub Desktop.
clojure ob
(when (locate-file "ob" load-path load-suffixes)
(require 'ob)
(require 'ob-tangle)
(add-to-list 'org-babel-tangle-lang-exts '("clojure" . "clj"))
(org-babel-do-load-languages
'org-babel-load-languages
'((emacs-lisp . t)
(clojure . t)))
(defun org-babel-execute:clojure (body params)
"Evaluate a block of Clojure code with Babel."
(let* ((result (nrepl-send-string-sync body (nrepl-current-ns)))
(value (plist-get result :value))
(out (plist-get result :stdout))
(out (when out
(if (string= "\n" (substring out -1))
(substring out 0 -1)
out)))
(stdout (when out
(mapconcat (lambda (line)
(concat ";; " line))
(split-string out "\n")
"\n"))))
(concat stdout
(when (and stdout (not (string= "\n" (substring stdout -1))))
"\n")
";;=> " value)))
(provide 'ob-clojure)
(setq org-src-fontify-natively t)
(setq org-confirm-babel-evaluate nil))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment