ob-plantuml.el 3.0 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. (java (or (cdr (assoc :java params)) ""))
  45. (cmd (if (not org-plantuml-jar-path)
  46. (error "`org-plantuml-jar-path' is not set")
  47. (concat "java " java " -jar "
  48. (shell-quote-argument
  49. (expand-file-name org-plantuml-jar-path))
  50. (if (string= (file-name-extension out-file) "svg")
  51. " -tsvg" "")
  52. (if (string= (file-name-extension out-file) "eps")
  53. " -teps" "")
  54. " -p " cmdline " < "
  55. (org-babel-process-file-name in-file)
  56. " > "
  57. (org-babel-process-file-name out-file)))))
  58. (unless (file-exists-p org-plantuml-jar-path)
  59. (error "Could not find plantuml.jar at %s" org-plantuml-jar-path))
  60. (with-temp-file in-file (insert (concat "@startuml\n" body "\n@enduml")))
  61. (message "%s" cmd) (org-babel-eval cmd "")
  62. nil)) ;; signal that output has already been written to file
  63. (defun org-babel-prep-session:plantuml (session params)
  64. "Return an error because plantuml does not support sessions."
  65. (error "Plantuml does not support sessions"))
  66. (provide 'ob-plantuml)
  67. ;;; ob-plantuml.el ends here