ob-mscgen.el (2937B)
1 ;;; ob-mscgen.el --- Babel Functions for Mscgen -*- lexical-binding: t; -*- 2 3 ;; Copyright (C) 2010-2021 Free Software Foundation, Inc. 4 5 ;; Author: Juan Pechiar 6 ;; Maintainer: Justin Abrahms 7 ;; Keywords: literate programming, reproducible research 8 ;; Homepage: https://git.sr.ht/~bzg/org-contrib 9 10 ;; This file is not 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 <https://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 ;; https://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 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 64 (defun org-babel-execute:mscgen (body params) 65 "Execute a block of Mscgen code with Babel. 66 This function is called by `org-babel-execute-src-block'. 67 Default filetype is png. Modify by setting :filetype parameter to 68 mscgen supported formats." 69 (let* ((out-file (or (cdr (assq :file params)) "output.png" )) 70 (filetype (or (cdr (assq :filetype params)) "png" ))) 71 (unless (cdr (assq :file params)) 72 (error "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 ;;; ob-mscgen.el ends here