ob-mscgen.el 3.3 KB

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