ob-ditaa.el 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. ;;; ob-ditaa.el --- org-babel functions for ditaa evaluation
  2. ;; Copyright (C) 2009-2012 Free Software Foundation, Inc.
  3. ;; Author: Eric Schulte
  4. ;; Keywords: literate programming, reproducible research
  5. ;; Homepage: http://orgmode.org
  6. ;; This file is part of GNU Emacs.
  7. ;; GNU Emacs is free software: you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;; Org-Babel support for evaluating ditaa source code.
  19. ;;
  20. ;; This differs from most standard languages in that
  21. ;;
  22. ;; 1) there is no such thing as a "session" in ditaa
  23. ;;
  24. ;; 2) we are generally only going to return results of type "file"
  25. ;;
  26. ;; 3) we are adding the "file" and "cmdline" header arguments
  27. ;;
  28. ;; 4) there are no variables (at least for now)
  29. ;;; Code:
  30. (require 'ob)
  31. (defvar org-babel-default-header-args:ditaa
  32. '((:results . "file")
  33. (:exports . "results")
  34. (:java . "-Dfile.encoding=UTF-8"))
  35. "Default arguments for evaluating a ditaa source block.")
  36. (defcustom org-ditaa-jar-path nil
  37. "Path for the ditaa jar file."
  38. :group 'org-babel
  39. :type 'string)
  40. (defcustom org-ditaa-jar-option "-jar"
  41. "Option for the ditaa jar file.
  42. Do not leave leading or trailing spaces in this string."
  43. :group 'org-babel
  44. :version "24.1"
  45. :type 'string)
  46. (defun org-babel-execute:ditaa (body params)
  47. "Execute a block of Ditaa code with org-babel.
  48. This function is called by `org-babel-execute-src-block'."
  49. (let* ((result-params (split-string (or (cdr (assoc :results params)) "")))
  50. (out-file ((lambda (el)
  51. (or el
  52. (error
  53. "ditaa code block requires :file header argument")))
  54. (cdr (assoc :file params))))
  55. (cmdline (cdr (assoc :cmdline params)))
  56. (java (cdr (assoc :java params)))
  57. (in-file (org-babel-temp-file "ditaa-"))
  58. (cmd (concat "java " java " " org-ditaa-jar-option " "
  59. (shell-quote-argument
  60. (expand-file-name org-ditaa-jar-path))
  61. " " cmdline
  62. " " (org-babel-process-file-name in-file)
  63. " " (org-babel-process-file-name out-file))))
  64. (unless (file-exists-p org-ditaa-jar-path)
  65. (error "Could not find ditaa.jar at %s" org-ditaa-jar-path))
  66. (with-temp-file in-file (insert body))
  67. (message cmd) (shell-command cmd)
  68. nil)) ;; signal that output has already been written to file
  69. (defun org-babel-prep-session:ditaa (session params)
  70. "Return an error because ditaa does not support sessions."
  71. (error "Ditaa does not support sessions"))
  72. (provide 'ob-ditaa)
  73. ;;; ob-ditaa.el ends here