ob-org.el 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. ;;; ob-org.el --- org-babel functions for org code block 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. ;; This is the simplest of code blocks, where upon evaluation the
  20. ;; contents of the code block are returned in a raw result.
  21. ;;; Code:
  22. (require 'ob)
  23. (declare-function org-load-modules-maybe "org" (&optional force))
  24. (declare-function org-get-local-variables "org" ())
  25. (defvar org-babel-default-header-args:org
  26. '((:results . "raw silent") (:exports . "results"))
  27. "Default arguments for evaluating a org source block.")
  28. (defun org-babel-expand-body:org (body params &optional processed-params)
  29. "Expand BODY according to PARAMS, return the expanded body." body)
  30. (defun org-babel-execute:org (body params)
  31. "Execute a block of Org code with.
  32. This function is called by `org-babel-execute-src-block'."
  33. (let ((result-params (split-string (or (cdr (assoc :results params)) ""))))
  34. (cond
  35. ((member "latex" result-params) (org-babel-org-export body "latex"))
  36. ((member "html" result-params) (org-babel-org-export body "html"))
  37. ((member "ascii" result-params) (org-babel-org-export body "ascii"))
  38. (t body))))
  39. (defvar org-local-vars)
  40. (defun org-babel-org-export (body fmt)
  41. "Export BODY to FMT using Org-mode's export facilities. "
  42. (let ((tmp-file (org-babel-temp-file "org-")))
  43. (with-temp-buffer
  44. (insert body)
  45. (write-file tmp-file)
  46. (org-load-modules-maybe)
  47. (unless org-local-vars
  48. (setq org-local-vars (org-get-local-variables)))
  49. (eval ;; convert to fmt -- mimicing `org-run-like-in-org-mode'
  50. (list 'let org-local-vars
  51. (list (intern (concat "org-export-as-" fmt))
  52. nil nil nil ''string t))))))
  53. (defun org-babel-prep-session:org (session params)
  54. "Return an error because org does not support sessions."
  55. (error "Org does not support sessions"))
  56. (provide 'ob-org)
  57. ;; arch-tag: 130af5fe-cc56-46bd-9508-fa0ebd94cb1f
  58. ;;; ob-org.el ends here