ob-maxima.el 2.4 KB

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