ob-org.el 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. ;;; ob-org.el --- org-babel functions for org code block evaluation
  2. ;; Copyright (C) 2010-2012 Free Software Foundation, Inc.
  3. ;; Author: Eric Schulte
  4. ;; Keywords: literate programming, reproducible research
  5. ;; Homepage: http://orgmode.org
  6. ;; This file is part of GNU Emacs.
  7. ;; GNU Emacs is free software: you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;; This is the simplest of code blocks, where upon evaluation the
  19. ;; contents of the code block are returned in a raw result.
  20. ;;; Code:
  21. (require 'ob)
  22. (declare-function org-export-string "org-exp" (string fmt &optional dir))
  23. (defvar org-babel-default-header-args:org
  24. '((:results . "raw silent") (:exports . "results"))
  25. "Default arguments for evaluating a org source block.")
  26. (defvar org-babel-org-default-header
  27. "#+TITLE: default empty header\n"
  28. "Default header inserted during export of org blocks.")
  29. (defun org-babel-expand-body:org (body params)
  30. (dolist (var (mapcar #'cdr (org-babel-get-header params :var)))
  31. (setq body (replace-regexp-in-string
  32. (regexp-quote (format "$%s" (car var))) (cdr var) body
  33. nil 'literal)))
  34. body)
  35. (defun org-babel-execute:org (body params)
  36. "Execute a block of Org code with.
  37. This function is called by `org-babel-execute-src-block'."
  38. (let ((result-params (split-string (or (cdr (assoc :results params)) "")))
  39. (body (org-babel-expand-body:org
  40. (replace-regexp-in-string "^," "" body) params)))
  41. (cond
  42. ((member "latex" result-params) (org-export-string
  43. (concat "#+Title: \n" body) "latex"))
  44. ((member "html" result-params) (org-export-string body "html"))
  45. ((member "ascii" result-params) (org-export-string body "ascii"))
  46. (t body))))
  47. (defun org-babel-prep-session:org (session params)
  48. "Return an error because org does not support sessions."
  49. (error "Org does not support sessions"))
  50. (provide 'ob-org)
  51. ;;; ob-org.el ends here