Commit | Line | Data |
---|---|---|
afe98dfa CD |
1 | ;;; ob-org.el --- org-babel functions for org code block evaluation |
2 | ||
ba318903 | 3 | ;; Copyright (C) 2010-2014 Free Software Foundation, Inc. |
afe98dfa CD |
4 | |
5 | ;; Author: Eric Schulte | |
6 | ;; Keywords: literate programming, reproducible research | |
7 | ;; Homepage: http://orgmode.org | |
afe98dfa CD |
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 <http://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 | (require 'ob) | |
31 | ||
271672fa BG |
32 | (declare-function org-export-string-as "ox" |
33 | (string backend &optional body-only ext-plist)) | |
afe98dfa CD |
34 | |
35 | (defvar org-babel-default-header-args:org | |
8223b1d2 | 36 | '((:results . "raw silent") (:exports . "code")) |
afe98dfa CD |
37 | "Default arguments for evaluating a org source block.") |
38 | ||
39 | (defvar org-babel-org-default-header | |
40 | "#+TITLE: default empty header\n" | |
41 | "Default header inserted during export of org blocks.") | |
42 | ||
3ab2c837 BG |
43 | (defun org-babel-expand-body:org (body params) |
44 | (dolist (var (mapcar #'cdr (org-babel-get-header params :var))) | |
45 | (setq body (replace-regexp-in-string | |
271672fa BG |
46 | (regexp-quote (format "$%s" (car var))) |
47 | (format "%s" (cdr var)) | |
48 | body nil 'literal))) | |
3ab2c837 BG |
49 | body) |
50 | ||
afe98dfa CD |
51 | (defun org-babel-execute:org (body params) |
52 | "Execute a block of Org code with. | |
53 | This function is called by `org-babel-execute-src-block'." | |
54 | (let ((result-params (split-string (or (cdr (assoc :results params)) ""))) | |
3ab2c837 BG |
55 | (body (org-babel-expand-body:org |
56 | (replace-regexp-in-string "^," "" body) params))) | |
afe98dfa | 57 | (cond |
271672fa BG |
58 | ((member "latex" result-params) |
59 | (org-export-string-as (concat "#+Title: \n" body) 'latex t)) | |
60 | ((member "html" result-params) (org-export-string-as body 'html t)) | |
61 | ((member "ascii" result-params) (org-export-string-as body 'ascii t)) | |
afe98dfa CD |
62 | (t body)))) |
63 | ||
64 | (defun org-babel-prep-session:org (session params) | |
65 | "Return an error because org does not support sessions." | |
66 | (error "Org does not support sessions")) | |
67 | ||
68 | (provide 'ob-org) | |
69 | ||
5b409b39 | 70 | |
afe98dfa CD |
71 | |
72 | ;;; ob-org.el ends here |