ob-maxima.el 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. ;;; org-babel-maxima.el --- org-babel functions for maxima evaluation
  2. ;; Copyright (c) 2009, 2010, 2011 Eric S Fraga, Eric Schulte
  3. ;; Author: Eric S Fraga, Eric Schulte
  4. ;; Keywords: literate programming, reproducible research, maxima
  5. ;; Homepage: http://orgmode.org
  6. ;; Version: 7.6
  7. ;;; License:
  8. ;; This program 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, or (at your option)
  11. ;; any later version.
  12. ;;
  13. ;; This program 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. ;;
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  20. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. ;; Boston, MA 02110-1301, USA.
  22. ;;; Commentary:
  23. ;; Org-Babel support for evaluating maxima entries.
  24. ;;
  25. ;; This differs from most standard languages in that
  26. ;;
  27. ;; 1) there is no such thing as a "session" in maxima
  28. ;;
  29. ;; 2) we are generally only going to return output from maxima
  30. ;;
  31. ;; 3) we are adding the "cmdline" header argument
  32. ;;
  33. ;; 4) there are no variables
  34. ;;; Code:
  35. (require 'ob)
  36. (defvar org-babel-default-header-args:maxima '())
  37. (defun org-babel-maxima-expand (body params)
  38. "Expand a block of Maxima code according to its header arguments."
  39. body)
  40. (defun org-babel-execute:maxima (body params)
  41. "Execute a block of Maxima entries with org-babel. This function is
  42. called by `org-babel-execute-src-block'."
  43. (message "executing Maxima source code block")
  44. (let* ((result-params (split-string (or (cdr (assoc :results params)) "")))
  45. (cmdline (cdr (assoc :cmdline params)))
  46. (in-file (org-babel-temp-file "maxima-"))
  47. (cmd (format "maxima --very-quiet -r 'batchload(%S)$' %s"
  48. in-file cmdline)))
  49. (with-temp-file in-file (insert body))
  50. (message cmd)
  51. ((lambda (raw) ;; " | grep -v batch | grep -v 'replaced' | sed '/^$/d' "
  52. (mapconcat
  53. #'identity
  54. (delq nil
  55. (mapcar (lambda (line)
  56. (unless (or (string-match "batch" line)
  57. (string-match "^rat: replaced .*$" line)
  58. (= 0 (length line)))
  59. line))
  60. (split-string raw "[\r\n]"))) "\n"))
  61. (org-babel-eval cmd ""))))
  62. (defun org-babel-prep-session:maxima (session params)
  63. (error "Maxima does not support sessions"))
  64. (provide 'ob-maxima)
  65. ;; arch-tag: d86c97ac-7eab-4349-8d8b-302dd09779a8
  66. ;;; org-babel-maxima.el ends here