ob-mscgen.el 2.9 KB

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