org-babel-asymptote now supports interactive viewing if the :file header argument...
[org-mode.git] / contrib / babel / lisp / langs / org-babel-asymptote.el
blob8af97b02f53d43a487f3e7018ec176b006641c8a
1 ;;; org-babel-asymptote.el --- org-babel functions for asymptote evaluation
3 ;; Copyright (C) 2009 Eric Schulte
5 ;; Author: Eric Schulte
6 ;; Keywords: literate programming, reproducible research
7 ;; Homepage: http://orgmode.org
8 ;; Version: 0.01
10 ;;; License:
12 ;; This program 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, or (at your option)
15 ;; any later version.
17 ;; This program 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.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
27 ;;; Commentary:
29 ;; Org-Babel support for evaluating asymptote source code.
31 ;; This differs from most standard languages in that
33 ;; 1) there is no such thing as a "session" in asymptote
35 ;; 2) we are generally only going to return results of type "file"
37 ;; 3) we are adding the "file" and "cmdline" header arguments, if file
38 ;; is omitted then the -V option is passed to the asy command for
39 ;; interactive viewing
41 ;; 4) there are no variables (at least for now)
43 ;;; Requirements:
45 ;; - The asymptote program :: http://asymptote.sourceforge.net/
47 ;; - asy-mode :: Major mode for editing asymptote files
49 ;;; Code:
50 (require 'org-babel)
52 (org-babel-add-interpreter "asymptote")
54 (add-to-list 'org-babel-tangle-langs '("asymptote" "asymptote"))
56 (defvar org-babel-default-header-args:asymptote '((:results . "file") (:exports . "results"))
57 "Default arguments to use when evaluating a asymptote source block.")
59 (defun org-babel-execute:asymptote (body params)
60 "Execute a block of Asymptote code with org-babel. This function is
61 called by `org-babel-execute-src-block'."
62 (message "executing Asymptote source code block")
63 (let* ((result-params (split-string (or (cdr (assoc :results params)) "")))
64 (out-file (cdr (assoc :file params)))
65 (format (or (and out-file
66 (string-match ".+\\.\\(.+\\)" out-file)
67 (match-string 1 out-file))
68 "pdf"))
69 (cmdline (cdr (assoc :cmdline params)))
70 (in-file (make-temp-file "org-babel-asymptote"))
71 (cmd (concat "asy "
72 (if out-file
73 (concat "-globalwrite -f " format " -o " out-file)
74 "-V")
75 " " cmdline " " in-file)))
76 (with-temp-file in-file (insert body))
77 (message cmd) (shell-command cmd)
78 out-file))
80 (defun org-babel-prep-session:asymptote (session params)
81 (error "Asymptote does not support sessions"))
83 (provide 'org-babel-asymptote)
84 ;;; org-babel-asymptote.el ends here