ob-ditaa.el 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. ;;; ob-ditaa.el --- org-babel functions for ditaa evaluation
  2. ;; Copyright (C) 2009 Eric Schulte
  3. ;; Author: Eric Schulte
  4. ;; Keywords: literate programming, reproducible research
  5. ;; Homepage: http://orgmode.org
  6. ;; Version: 0.01
  7. ;;; License:
  8. ;; This program 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, or (at your option)
  11. ;; any later version.
  12. ;;
  13. ;; This program is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;;
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  20. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. ;; Boston, MA 02110-1301, USA.
  22. ;;; Commentary:
  23. ;; Org-Babel support for evaluating ditaa source code.
  24. ;;
  25. ;; This differs from most standard languages in that
  26. ;;
  27. ;; 1) there is no such thing as a "session" in ditaa
  28. ;;
  29. ;; 2) we are generally only going to return results of type "file"
  30. ;;
  31. ;; 3) we are adding the "file" and "cmdline" header arguments
  32. ;;
  33. ;; 4) there are no variables (at least for now)
  34. ;;; Code:
  35. (require 'ob)
  36. (defvar org-babel-default-header-args:ditaa
  37. '((:results . "file") (:exports . "results"))
  38. "Default arguments to use when evaluating a ditaa source block.")
  39. (defun org-babel-expand-body:ditaa (body params &optional processed-params)
  40. "Expand BODY according to PARAMS, return the expanded body." body)
  41. (defun org-babel-execute:ditaa (body params)
  42. "Execute a block of Ditaa code with org-babel. This function is
  43. called by `org-babel-execute-src-block'."
  44. (message "executing Ditaa source code block")
  45. (let ((result-params (split-string (or (cdr (assoc :results params)) "")))
  46. (out-file (cdr (assoc :file params)))
  47. (cmdline (cdr (assoc :cmdline params)))
  48. (in-file (make-temp-file "org-babel-ditaa")))
  49. (unless (file-exists-p org-ditaa-jar-path)
  50. (error (format "Could not find ditaa.jar at %s" org-ditaa-jar-path)))
  51. (with-temp-file in-file (insert body))
  52. (message (concat "java -jar " org-ditaa-jar-path " " cmdline " " in-file " " out-file))
  53. (shell-command (concat "java -jar " org-ditaa-jar-path " " cmdline " " in-file " " out-file))
  54. out-file))
  55. (defun org-babel-prep-session:ditaa (session params)
  56. "This function does nothing as ditaa does not support
  57. sessions."
  58. (error "Ditaa does not support sessions"))
  59. (provide 'ob-ditaa)
  60. ;;; ob-ditaa.el ends here