README_contribute: Update instructions
[org-mode.git] / lisp / ob-mscgen.el
blob784e0a94697b132afb5476ea494b97a2983360d6
1 ;;; ob-msc.el --- Babel Functions for Mscgen -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2010-2017 Free Software Foundation, Inc.
5 ;; Author: Juan Pechiar
6 ;; Keywords: literate programming, reproducible research
7 ;; Homepage: http://orgmode.org
9 ;; This file is part of GNU Emacs.
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.
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.
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/>.
24 ;;; Commentary:
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.
30 ;; Mscgen is available and documented at
31 ;; http://www.mcternan.me.uk/mscgen/index.html
33 ;; This code is directly inspired by Eric Schulte's ob-dot.el
35 ;; Example:
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
45 ;; Header for alternative file type:
47 ;; #+begin_src mscgen :file ex2.svg :filetype svg
49 ;; This differs from most standard languages in that
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
56 ;;; Code:
57 (require 'ob)
59 (defvar org-babel-default-header-args:mscgen
60 '((:results . "file") (:exports . "results"))
61 "Default arguments to use when evaluating a mscgen source block.")
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
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"))
80 (provide 'ob-mscgen)
84 ;;; ob-msc.el ends here