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