Commit | Line | Data |
---|---|---|
3ab2c837 BG |
1 | ;;; ob-maxima.el --- org-babel functions for maxima evaluation |
2 | ||
09ade3a3 | 3 | ;; Copyright (C) 2009-2011 Free Software Foundation, Inc. |
3ab2c837 | 4 | |
09ade3a3 GM |
5 | ;; Author: Eric S Fraga |
6 | ;; Eric Schulte | |
3ab2c837 BG |
7 | ;; Keywords: literate programming, reproducible research, maxima |
8 | ;; Homepage: http://orgmode.org | |
9 | ;; Version: 7.7 | |
10 | ||
09ade3a3 | 11 | ;; This file is part of GNU Emacs. |
3ab2c837 | 12 | |
09ade3a3 | 13 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
3ab2c837 | 14 | ;; it under the terms of the GNU General Public License as published by |
09ade3a3 GM |
15 | ;; the Free Software Foundation, either version 3 of the License, or |
16 | ;; (at your option) any later version. | |
17 | ||
18 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
3ab2c837 BG |
19 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
20 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 | ;; GNU General Public License for more details. | |
09ade3a3 | 22 | |
3ab2c837 | 23 | ;; You should have received a copy of the GNU General Public License |
09ade3a3 | 24 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
3ab2c837 BG |
25 | |
26 | ;;; Commentary: | |
27 | ||
28 | ;; Org-Babel support for evaluating maxima entries. | |
29 | ;; | |
30 | ;; This differs from most standard languages in that | |
31 | ;; | |
32 | ;; 1) there is no such thing as a "session" in maxima | |
33 | ;; | |
34 | ;; 2) we are generally only going to return output from maxima | |
35 | ;; | |
36 | ;; 3) we are adding the "cmdline" header argument | |
37 | ;; | |
38 | ;; 4) there are no variables | |
39 | ||
40 | ;;; Code: | |
41 | (require 'ob) | |
42 | ||
43 | (defvar org-babel-default-header-args:maxima '()) | |
44 | ||
45 | (defun org-babel-maxima-expand (body params) | |
46 | "Expand a block of Maxima code according to its header arguments." | |
47 | body) | |
48 | ||
49 | (defun org-babel-execute:maxima (body params) | |
50 | "Execute a block of Maxima entries with org-babel. This function is | |
51 | called by `org-babel-execute-src-block'." | |
52 | (message "executing Maxima source code block") | |
53 | (let* ((result-params (split-string (or (cdr (assoc :results params)) ""))) | |
54 | (cmdline (cdr (assoc :cmdline params))) | |
55 | (in-file (org-babel-temp-file "maxima-")) | |
56 | (cmd (format "maxima --very-quiet -r 'batchload(%S)$' %s" | |
57 | in-file cmdline))) | |
58 | (with-temp-file in-file (insert body)) | |
59 | (message cmd) | |
60 | ((lambda (raw) ;; " | grep -v batch | grep -v 'replaced' | sed '/^$/d' " | |
61 | (mapconcat | |
62 | #'identity | |
63 | (delq nil | |
64 | (mapcar (lambda (line) | |
65 | (unless (or (string-match "batch" line) | |
66 | (string-match "^rat: replaced .*$" line) | |
67 | (= 0 (length line))) | |
68 | line)) | |
69 | (split-string raw "[\r\n]"))) "\n")) | |
70 | (org-babel-eval cmd "")))) | |
71 | ||
72 | (defun org-babel-prep-session:maxima (session params) | |
73 | (error "Maxima does not support sessions")) | |
74 | ||
75 | (provide 'ob-maxima) | |
76 | ||
5b409b39 | 77 | |
3ab2c837 BG |
78 | |
79 | ;;; ob-maxima.el ends here |