commit | author | age
|
76bbd0
|
1 |
;;; ob-msc.el --- Babel Functions for Mscgen -*- lexical-binding: t; -*- |
C |
2 |
|
|
3 |
;; Copyright (C) 2010-2018 Free Software Foundation, Inc. |
|
4 |
|
|
5 |
;; Author: Juan Pechiar |
|
6 |
;; Keywords: literate programming, reproducible research |
|
7 |
;; Homepage: https://orgmode.org |
|
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 <https://www.gnu.org/licenses/>. |
|
23 |
|
|
24 |
;;; Commentary: |
|
25 |
;; |
|
26 |
;; This software provides EMACS org-babel export support for message |
|
27 |
;; sequence charts. The mscgen utility is used for processing the |
|
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 |
|
|
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 |
|
|
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'. |
|
66 |
Default filetype is png. Modify by setting :filetype parameter to |
|
67 |
mscgen supported formats." |
|
68 |
(let* ((out-file (or (cdr (assq :file params)) "output.png" )) |
|
69 |
(filetype (or (cdr (assq :filetype params)) "png" ))) |
|
70 |
(unless (cdr (assq :file params)) |
|
71 |
(error " |
|
72 |
ERROR: no output file specified. Add \":file name.png\" to the src header")) |
|
73 |
(org-babel-eval (concat "mscgen -T " filetype " -o " out-file) body) |
|
74 |
nil)) ;; signal that output has already been written to file |
|
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 |
|
|
82 |
|
|
83 |
|
|
84 |
;;; ob-msc.el ends here |