ob-ditaa.el 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. ;;; ob-ditaa.el --- org-babel functions for ditaa evaluation
  2. ;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.
  3. ;; Author: 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. ;; Org-Babel support for evaluating ditaa source code.
  20. ;;
  21. ;; This differs from most standard languages in that
  22. ;;
  23. ;; 1) there is no such thing as a "session" in ditaa
  24. ;;
  25. ;; 2) we are generally only going to return results of type "file"
  26. ;;
  27. ;; 3) we are adding the "file" and "cmdline" header arguments
  28. ;;
  29. ;; 4) there are no variables (at least for now)
  30. ;;; Code:
  31. (require 'ob)
  32. (defvar org-babel-default-header-args:ditaa
  33. '((:results . "file") (:exports . "results"))
  34. "Default arguments for evaluating a ditaa source block.")
  35. (defvar org-ditaa-jar-path)
  36. (defun org-babel-execute:ditaa (body params)
  37. "Execute a block of Ditaa code with org-babel.
  38. This function is called by `org-babel-execute-src-block'."
  39. (let* ((result-params (split-string (or (cdr (assoc :results params)) "")))
  40. (out-file (cdr (assoc :file params)))
  41. (cmdline (cdr (assoc :cmdline params)))
  42. (in-file (org-babel-temp-file "ditaa-"))
  43. (cmd (concat "java -jar "
  44. (shell-quote-argument
  45. (expand-file-name org-ditaa-jar-path))
  46. " " cmdline
  47. " " (org-babel-process-file-name in-file)
  48. " " (org-babel-process-file-name out-file))))
  49. (unless (file-exists-p org-ditaa-jar-path)
  50. (error "Could not find ditaa.jar at %s" org-ditaa-jar-path))
  51. (with-temp-file in-file (insert body))
  52. (message cmd) (shell-command cmd)
  53. out-file))
  54. (defun org-babel-prep-session:ditaa (session params)
  55. "Return an error because ditaa does not support sessions."
  56. (error "Ditaa does not support sessions"))
  57. (provide 'ob-ditaa)
  58. ;; arch-tag: 492cd006-07d9-4fac-bef6-5bb60b48842e
  59. ;;; ob-ditaa.el ends here