ob-mscgen.el 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. ;;; ob-msc.el --- Babel Functions for Mscgen -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2010-2021 Free Software Foundation, Inc.
  3. ;; Author: Juan Pechiar
  4. ;; Maintainer: Justin Abrahms
  5. ;; Keywords: literate programming, reproducible research
  6. ;; Homepage: https://orgmode.org
  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 <https://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. ;; https://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. (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 (assq :file params)) "output.png" ))
  59. (filetype (or (cdr (assq :filetype params)) "png" )))
  60. (unless (cdr (assq :file params))
  61. (error "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