ob-maxima.el 2.5 KB

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