ob-mscgen.el 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. ;;; ob-msc.el --- Babel Functions for Mscgen -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2010-2017 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 <https://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. (defvar org-babel-default-header-args:mscgen
  50. '((:results . "file") (:exports . "results"))
  51. "Default arguments to use when evaluating a mscgen source block.")
  52. (defun org-babel-execute:mscgen (body params)
  53. "Execute a block of Mscgen code with Babel.
  54. This function is called by `org-babel-execute-src-block'.
  55. Default filetype is png. Modify by setting :filetype parameter to
  56. mscgen supported formats."
  57. (let* ((out-file (or (cdr (assq :file params)) "output.png" ))
  58. (filetype (or (cdr (assq :filetype params)) "png" )))
  59. (unless (cdr (assq :file params))
  60. (error "
  61. ERROR: no output file specified. Add \":file name.png\" to the src header"))
  62. (org-babel-eval (concat "mscgen -T " filetype " -o " out-file) body)
  63. nil)) ;; signal that output has already been written to file
  64. (defun org-babel-prep-session:mscgen (_session _params)
  65. "Raise an error because Mscgen doesn't support sessions."
  66. (error "Mscgen does not support sessions"))
  67. (provide 'ob-mscgen)
  68. ;;; ob-msc.el ends here