Commit | Line | Data |
---|---|---|
afe98dfa CD |
1 | ;;; ob-org.el --- org-babel functions for org code block evaluation |
2 | ||
3ab2c837 | 3 | ;; Copyright (C) 2010 Free Software Foundation, Inc. |
afe98dfa CD |
4 | |
5 | ;; Author: Eric Schulte | |
6 | ;; Keywords: literate programming, reproducible research | |
7 | ;; Homepage: http://orgmode.org | |
3ab2c837 | 8 | ;; Version: 7.7 |
afe98dfa CD |
9 | |
10 | ;; This file is part of GNU Emacs. | |
11 | ||
12 | ;; GNU Emacs is free software: you can redistribute it and/or modify | |
13 | ;; it under the terms of the GNU General Public License as published by | |
14 | ;; the Free Software Foundation, either version 3 of the License, or | |
15 | ;; (at your option) any later version. | |
16 | ||
17 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | ;; GNU General Public License for more details. | |
21 | ||
22 | ;; You should have received a copy of the GNU General Public License | |
23 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |
24 | ||
25 | ;;; Commentary: | |
26 | ||
27 | ;; This is the simplest of code blocks, where upon evaluation the | |
28 | ;; contents of the code block are returned in a raw result. | |
29 | ||
30 | ;;; Code: | |
31 | (require 'ob) | |
32 | ||
33 | (declare-function org-export-string "org-exp" (string fmt &optional dir)) | |
34 | ||
35 | (defvar org-babel-default-header-args:org | |
36 | '((:results . "raw silent") (:exports . "results")) | |
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 | |
46 | (regexp-quote (format "$%s" (car var))) (cdr var) body | |
47 | nil 'literal))) | |
48 | body) | |
49 | ||
afe98dfa CD |
50 | (defun org-babel-execute:org (body params) |
51 | "Execute a block of Org code with. | |
52 | This function is called by `org-babel-execute-src-block'." | |
53 | (let ((result-params (split-string (or (cdr (assoc :results params)) ""))) | |
3ab2c837 BG |
54 | (body (org-babel-expand-body:org |
55 | (replace-regexp-in-string "^," "" body) params))) | |
afe98dfa | 56 | (cond |
3ab2c837 BG |
57 | ((member "latex" result-params) (org-export-string |
58 | (concat "#+Title: \n" body) "latex")) | |
afe98dfa CD |
59 | ((member "html" result-params) (org-export-string body "html")) |
60 | ((member "ascii" result-params) (org-export-string body "ascii")) | |
61 | (t body)))) | |
62 | ||
63 | (defun org-babel-prep-session:org (session params) | |
64 | "Return an error because org does not support sessions." | |
65 | (error "Org does not support sessions")) | |
66 | ||
67 | (provide 'ob-org) | |
68 | ||
3ab2c837 | 69 | ;; arch-tag: 130af5fe-cc56-46bd-9508-fa0ebd94cb1f |
afe98dfa CD |
70 | |
71 | ;;; ob-org.el ends here |