ob-org.el 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.6
  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-export-string "org-exp" (string fmt &optional dir))
  24. (defvar org-babel-default-header-args:org
  25. '((:results . "raw silent") (:exports . "results"))
  26. "Default arguments for evaluating a org source block.")
  27. (defvar org-babel-org-default-header
  28. "#+TITLE: default empty header\n"
  29. "Default header inserted during export of org blocks.")
  30. (defun org-babel-expand-body:org (body params)
  31. (dolist (var (mapcar #'cdr (org-babel-get-header params :var)))
  32. (setq body (replace-regexp-in-string
  33. (regexp-quote (format "$%s" (car var))) (cdr var) body
  34. nil 'literal)))
  35. body)
  36. (defun org-babel-execute:org (body params)
  37. "Execute a block of Org code with.
  38. This function is called by `org-babel-execute-src-block'."
  39. (let ((result-params (split-string (or (cdr (assoc :results params)) "")))
  40. (body (org-babel-expand-body:org
  41. (replace-regexp-in-string "^," "" body) params)))
  42. (cond
  43. ((member "latex" result-params) (org-export-string
  44. (concat "#+Title: \n" body) "latex"))
  45. ((member "html" result-params) (org-export-string body "html"))
  46. ((member "ascii" result-params) (org-export-string body "ascii"))
  47. (t body))))
  48. (defun org-babel-prep-session:org (session params)
  49. "Return an error because org does not support sessions."
  50. (error "Org does not support sessions"))
  51. (provide 'ob-org)
  52. ;; arch-tag: 130af5fe-cc56-46bd-9508-fa0ebd94cb1f
  53. ;;; ob-org.el ends here