From mboxrd@z Thu Jan 1 00:00:00 1970 From: Juan Subject: Code snippet for Message Sequence Diagram export Date: Sun, 16 May 2010 17:18:39 -0300 Message-ID: <20100516201839.GA25054@soloJazz.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from [140.186.70.92] (port=37720 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ODkIU-0002Ai-5W for emacs-orgmode@gnu.org; Sun, 16 May 2010 16:18:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1ODkIS-000064-1A for emacs-orgmode@gnu.org; Sun, 16 May 2010 16:18:50 -0400 Received: from cpoproxy3-pub.bluehost.com ([67.222.54.6]:51166 helo=outbound-mail-313.bluehost.com) by eggs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1ODkIR-00005p-HY for emacs-orgmode@gnu.org; Sun, 16 May 2010 16:18:47 -0400 Received: from r186-48-197-106.dialup.adsl.anteldata.net.uy ([186.48.197.106] helo=iso.palmas.net) by box519.bluehost.com with esmtpa (Exim 4.69) (envelope-from ) id 1ODkIM-0000Lx-T0 for emacs-orgmode@gnu.org; Sun, 16 May 2010 14:18:45 -0600 Content-Disposition: inline List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Emacs-orgmode 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 . ;;; 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))