]> code.delx.au - gnu-emacs/blob - lisp/org/ob-mscgen.el
Convert consecutive FSF copyright years to ranges.
[gnu-emacs] / lisp / org / ob-mscgen.el
1 ;;; ob-msc.el --- org-babel functions for mscgen evaluation
2
3 ;; Copyright (C) 2010-2011 Free Software Foundation, Inc.
4
5 ;; Author: Juan Pechiar
6 ;; Keywords: literate programming, reproducible research
7 ;; Homepage: http://orgmode.org
8 ;; Version: 7.4
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24
25 ;;; Commentary:
26 ;;
27 ;; This software provides EMACS org-babel export support for message
28 ;; sequence charts. The mscgen utility is used for processing the
29 ;; sequence definition, and must therefore be installed in the system.
30 ;;
31 ;; Mscgen is available and documented at
32 ;; http://www.mcternan.me.uk/mscgen/index.html
33 ;;
34 ;; This code is directly inspired by Eric Schulte's ob-dot.el
35 ;;
36 ;; Example:
37 ;;
38 ;; #+begin_src mscgen :file example.png
39 ;; msc {
40 ;; A,B;
41 ;; A -> B [ label = "send message" ];
42 ;; A <- B [ label = "get answer" ];
43 ;; }
44 ;; #+end_src
45 ;;
46 ;; Header for alternative file type:
47 ;;
48 ;; #+begin_src mscgen :file ex2.svg :filetype svg
49
50 ;; This differs from most standard languages in that
51 ;;
52 ;; 1) there is no such thing as a "session" in mscgen
53 ;; 2) we are generally only going to return results of type "file"
54 ;; 3) we are adding the "file" and "filetype" header arguments
55 ;; 4) there are no variables
56
57 ;;; Code:
58 (require 'ob)
59 (require 'ob-eval)
60
61 (defvar org-babel-default-header-args:mscgen
62 '((:results . "file") (:exports . "results"))
63 "Default arguments to use when evaluating a mscgen source block.")
64
65 (defun org-babel-execute:mscgen (body params)
66 "Execute a block of Mscgen code with Babel.
67 This function is called by `org-babel-execute-src-block'.
68 Default filetype is png. Modify by setting :filetype parameter to
69 mscgen supported formats."
70 (let* ((out-file (or (cdr (assoc :file params)) "output.png" ))
71 (filetype (or (cdr (assoc :filetype params)) "png" )))
72 (unless (cdr (assoc :file params))
73 (error "
74 ERROR: no output file specified. Add \":file name.png\" to the src header"))
75 (org-babel-eval (concat "mscgen -T " filetype " -o " out-file) body)
76 out-file))
77
78 (defun org-babel-prep-session:mscgen (session params)
79 "Raise an error because Mscgen doesn't support sessions."
80 (error "Mscgen does not support sessions"))
81
82 (provide 'ob-mscgen)
83
84
85 ;;; ob-msc.el ends here