Commit | Line | Data |
---|---|---|
86fbb8ca CD |
1 | ;;; ob-msc.el --- org-babel functions for mscgen evaluation |
2 | ||
ba318903 | 3 | ;; Copyright (C) 2010-2014 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) | |
86fbb8ca CD |
58 | |
59 | (defvar org-babel-default-header-args:mscgen | |
60 | '((:results . "file") (:exports . "results")) | |
61 | "Default arguments to use when evaluating a mscgen source block.") | |
62 | ||
86fbb8ca CD |
63 | (defun org-babel-execute:mscgen (body params) |
64 | "Execute a block of Mscgen code with Babel. | |
65 | This function is called by `org-babel-execute-src-block'. | |
8223b1d2 | 66 | Default filetype is png. Modify by setting :filetype parameter to |
86fbb8ca CD |
67 | mscgen supported formats." |
68 | (let* ((out-file (or (cdr (assoc :file params)) "output.png" )) | |
69 | (filetype (or (cdr (assoc :filetype params)) "png" ))) | |
70 | (unless (cdr (assoc :file params)) | |
71 | (error " | |
8223b1d2 | 72 | ERROR: no output file specified. Add \":file name.png\" to the src header")) |
86fbb8ca | 73 | (org-babel-eval (concat "mscgen -T " filetype " -o " out-file) body) |
3ab2c837 | 74 | nil)) ;; signal that output has already been written to file |
86fbb8ca CD |
75 | |
76 | (defun org-babel-prep-session:mscgen (session params) | |
77 | "Raise an error because Mscgen doesn't support sessions." | |
78 | (error "Mscgen does not support sessions")) | |
79 | ||
80 | (provide 'ob-mscgen) | |
81 | ||
5b409b39 | 82 | |
86fbb8ca CD |
83 | |
84 | ;;; ob-msc.el ends here |