ob-clojure.el 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. ;;; ob-clojure.el --- org-babel functions for clojure evaluation
  2. ;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.
  3. ;; Author: Joel Boehland, Eric Schulte
  4. ;; Keywords: literate programming, reproducible research
  5. ;; Homepage: http://orgmode.org
  6. ;; Version: 7.3
  7. ;; This file is part of GNU Emacs.
  8. ;; GNU Emacs is free software: you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation, either version 3 of the License, or
  11. ;; (at your option) any later version.
  12. ;; GNU Emacs is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;; GNU General Public License for more details.
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  18. ;;; Commentary:
  19. ;;; support for evaluating clojure code, relies on slime for all eval
  20. ;;; Requirements:
  21. ;;; A working clojure install. This also implies a working java executable
  22. ;;; - clojure-mode
  23. ;;; - slime
  24. ;;; - swank-clojure
  25. ;;; By far, the best way to install these components is by following
  26. ;;; the directions as set out by Phil Hagelberg (Technomancy) on the
  27. ;;; web page: http://technomancy.us/126
  28. ;;; Code:
  29. (require 'ob)
  30. (declare-function slime-eval "ext:slime" (sexp &optional package))
  31. (add-to-list 'org-babel-tangle-lang-exts '("clojure" . "clj"))
  32. (defvar org-babel-default-header-args:clojure '())
  33. (defun org-babel-expand-body:clojure (body params)
  34. "Expand BODY according to PARAMS, return the expanded body."
  35. (let* ((vars (mapcar #'cdr (org-babel-get-header params :var)))
  36. (print-level nil) (print-length nil)
  37. (body (if (> (length vars) 0)
  38. (concat "(let ["
  39. (mapconcat
  40. (lambda (var)
  41. (format "%S (quote %S)" (car var) (cdr var)))
  42. vars "\n ")
  43. "]\n" body ")")
  44. body)))
  45. body))
  46. (defun org-babel-execute:clojure (body params)
  47. "Execute a block of Clojure code with Babel."
  48. (require 'slime) (require 'swank-clojure)
  49. (with-temp-buffer
  50. (insert (org-babel-expand-body:clojure body params))
  51. (read
  52. (slime-eval
  53. `(swank:interactive-eval-region
  54. ,(buffer-substring-no-properties (point-min) (point-max)))
  55. (cdr (assoc :package params))))))
  56. (provide 'ob-clojure)
  57. ;; arch-tag: a43b33f2-653e-46b1-ac56-2805cf05b7d1
  58. ;;; ob-clojure.el ends here