annotate lisp/org/ob-exp.el @ 111686:e8049570c647

* lisp/eshell/: Use with-silent-modifications. * lisp/eshell/esh-cmd.el (eshell-parse-command): * lisp/eshell/esh-arg.el (eshell-parse-arguments): * lisp/eshell/em-script.el (eshell-source-file): Use with-silent-modifications.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Tue, 23 Nov 2010 12:36:15 -0500
parents 5cb272c831e8
children a7740098b594
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1 ;;; ob-exp.el --- Exportation of org-babel source blocks
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
2
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
3 ;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
4
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
5 ;; Author: Eric Schulte, Dan Davison
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
6 ;; Keywords: literate programming, reproducible research
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
7 ;; Homepage: http://orgmode.org
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
8 ;; Version: 7.3
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
9
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
11
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
14 ;; the Free Software Foundation, either version 3 of the License, or
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
15 ;; (at your option) any later version.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
16
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
20 ;; GNU General Public License for more details.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
21
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
24
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
25 ;;; Commentary:
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
26
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
27 ;; See the online documentation for more information
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
28 ;;
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
29 ;; http://orgmode.org/worg/org-contrib/babel/
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
30
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
31 ;;; Code:
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
32 (require 'ob)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
33 (require 'org-exp-blocks)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
34 (eval-when-compile
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
35 (require 'cl))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
36
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
37 (defvar obe-marker nil)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
38 (defvar org-current-export-file)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
39 (defvar org-babel-lob-one-liner-regexp)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
40 (defvar org-babel-ref-split-regexp)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
41 (declare-function org-babel-lob-get-info "ob-lob" ())
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
42 (declare-function org-babel-ref-literal "ob-ref" (ref))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
43
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
44 (add-to-list 'org-export-interblocks '(src org-babel-exp-inline-src-blocks))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
45 (add-to-list 'org-export-interblocks '(lob org-babel-exp-lob-one-liners))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
46 (add-hook 'org-export-blocks-postblock-hook 'org-exp-res/src-name-cleanup)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
47
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
48 (org-export-blocks-add-block '(src org-babel-exp-src-blocks nil))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
49
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
50 (defcustom org-export-babel-evaluate t
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
51 "Switch controlling code evaluation during export.
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
52 When set to nil no code will be evaluated as part of the export
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
53 process."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
54 :group 'org-babel
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
55 :type 'boolean)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
56 (put 'org-export-babel-evaluate 'safe-local-variable (lambda (x) (eq x nil)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
57
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
58 (defvar org-babel-function-def-export-keyword "function"
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
59 "The keyword to substitute for the source name line on export.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
60 When exporting a source block function, this keyword will
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
61 appear in the exported version in the place of source name
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
62 line. A source block is considered to be a source block function
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
63 if the source name is present and is followed by a parenthesized
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
64 argument list. The parentheses may be empty or contain
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
65 whitespace. An example is the following which generates n random
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
66 \(uniform) numbers.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
67
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
68 #+source: rand(n)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
69 #+begin_src R
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
70 runif(n)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
71 #+end_src")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
72
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
73 (defvar org-babel-function-def-export-indent 4
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
74 "Number of characters to indent a source block on export.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
75 When exporting a source block function, the block contents will
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
76 be indented by this many characters. See
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
77 `org-babel-function-def-export-name' for the definition of a
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
78 source block function.")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
79
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
80 (defmacro org-babel-exp-in-export-file (&rest body)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
81 `(let* ((lang-headers (intern (concat "org-babel-default-header-args:" lang)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
82 (heading (nth 4 (ignore-errors (org-heading-components))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
83 (link (when org-current-export-file
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
84 (org-make-link-string
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
85 (if heading
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
86 (concat org-current-export-file "::" heading)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
87 org-current-export-file))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
88 (export-buffer (current-buffer)) results)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
89 (when link
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
90 ;; resolve parameters in the original file so that
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
91 ;; headline and file-wide parameters are included, attempt
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
92 ;; to go to the same heading in the original file
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
93 (set-buffer (get-file-buffer org-current-export-file))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
94 (save-restriction
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
95 (condition-case nil
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
96 (org-open-link-from-string link)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
97 (error (when heading
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
98 (goto-char (point-min))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
99 (re-search-forward (regexp-quote heading) nil t))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
100 (setq results ,@body))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
101 (set-buffer export-buffer)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
102 results)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
103
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
104 (defun org-babel-exp-src-blocks (body &rest headers)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
105 "Process source block for export.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
106 Depending on the 'export' headers argument in replace the source
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
107 code block with...
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
108
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
109 both ---- display the code and the results
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
110
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
111 code ---- the default, display the code inside the block but do
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
112 not process
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
113
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
114 results - just like none only the block is run on export ensuring
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
115 that it's results are present in the org-mode buffer
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
116
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
117 none ----- do not display either code or results upon export"
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
118 (interactive)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
119 (message "org-babel-exp processing...")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
120 (save-excursion
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
121 (goto-char (match-beginning 0))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
122 (let* ((info (org-babel-get-src-block-info 'light))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
123 (lang (nth 0 info))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
124 (raw-params (nth 2 info)))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
125 ;; bail if we couldn't get any info from the block
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
126 (when info
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
127 (org-babel-exp-in-export-file
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
128 (setf (nth 2 info)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
129 (org-babel-merge-params
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
130 org-babel-default-header-args
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
131 (org-babel-params-from-buffer)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
132 (org-babel-params-from-properties lang)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
133 (if (boundp lang-headers) (eval lang-headers) nil)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
134 raw-params)))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
135 ;; expand noweb references in the original file
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
136 (setf (nth 1 info)
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
137 (if (and (cdr (assoc :noweb (nth 2 info)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
138 (string= "yes" (cdr (assoc :noweb (nth 2 info)))))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
139 (org-babel-expand-noweb-references
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
140 info (get-file-buffer org-current-export-file))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
141 (nth 1 info)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
142 (org-babel-exp-do-export info 'block)))))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
143
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
144 (defun org-babel-exp-inline-src-blocks (start end)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
145 "Process inline source blocks between START and END for export.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
146 See `org-babel-exp-src-blocks' for export options, currently the
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
147 options and are taken from `org-babel-default-inline-header-args'."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
148 (interactive)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
149 (save-excursion
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
150 (goto-char start)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
151 (while (and (< (point) end)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
152 (re-search-forward org-babel-inline-src-block-regexp end t))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
153 (let* ((info (save-match-data (org-babel-parse-inline-src-block-match)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
154 (params (nth 2 info))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
155 (replacement
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
156 (save-match-data
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
157 (if (org-babel-in-example-or-verbatim)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
158 (buffer-substring (match-beginning 0) (match-end 0))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
159 ;; expand noweb references in the original file
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
160 (setf (nth 1 info)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
161 (if (and (cdr (assoc :noweb params))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
162 (string= "yes" (cdr (assoc :noweb params))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
163 (org-babel-expand-noweb-references
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
164 info (get-file-buffer org-current-export-file))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
165 (nth 1 info)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
166 (org-babel-exp-do-export info 'inline)))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
167 (setq end (+ end (- (length replacement) (length (match-string 1)))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
168 (replace-match replacement t t nil 1)))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
169
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
170 (defun org-exp-res/src-name-cleanup ()
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
171 "Clean up #+results and #+srcname lines for export.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
172 This function should only be called after all block processing
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
173 has taken place."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
174 (interactive)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
175 (save-excursion
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
176 (goto-char (point-min))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
177 (while (org-re-search-forward-unprotected
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
178 (concat
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
179 "\\("org-babel-src-name-regexp"\\|"org-babel-result-regexp"\\)")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
180 nil t)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
181 (delete-region
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
182 (progn (beginning-of-line) (point))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
183 (progn (end-of-line) (+ 1 (point)))))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
184
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
185 (defun org-babel-in-example-or-verbatim ()
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
186 "Return true if point is in example or verbatim code.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
187 Example and verbatim code include escaped portions of
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
188 an org-mode buffer code that should be treated as normal
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
189 org-mode text."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
190 (or (org-in-indented-comment-line)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
191 (save-excursion
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
192 (save-match-data
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
193 (goto-char (point-at-bol))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
194 (looking-at "[ \t]*:[ \t]")))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
195 (org-in-regexps-block-p "^[ \t]*#\\+begin_src" "^[ \t]*#\\+end_src")))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
196
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
197 (defun org-babel-exp-lob-one-liners (start end)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
198 "Process Library of Babel calls between START and END for export.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
199 See `org-babel-exp-src-blocks' for export options. Currently the
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
200 options are taken from `org-babel-default-header-args'."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
201 (interactive)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
202 (let (replacement)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
203 (save-excursion
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
204 (goto-char start)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
205 (while (and (< (point) end)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
206 (re-search-forward org-babel-lob-one-liner-regexp nil t))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
207 (setq replacement
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
208 (let ((lob-info (org-babel-lob-get-info)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
209 (save-match-data
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
210 (org-babel-exp-do-export
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
211 (list "emacs-lisp" "results"
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
212 (org-babel-merge-params
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
213 org-babel-default-header-args
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
214 (org-babel-params-from-buffer)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
215 (org-babel-params-from-properties)
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
216 (org-babel-parse-header-arguments
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
217 (org-babel-clean-text-properties
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
218 (concat ":var results="
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
219 (mapconcat #'identity
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
220 (butlast lob-info) " ")))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
221 (car (last lob-info)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
222 'lob))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
223 (setq end (+ end (- (length replacement) (length (match-string 0)))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
224 (replace-match replacement t t)))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
225
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
226 (defun org-babel-exp-do-export (info type)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
227 "Return a string with the exported content of a code block.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
228 The function respects the value of the :exports header argument."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
229 (flet ((silently () (let ((session (cdr (assoc :session (nth 2 info)))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
230 (when (and session
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
231 (not (equal "none" session)))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
232 (org-babel-exp-results info type 'silent))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
233 (clean () (org-babel-remove-result info)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
234 (case (intern (or (cdr (assoc :exports (nth 2 info))) "code"))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
235 ('none (silently) (clean) "")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
236 ('code (silently) (clean) (org-babel-exp-code info type))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
237 ('results (org-babel-exp-results info type))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
238 ('both (concat (org-babel-exp-code info type)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
239 "\n\n"
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
240 (org-babel-exp-results info type))))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
241
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
242 (defvar backend)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
243 (defun org-babel-exp-code (info type)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
244 "Prepare and return code in the current code block for export.
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
245 Code is prepared in a manner suitable for export by
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
246 org-mode. This function is called by `org-babel-exp-do-export'.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
247 The code block is not evaluated."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
248 (let ((lang (nth 0 info))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
249 (body (nth 1 info))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
250 (switches (nth 3 info))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
251 (name (nth 4 info))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
252 (args (mapcar #'cdr (org-babel-get-header (nth 2 info) :var))))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
253 (case type
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
254 ('inline (format "=%s=" body))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
255 ('block
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
256 (let ((str
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
257 (format "#+BEGIN_SRC %s %s\n%s%s#+END_SRC\n" lang switches body
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
258 (if (and body (string-match "\n$" body))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
259 "" "\n"))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
260 (when name
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
261 (add-text-properties
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
262 0 (length str)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
263 (list 'org-caption
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
264 (format "%s(%s)"
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
265 name
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
266 (mapconcat #'identity args ", ")))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
267 str))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
268 str))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
269 ('lob
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
270 (let ((call-line (and (string-match "results=" (car args))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
271 (substring (car args) (match-end 0)))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
272 (cond
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
273 ((eq backend 'html)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
274 (format "\n#+HTML: <label class=\"org-src-name\">%s</label>\n"
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
275 call-line))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
276 ((format ": %s\n" call-line))))))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
277
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
278 (defun org-babel-exp-results (info type &optional silent)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
279 "Evaluate and return the results of the current code block for export.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
280 Results are prepared in a manner suitable for export by org-mode.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
281 This function is called by `org-babel-exp-do-export'. The code
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
282 block will be evaluated. Optional argument SILENT can be used to
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
283 inhibit insertion of results into the buffer."
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
284 (or
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
285 (when org-export-babel-evaluate
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
286 (let ((lang (nth 0 info))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
287 (body (nth 1 info)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
288 (setf (nth 2 info) (org-babel-exp-in-export-file
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
289 (org-babel-process-params (nth 2 info))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
290 ;; skip code blocks which we can't evaluate
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
291 (when (fboundp (intern (concat "org-babel-execute:" lang)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
292 (if (equal type 'inline)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
293 (let ((raw (org-babel-execute-src-block
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
294 nil info '((:results . "silent"))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
295 (result-params (split-string
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
296 (cdr (assoc :results (nth 2 info))))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
297 (unless silent
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
298 (cond ;; respect the value of the :results header argument
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
299 ((member "file" result-params)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
300 (org-babel-result-to-file raw))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
301 ((or (member "raw" result-params)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
302 (member "org" result-params))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
303 (format "%s" raw))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
304 ((member "code" result-params)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
305 (format "src_%s{%s}" lang raw))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
306 (t
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
307 (if (stringp raw)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
308 (if (= 0 (length raw)) "=(no results)="
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
309 (format "%s" raw))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
310 (format "%S" raw))))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
311 (prog1 nil
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
312 (setf (nth 2 info)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
313 (org-babel-merge-params
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
314 (nth 2 info)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
315 `((:results . ,(if silent "silent" "replace")))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
316 (cond
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
317 ((equal type 'block) (org-babel-execute-src-block nil info))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
318 ((equal type 'lob)
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
319 (save-excursion
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
320 (re-search-backward org-babel-lob-one-liner-regexp nil t)
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
321 (org-babel-execute-src-block nil info)))))))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
322 ""))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
323
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
324 (provide 'ob-exp)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
325
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
326 ;; arch-tag: 523abf4c-76d1-44ed-9f27-e3bddf34bf0f
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
327
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
328 ;;; ob-exp.el ends here