ob-mscgen.el 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. ;;; ob-msc.el --- org-babel functions for mscgen evaluation
  2. ;; Copyright (C) 2010-2012 Free Software Foundation, Inc.
  3. ;; Author: Juan Pechiar
  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. ;;
  19. ;; This software provides EMACS org-babel export support for message
  20. ;; sequence charts. The mscgen utility is used for processing the
  21. ;; sequence definition, and must therefore be installed in the system.
  22. ;;
  23. ;; Mscgen is available and documented at
  24. ;; http://www.mcternan.me.uk/mscgen/index.html
  25. ;;
  26. ;; This code is directly inspired by Eric Schulte's ob-dot.el
  27. ;;
  28. ;; Example:
  29. ;;
  30. ;; #+begin_src mscgen :file example.png
  31. ;; msc {
  32. ;; A,B;
  33. ;; A -> B [ label = "send message" ];
  34. ;; A <- B [ label = "get answer" ];
  35. ;; }
  36. ;; #+end_src
  37. ;;
  38. ;; Header for alternative file type:
  39. ;;
  40. ;; #+begin_src mscgen :file ex2.svg :filetype svg
  41. ;; This differs from most standard languages in that
  42. ;;
  43. ;; 1) there is no such thing as a "session" in mscgen
  44. ;; 2) we are generally only going to return results of type "file"
  45. ;; 3) we are adding the "file" and "filetype" header arguments
  46. ;; 4) there are no variables
  47. ;;; Code:
  48. (require 'ob)
  49. (require 'ob-eval)
  50. (defvar org-babel-default-header-args:mscgen
  51. '((:results . "file") (:exports . "results"))
  52. "Default arguments to use when evaluating a mscgen source block.")
  53. (defun org-babel-execute:mscgen (body params)
  54. "Execute a block of Mscgen code with Babel.
  55. This function is called by `org-babel-execute-src-block'.
  56. Default filetype is png. Modify by setting :filetype parameter to
  57. mscgen supported formats."
  58. (let* ((out-file (or (cdr (assoc :file params)) "output.png" ))
  59. (filetype (or (cdr (assoc :filetype params)) "png" )))
  60. (unless (cdr (assoc :file params))
  61. (error "
  62. ERROR: no output file specified. Add \":file name.png\" to the src header"))
  63. (org-babel-eval (concat "mscgen -T " filetype " -o " out-file) body)
  64. nil)) ;; signal that output has already been written to file
  65. (defun org-babel-prep-session:mscgen (session params)
  66. "Raise an error because Mscgen doesn't support sessions."
  67. (error "Mscgen does not support sessions"))
  68. (provide 'ob-mscgen)
  69. ;;; ob-msc.el ends here