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