From: Juan <pechiar@computer.org>
To: Emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Code snippet for Message Sequence Diagram export
Date: Sun, 16 May 2010 17:18:39 -0300 [thread overview]
Message-ID: <20100516201839.GA25054@soloJazz.com> (raw)
Hi,
The following code adds an export block of type 'mscgen'. The block
body will be processed by the mscgen application. Sort of works, not
very tested yet.
;;; org-exp-mscgen.el --- message sequence chart support for org-export
;; Copyright (C) 2010
;; Free Software Foundation, Inc.
;; Author: Juan Pechiar
;; Version: 0.1 2010-05-16
;; This is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This software is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; This software provides EMACS org-mode export support for message
;; sequence charts. The mscgen utility is used for processing the
;; sequence definition, and must therefore be installed in the system.
;;
;; The code is a direct modification of org-export-blocks-format-ditaa
;; from the org-mode distribution.
;;
;; Mscgen is available and documented at http://www.mcternan.me.uk/mscgen/index.html
;;
;; Customize path to mscgen utility with org-mscgen-path variable
;;
;; Example:
;;
;; #+begin_mscgen example1
;; A,B;
;; --- [ label = "start of sequence" ];
;; A -> B [ label = "send message" ];
;; #+end_mscgen
;;
;; TODO: check cleanup of temp files
;; TODO: fix automatic filename generation when name not given
;; TODO: export in EPS format for LaTeX (need to convert EPS to PDF for pdflatex to use)
(defvar org-mscgen-path
"/opt/local/bin/mscgen"
"Complete path to the mscgen executable")
(defun org-export-blocks-format-mscgen (body &rest headers)
"Pass block BODY to the mscgen utility creating an image.
Enclosing tags \"msc{\" and \"}\" must not appear in BODY.
Specify the path at which the image should be saved as the first
element of headers. Additional header elements are ignored and
for future use."
(message "mscgen-formatting...")
(let* ((args (if (cdr headers) (mapconcat 'identity (cdr headers) " "))) ;; for building hash
(data-file (make-temp-file "org-mscgen")) ;; temp storage for BODY
(hash (sha1 (prin1-to-string (list body args)))) ;; hash (body + args)
(raw-out-file (if headers (car headers) "out_mscgen" )) ;; output file
(out-file-parts (cons raw-out-file "png"))
(out-file (concat (car out-file-parts) "_" hash "." (cdr out-file-parts)))
(unless (file-exists-p org-mscgen-path)
(error (format "Could not find mscgen at %s" org-mscgen-path)))
(cond
((or latexp htmlp docbookp)
;; HTML, LaTeX and DocBook export
(unless (file-exists-p out-file)
(mapc ;; remove old hashed versions of this file
(lambda (file)
(when (and (string-match (concat (regexp-quote (car out-file-parts))
"_\\([[:alnum:]]+\\)\\."
(regexp-quote (cdr out-file-parts)))
file)
(= (length (match-string 1 out-file)) 40))
(delete-file (expand-file-name file
(file-name-directory out-file)))))
(directory-files (or (file-name-directory out-file)
default-directory)))
(with-temp-file data-file (insert (concat "msc {\n" body "\n}\n")))
(message (concat org-mscgen-path " -T png -o " out-file " -i " data-file))
(shell-command (concat org-mscgen-path " -T png -o " out-file " -i " data-file)))
(cond
(latexp
(format "\n#+ATTR_LaTeX: width=0.85\\textwidth\n[[file:%s]]\n" out-file))
(t
(format "\n[[file:%s]]\n" out-file))))
;; export to other formats: keep body as is
(t (concat
"\n#+BEGIN_EXAMPLE\n"
body (if (string-match "\n$" body) "" "\n")
"#+END_EXAMPLE\n")))))
(org-export-blocks-add-block '(mscgen org-export-blocks-format-mscgen nil))
next reply other threads:[~2010-05-16 20:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-16 20:18 Juan [this message]
2010-05-17 8:13 ` Code snippet for Message Sequence Diagram export Eric S Fraga
2010-05-17 20:04 ` Juan
2010-05-17 23:04 ` Dan Davison
2010-05-18 1:24 ` Juan
2010-05-23 22:43 ` Juan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100516201839.GA25054@soloJazz.com \
--to=pechiar@computer.org \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).