ob-plantuml.el 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. ;;; ob-plantuml.el --- org-babel functions for plantuml evaluation
  2. ;; Copyright (C) 2010 Free Software Foundation, Inc.
  3. ;; Author: Zhang Weize
  4. ;; Keywords: literate programming, reproducible research
  5. ;; Homepage: http://orgmode.org
  6. ;; Version: 7.01trans
  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 plantuml script.
  20. ;;
  21. ;; Inspired by Ian Yang's org-export-blocks-format-plantuml
  22. ;; http://www.emacswiki.org/emacs/org-export-blocks-format-plantuml.el
  23. ;;; Requirements:
  24. ;; plantuml | http://plantuml.sourceforge.net/
  25. ;; plantuml.jar | `org-plantuml-jar-path' should point to the jar file
  26. ;;; Code:
  27. (require 'ob)
  28. (require 'ob-eval)
  29. (defvar org-babel-default-header-args:plantuml
  30. '((:results . "file") (:exports . "results"))
  31. "Default arguments for evaluating a plantuml source block.")
  32. (defun org-babel-expand-body:plantuml (body params &optional processed-params)
  33. "Expand BODY according to PARAMS, return the expanded body." body)
  34. (defcustom org-plantuml-jar-path nil
  35. "Path to the plantuml.jar file."
  36. :group 'org-babel
  37. :type 'string)
  38. (defun org-babel-execute:plantuml (body params)
  39. "Execute a block of plantuml code with org-babel.
  40. This function is called by `org-babel-execute-src-block'."
  41. (let* ((result-params (split-string (or (cdr (assoc :results params)) "")))
  42. (out-file (cdr (assoc :file params)))
  43. (cmdline (cdr (assoc :cmdline params)))
  44. (in-file (org-babel-temp-file "plantuml-"))
  45. (cmd (if (not org-plantuml-jar-path)
  46. (error "`org-plantuml-jar-path' is not set")
  47. (concat "java -jar "
  48. (shell-quote-argument
  49. (expand-file-name org-plantuml-jar-path))
  50. " -p " cmdline " < "
  51. (shell-quote-argument
  52. (expand-file-name in-file))
  53. " > "
  54. (shell-quote-argument
  55. (expand-file-name out-file))))))
  56. (unless (file-exists-p org-plantuml-jar-path)
  57. (error "Could not find plantuml.jar at %s" org-plantuml-jar-path))
  58. (with-temp-file in-file (insert (concat "@startuml\n" body "\n@enduml")))
  59. (message "%s" cmd) (org-babel-eval cmd "")
  60. out-file))
  61. (defun org-babel-prep-session:plantuml (session params)
  62. "Return an error because plantuml does not support sessions."
  63. (error "Plantuml does not support sessions"))
  64. (provide 'ob-plantuml)
  65. ;; arch-tag: 451f50c5-e779-407e-ad64-70e0e8f161d1
  66. ;;; ob-plantuml.el ends here