ob-calc.el 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. ;;; ob-calc.el --- org-babel functions for calc code evaluation
  2. ;; Copyright (C) 2010 Free Software Foundation, Inc
  3. ;; Author: Eric Schulte
  4. ;; Keywords: literate programming, reproducible research
  5. ;; Homepage: http://orgmode.org
  6. ;; Version: 7.01trans
  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 calc code
  20. ;;; Code:
  21. (require 'ob)
  22. (require 'calc)
  23. (eval-when-compile (require 'ob-comint))
  24. (defvar org-babel-default-header-args:calc nil
  25. "Default arguments for evaluating an calc source block.")
  26. (defun org-babel-expand-body:calc (body params)
  27. "Expand BODY according to PARAMS, return the expanded body." body)
  28. (defun org-babel-execute:calc (body params)
  29. "Execute a block of calc code with Babel."
  30. (mapcar
  31. (lambda (line)
  32. (when (> (length line) 0)
  33. (if (string= "'" (substring line 0 1))
  34. (funcall (lookup-key calc-mode-map (substring line 1)) nil)
  35. (calc-push-list (list ((lambda (res)
  36. (if (numberp res) res (math-read-number res)))
  37. (calc-eval line)))))))
  38. (split-string (org-babel-expand-body:calc body params) "[\n\r]"))
  39. (calc-eval (calc-top 1)))
  40. (provide 'ob-calc)
  41. ;; arch-tag: 5c57a3b7-5818-4c6c-acda-7a94831a6449
  42. ;;; ob-calc.el ends here