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
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)
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.
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)
45 ;; - The asymptote program :: http://asymptote.sourceforge.net/
47 ;; - asy-mode :: Major mode for editing asymptote files
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
))
69 (cmdline (cdr (assoc :cmdline params
)))
70 (in-file (make-temp-file "org-babel-asymptote"))
73 (concat "-globalwrite -f " format
" -o " out-file
)
75 " " cmdline
" " in-file
)))
76 (with-temp-file in-file
(insert body
))
77 (message cmd
) (shell-command cmd
)
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