ob-mscgen.el 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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: 0.01
  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-expand-body:mscgen (body params &optional processed-params)
  55. "Expand BODY according to PARAMS, return the expanded body." body)
  56. (defun org-babel-execute:mscgen (body params)
  57. "Execute a block of Mscgen code with org-babel. This function
  58. is called by `org-babel-execute-src-block'. Default filetype is
  59. png. Modify by setting :filetype parameter to mscgen supported
  60. formats."
  61. (message "executing Mscgen source code block")
  62. (let* ((out-file (or (cdr (assoc :file params)) "output.png" ))
  63. (filetype (or (cdr (assoc :filetype params)) "png" )))
  64. (unless (cdr (assoc :file params))
  65. (error (concat
  66. "\nERROR: no output file specified. "
  67. "Add \":file some_name.png\" to the src header")))
  68. (org-babel-eval (concat "mscgen -T " filetype " -o " out-file) body)
  69. out-file))
  70. (defun org-babel-prep-session:mscgen (session params)
  71. "Prepare SESSION according to PARAMS."
  72. (error "Mscgen does not support sessions"))
  73. (provide 'ob-mscgen)
  74. ;; arch-tag: 74695b1e-715f-4b5a-a3a9-d78ee39ba5c8
  75. ;;; ob-msc.el ends here