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
39 ;; 4) there are no variables (at least for now)
43 ;; - The asymptote program :: http://asymptote.sourceforge.net/
45 ;; - asy-mode :: Major mode for editing asymptote files
50 (org-babel-add-interpreter "asymptote")
52 (add-to-list 'org-babel-tangle-langs
'("asymptote" "asymptote"))
54 (defvar org-babel-default-header-args
:asymptote
'((:results .
"file") (:exports .
"results"))
55 "Default arguments to use when evaluating a asymptote source block.")
57 (defun org-babel-execute:asymptote
(body params
)
58 "Execute a block of Asymptote code with org-babel. This function is
59 called by `org-babel-execute-src-block'."
60 (message "executing Asymptote source code block")
61 (let* ((result-params (split-string (or (cdr (assoc :results params
)) "")))
62 (out-file (cdr (assoc :file params
)))
63 (format (or (and (string-match ".+\\.\\(.+\\)" out-file
)
64 (match-string 1 out-file
))
66 (cmdline (cdr (assoc :cmdline params
)))
67 (in-file (make-temp-file "org-babel-asymptote")))
68 (with-temp-file in-file
(insert body
))
69 (message (concat "asy -globalwrite -f " format
" -o " out-file
" " cmdline
" " in-file
))
70 (shell-command (concat "asy -globalwrite -f " format
" -o " out-file
" " cmdline
" " in-file
))
73 (defun org-babel-prep-session:asymptote
(session params
)
74 (error "Asymptote does not support sessions"))
76 (provide 'org-babel-asymptote
)
77 ;;; org-babel-asymptote.el ends here