ob-org.el 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. ;;; ob-org.el --- Babel Functions for Org Code Blocks -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2010-2022 Free Software Foundation, Inc.
  3. ;; Author: Eric Schulte
  4. ;; Keywords: literate programming, reproducible research
  5. ;; Homepage: https://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 <https://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-as "ox"
  23. (string backend &optional body-only ext-plist))
  24. (defvar org-babel-default-header-args:org
  25. '((:results . "raw silent") (:exports . "code"))
  26. "Default arguments for evaluating an 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 (org-babel--get-vars params))
  32. (setq body (replace-regexp-in-string
  33. (regexp-quote (format "$%s" (car var)))
  34. (format "%s" (cdr var))
  35. body nil 'literal)))
  36. body)
  37. (defun org-babel-execute:org (body params)
  38. "Execute a block of Org code with.
  39. This function is called by `org-babel-execute-src-block'."
  40. (let ((result-params (split-string (or (cdr (assq :results params)) "")))
  41. (body (org-babel-expand-body:org
  42. (replace-regexp-in-string "^," "" body) params)))
  43. (cond
  44. ((member "latex" result-params)
  45. (org-export-string-as (concat "#+Title: \n" body) 'latex t))
  46. ((member "html" result-params) (org-export-string-as body 'html t))
  47. ((member "ascii" result-params) (org-export-string-as body 'ascii t))
  48. (t body))))
  49. (defun org-babel-prep-session:org (_session _params)
  50. "Return an error because org does not support sessions."
  51. (error "Org does not support sessions"))
  52. (provide 'ob-org)
  53. ;;; ob-org.el ends here