From mboxrd@z Thu Jan 1 00:00:00 1970 From: Juan Subject: Re: Code snippet for Message Sequence Diagram export Date: Sun, 23 May 2010 19:43:07 -0300 Message-ID: <20100523224307.GC27574@soloJazz.com> References: <20100516201839.GA25054@soloJazz.com> <87aarzq72u.wl%ucecesf@ucl.ac.uk> <20100517200431.GA27574@soloJazz.com> <87hbm6w2oh.fsf@stats.ox.ac.uk> <20100518012410.GB27574@soloJazz.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from [140.186.70.92] (port=38060 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OGJt7-0005NR-PM for emacs-orgmode@gnu.org; Sun, 23 May 2010 18:43:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OGJt4-0002mH-Ue for emacs-orgmode@gnu.org; Sun, 23 May 2010 18:43:17 -0400 Received: from cpoproxy1-pub.bluehost.com ([69.89.21.11]:49545 helo=outbound-mail-01.bluehost.com) by eggs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1OGJt4-0002mD-Il for emacs-orgmode@gnu.org; Sun, 23 May 2010 18:43:14 -0400 Content-Disposition: inline In-Reply-To: <20100518012410.GB27574@soloJazz.com> 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: Dan Davison Cc: Emacs-orgmode Dan, Below is the final proposal for org-babel-mscgen.el. Already sent form to assign@gnu.org, got no answer (I assume it is OK). I remade all of the code, so almost no traces from org-babel-ditaa. On Mon, May 17, 2010 at 10:24:10PM -0300, Juan wrote: > On Mon, May 17, 2010 at 07:04:14PM -0400, Dan Davison wrote: > > Juan writes: > > > Below goes code snippet using org-babel instead of org-export. > > And a couple of little questions: > > > > - I think I'd prefer to get rid of the org-mscgen-path variable, and > > simply require that mscgen is on the user's $PATH. Is that OK or am I > > missing a reason for doing it differently? > > You're right. I'll get rid of it. Done. Now mscgen must be accessible on exec-path. > ... > > - If you are feeling energetic, it would be really nice to check the > > exit code from the shell-command and use org-babel-error-notify if > > necessary > > I'll look into it. Done. Now error messages from mscgen are passed to org-babel-error-notify. Just a question on style: If you look at the '(unless' line below, I throw an elisp 'error' if the user forgets to add an output file to the #+begin_src header. Is this OK, or should I stick to org-babel-error-notify with a dummy exit code? Thanks & regards, .j. 8<------------------------------------------------------------ ;;; org-babel-mscgen.el --- org-babel functions for mscgen evaluation ;;; TODO insert license information ;;; Author: Juan Pechiar (juan@pechiar.com) ;;; Commentary: ;; ;; This software provides EMACS org-babel export support for message ;; sequence charts. The mscgen utility is used for processing the ;; sequence definition, and must therefore be installed in the system. ;; ;; Mscgen is available and documented at http://www.mcternan.me.uk/mscgen/index.html ;; ;; Example: ;; ;; #+begin_src mscgen :file example.png ;; msc { ;; A,B; ;; A -> B [ label = "send message" ]; ;; A <- B [ label = "get answer" ]; ;; } ;; #+end_src ;;; Code: (require 'org-babel) (org-babel-add-interpreter "mscgen") (add-to-list 'org-babel-tangle-langs '("mscgen" "mscgen")) (defvar org-babel-default-header-args:mscgen '((:results . "file") (:exports . "results")) "Default arguments to use when evaluating a mscgen source block.") (defun org-babel-expand-body:mscgen (body params &optional processed-params) body) (defun org-babel-execute:mscgen (body params) "Execute a block of Mscgen code with org-babel. This function is called by `org-babel-execute-src-block'." (message "executing Mscgen source code block") (let* ((out-file (or (cdr (assoc :file params)) "output.png" )) exit-code (stderr (with-temp-buffer (insert body) (setq exit-code (org-babel-shell-command-on-region (point-min) (point-max) (concat "mscgen -T png -o " out-file) nil 'replace (current-buffer))) (buffer-string)))) (unless (cdr (assoc :file params)) (setq stderr (concat stderr "\nERROR: no output file specified. Add \":file some_name.png\" to the src header" )) (error stderr)) (if (> exit-code 0) (org-babel-error-notify exit-code stderr)) out-file)) (defun org-babel-prep-session:mscgen (session params) (error "Mscgen does not support sessions")) (provide 'org-babel-mscgen) ;;; org-babel-mscgen.el ends here