ob-plantuml.el 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. ;;; ob-plantuml.el --- org-babel functions for plantuml evaluation
  2. ;; Copyright (C) 2010-2012 Free Software Foundation, Inc.
  3. ;; Author: Zhang Weize
  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 plantuml script.
  19. ;;
  20. ;; Inspired by Ian Yang's org-export-blocks-format-plantuml
  21. ;; http://www.emacswiki.org/emacs/org-export-blocks-format-plantuml.el
  22. ;;; Requirements:
  23. ;; plantuml | http://plantuml.sourceforge.net/
  24. ;; plantuml.jar | `org-plantuml-jar-path' should point to the jar file
  25. ;;; Code:
  26. (require 'ob)
  27. (require 'ob-eval)
  28. (defvar org-babel-default-header-args:plantuml
  29. '((:results . "file") (:exports . "results"))
  30. "Default arguments for evaluating a plantuml source block.")
  31. (defcustom org-plantuml-jar-path nil
  32. "Path to the plantuml.jar file."
  33. :group 'org-babel
  34. :version "24.1"
  35. :type 'string)
  36. (defun org-babel-execute:plantuml (body params)
  37. "Execute a block of plantuml 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 (or (cdr (assoc :file params))
  41. (error "plantuml requires a \":file\" header argument")))
  42. (cmdline (cdr (assoc :cmdline params)))
  43. (in-file (org-babel-temp-file "plantuml-"))
  44. (cmd (if (not org-plantuml-jar-path)
  45. (error "`org-plantuml-jar-path' is not set")
  46. (concat "java -jar "
  47. (shell-quote-argument
  48. (expand-file-name org-plantuml-jar-path))
  49. (if (string= (file-name-extension out-file) "svg")
  50. " -tsvg" "")
  51. (if (string= (file-name-extension out-file) "eps")
  52. " -teps" "")
  53. " -p " cmdline " < "
  54. (org-babel-process-file-name in-file)
  55. " > "
  56. (org-babel-process-file-name out-file)))))
  57. (unless (file-exists-p org-plantuml-jar-path)
  58. (error "Could not find plantuml.jar at %s" org-plantuml-jar-path))
  59. (with-temp-file in-file (insert (concat "@startuml\n" body "\n@enduml")))
  60. (message "%s" cmd) (org-babel-eval cmd "")
  61. nil)) ;; signal that output has already been written to file
  62. (defun org-babel-prep-session:plantuml (session params)
  63. "Return an error because plantuml does not support sessions."
  64. (error "Plantuml does not support sessions"))
  65. (provide 'ob-plantuml)
  66. ;;; ob-plantuml.el ends here