2010-06-11 23:02:42 +00:00
|
|
|
;;; ob-exp.el --- Exportation of org-babel source blocks
|
2009-04-23 22:48:22 +00:00
|
|
|
|
2016-01-09 22:12:03 +00:00
|
|
|
;; Copyright (C) 2009-2016 Free Software Foundation, Inc.
|
2009-04-23 22:48:22 +00:00
|
|
|
|
2012-04-01 22:53:28 +00:00
|
|
|
;; Authors: Eric Schulte
|
2011-08-24 18:55:11 +00:00
|
|
|
;; Dan Davison
|
2009-04-23 22:48:22 +00:00
|
|
|
;; Keywords: literate programming, reproducible research
|
|
|
|
;; Homepage: http://orgmode.org
|
|
|
|
|
2010-06-25 16:20:39 +00:00
|
|
|
;; This file is part of GNU Emacs.
|
2009-04-23 22:48:22 +00:00
|
|
|
|
2010-06-25 16:20:39 +00:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2009-04-23 22:48:22 +00:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2010-06-25 16:20:39 +00:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
2009-04-23 22:48:22 +00:00
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
2010-06-25 16:20:39 +00:00
|
|
|
|
2009-04-23 22:48:22 +00:00
|
|
|
;; You should have received a copy of the GNU General Public License
|
2010-06-25 16:20:39 +00:00
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
2009-04-23 22:48:22 +00:00
|
|
|
|
|
|
|
;;; Code:
|
2012-12-11 23:58:16 +00:00
|
|
|
(require 'ob-core)
|
2010-06-13 01:32:23 +00:00
|
|
|
|
2016-01-28 10:18:50 +00:00
|
|
|
(declare-function org-babel-lob-get-info "ob-lob" (&optional datum))
|
2013-11-24 23:24:54 +00:00
|
|
|
(declare-function org-element-at-point "org-element" ())
|
2016-05-15 02:56:53 +00:00
|
|
|
(declare-function org-element-context "org-element" (&optional element))
|
2012-08-19 20:19:59 +00:00
|
|
|
(declare-function org-element-property "org-element" (property element))
|
|
|
|
(declare-function org-element-type "org-element" (element))
|
2016-06-18 20:11:14 +00:00
|
|
|
(declare-function org-export-copy-buffer "ox" ())
|
|
|
|
(declare-function org-fill-template "org" (template alist))
|
|
|
|
(declare-function org-get-indentation "org" (&optional line))
|
|
|
|
(declare-function org-heading-components "org" ())
|
|
|
|
(declare-function org-in-commented-heading-p "org" (&optional no-inheritance))
|
|
|
|
|
|
|
|
(defvar org-src-preserve-indentation)
|
2010-06-13 01:32:23 +00:00
|
|
|
|
2010-07-08 17:28:47 +00:00
|
|
|
(defcustom org-export-babel-evaluate t
|
|
|
|
"Switch controlling code evaluation during export.
|
2010-09-26 10:39:43 +00:00
|
|
|
When set to nil no code will be evaluated as part of the export
|
2015-09-21 04:24:12 +00:00
|
|
|
process. When set to `inline-only', only inline code blocks will
|
2013-03-31 22:47:44 +00:00
|
|
|
be executed."
|
2010-07-08 17:28:47 +00:00
|
|
|
:group 'org-babel
|
2012-03-19 20:38:12 +00:00
|
|
|
:version "24.1"
|
2013-03-31 22:47:44 +00:00
|
|
|
:type '(choice (const :tag "Never" nil)
|
|
|
|
(const :tag "Only inline code" inline-only)
|
|
|
|
(const :tag "Always" t)))
|
2010-07-08 22:11:38 +00:00
|
|
|
(put 'org-export-babel-evaluate 'safe-local-variable (lambda (x) (eq x nil)))
|
2010-07-08 17:28:47 +00:00
|
|
|
|
2016-06-18 21:15:24 +00:00
|
|
|
(defmacro org-babel-exp--at-source (&rest body)
|
|
|
|
"Evaluate BODY at the source of the Babel block at point.
|
|
|
|
Source is located in `org-babel-exp-reference-buffer'. The value
|
|
|
|
returned is the value of the last form in BODY. Assume that
|
|
|
|
point is at the beginning of the Babel block."
|
|
|
|
(declare (indent 1) (debug body))
|
|
|
|
`(let ((source (get-text-property (point) 'org-reference)))
|
|
|
|
(with-current-buffer org-babel-exp-reference-buffer
|
|
|
|
(org-with-wide-buffer
|
|
|
|
(goto-char source)
|
|
|
|
,@body))))
|
|
|
|
|
|
|
|
(defun org-babel-exp-src-block ()
|
2010-07-13 23:04:47 +00:00
|
|
|
"Process source block for export.
|
2016-06-18 21:15:24 +00:00
|
|
|
Depending on the \":export\" header argument, replace the source
|
2013-04-10 14:19:04 +00:00
|
|
|
code block like this:
|
2009-04-23 22:48:22 +00:00
|
|
|
|
2009-08-17 18:19:25 +00:00
|
|
|
both ---- display the code and the results
|
2009-04-23 22:48:22 +00:00
|
|
|
|
2009-08-17 18:19:25 +00:00
|
|
|
code ---- the default, display the code inside the block but do
|
|
|
|
not process
|
2009-04-23 22:48:22 +00:00
|
|
|
|
2009-09-01 21:42:14 +00:00
|
|
|
results - just like none only the block is run on export ensuring
|
2016-06-18 21:15:24 +00:00
|
|
|
that its results are present in the Org mode buffer
|
2009-04-23 22:48:22 +00:00
|
|
|
|
2013-04-10 14:19:04 +00:00
|
|
|
none ---- do not display either code or results upon export
|
2012-08-19 20:07:55 +00:00
|
|
|
|
2016-06-18 21:15:24 +00:00
|
|
|
Assume point is at block opening line."
|
2009-04-23 22:48:22 +00:00
|
|
|
(interactive)
|
2010-06-17 16:29:38 +00:00
|
|
|
(save-excursion
|
2010-10-15 15:13:51 +00:00
|
|
|
(let* ((info (org-babel-get-src-block-info 'light))
|
2010-09-19 01:01:49 +00:00
|
|
|
(lang (nth 0 info))
|
2016-06-18 21:15:24 +00:00
|
|
|
(raw-params (nth 2 info))
|
|
|
|
hash)
|
2010-07-16 22:34:57 +00:00
|
|
|
;; bail if we couldn't get any info from the block
|
2013-11-07 15:24:53 +00:00
|
|
|
(unless noninteractive
|
2016-05-20 11:38:57 +00:00
|
|
|
(message "org-babel-exp process %s at position %d..."
|
2016-06-18 21:15:24 +00:00
|
|
|
lang
|
|
|
|
(line-beginning-position)))
|
2010-07-16 22:34:57 +00:00
|
|
|
(when info
|
2011-02-27 18:01:56 +00:00
|
|
|
;; if we're actually going to need the parameters
|
2016-06-18 21:15:24 +00:00
|
|
|
(when (member (cdr (assq :exports (nth 2 info))) '("both" "results"))
|
|
|
|
(let ((lang-headers (intern (concat "org-babel-default-header-args:"
|
|
|
|
lang))))
|
|
|
|
(org-babel-exp--at-source
|
|
|
|
(setf (nth 2 info)
|
|
|
|
(org-babel-process-params
|
|
|
|
(apply #'org-babel-merge-params
|
|
|
|
org-babel-default-header-args
|
|
|
|
(and (boundp lang-headers) (eval lang-headers))
|
|
|
|
(append (org-babel-params-from-properties lang)
|
|
|
|
(list raw-params)))))))
|
2011-02-27 18:01:56 +00:00
|
|
|
(setf hash (org-babel-sha1-hash info)))
|
|
|
|
(org-babel-exp-do-export info 'block hash)))))
|
2009-04-26 20:29:59 +00:00
|
|
|
|
2012-03-19 20:38:12 +00:00
|
|
|
(defcustom org-babel-exp-call-line-template
|
|
|
|
""
|
|
|
|
"Template used to export call lines.
|
|
|
|
This template may be customized to include the call line name
|
|
|
|
with any export markup. The template is filled out using
|
|
|
|
`org-fill-template', and the following %keys may be used.
|
|
|
|
|
|
|
|
line --- call line
|
|
|
|
|
|
|
|
An example value would be \"\\n: call: %line\" to export the call line
|
|
|
|
wrapped in a verbatim environment.
|
|
|
|
|
|
|
|
Note: the results are inserted separately after the contents of
|
|
|
|
this template."
|
|
|
|
:group 'org-babel
|
|
|
|
:type 'string)
|
|
|
|
|
2016-06-18 20:11:14 +00:00
|
|
|
(defun org-babel-exp-process-buffer ()
|
|
|
|
"Execute all Babel blocks in current buffer."
|
2009-04-26 20:29:59 +00:00
|
|
|
(interactive)
|
2016-04-28 15:25:31 +00:00
|
|
|
(when org-export-babel-evaluate
|
|
|
|
(save-window-excursion
|
2016-06-18 21:15:24 +00:00
|
|
|
(let ((case-fold-search t)
|
|
|
|
(regexp (if (eq org-export-babel-evaluate 'inline-only)
|
|
|
|
"\\(call\\|src\\)_"
|
|
|
|
"\\(call\\|src\\)_\\|^[ \t]*#\\+\\(BEGIN_SRC\\|CALL:\\)"))
|
|
|
|
;; Get a pristine copy of current buffer so Babel
|
|
|
|
;; references are properly resolved and source block
|
|
|
|
;; context is preserved.
|
|
|
|
(org-babel-exp-reference-buffer (org-export-copy-buffer)))
|
|
|
|
(unwind-protect
|
|
|
|
(save-excursion
|
|
|
|
;; First attach to every source block their original
|
|
|
|
;; position, so that they can be retrieved within
|
|
|
|
;; `org-babel-exp-reference-buffer', even after heavy
|
|
|
|
;; modifications on current buffer.
|
|
|
|
;;
|
|
|
|
;; False positives are harmless, so we don't check if
|
|
|
|
;; we're really at some Babel object. Moreover,
|
|
|
|
;; `line-end-position' ensures that we propertize
|
|
|
|
;; a noticeable part of the object, without affecting
|
|
|
|
;; multiple objects on the same line.
|
|
|
|
(goto-char (point-min))
|
|
|
|
(while (re-search-forward regexp nil t)
|
|
|
|
(let ((s (match-beginning 0)))
|
|
|
|
(put-text-property s (line-end-position) 'org-reference s)))
|
|
|
|
;; Evaluate from top to bottom every Babel block
|
|
|
|
;; encountered.
|
|
|
|
(goto-char (point-min))
|
2016-06-18 20:11:14 +00:00
|
|
|
(while (re-search-forward regexp nil t)
|
|
|
|
(unless (save-match-data (org-in-commented-heading-p))
|
|
|
|
(let* ((element (save-match-data (org-element-context)))
|
|
|
|
(type (org-element-type element))
|
|
|
|
(begin
|
|
|
|
(copy-marker (org-element-property :begin element)))
|
|
|
|
(end
|
|
|
|
(copy-marker
|
2016-04-28 15:25:31 +00:00
|
|
|
(save-excursion
|
|
|
|
(goto-char (org-element-property :end element))
|
|
|
|
(skip-chars-backward " \r\t\n")
|
|
|
|
(point)))))
|
2016-06-18 21:24:22 +00:00
|
|
|
(pcase type
|
|
|
|
(`inline-src-block
|
2016-06-18 20:11:14 +00:00
|
|
|
(let* ((info
|
|
|
|
(org-babel-get-src-block-info nil element))
|
|
|
|
(params (nth 2 info)))
|
|
|
|
(setf (nth 1 info)
|
|
|
|
(if (and (cdr (assoc :noweb params))
|
|
|
|
(string= "yes"
|
|
|
|
(cdr (assq :noweb params))))
|
|
|
|
(org-babel-expand-noweb-references
|
|
|
|
info org-babel-exp-reference-buffer)
|
|
|
|
(nth 1 info)))
|
|
|
|
(goto-char begin)
|
|
|
|
(let ((replacement
|
|
|
|
(org-babel-exp-do-export info 'inline)))
|
|
|
|
(if (equal replacement "")
|
|
|
|
;; Replacement code is empty: remove
|
|
|
|
;; inline source block, including extra
|
|
|
|
;; white space that might have been
|
|
|
|
;; created when inserting results.
|
|
|
|
(delete-region begin
|
|
|
|
(progn (goto-char end)
|
|
|
|
(skip-chars-forward " \t")
|
|
|
|
(point)))
|
|
|
|
;; Otherwise: remove inline src block but
|
|
|
|
;; preserve following white spaces. Then
|
|
|
|
;; insert value.
|
|
|
|
(delete-region begin end)
|
|
|
|
(insert replacement)))))
|
2016-06-18 21:24:22 +00:00
|
|
|
((or `babel-call `inline-babel-call)
|
2016-06-18 20:11:14 +00:00
|
|
|
(let ((results (org-babel-exp-do-export
|
|
|
|
(org-babel-lob-get-info element)
|
|
|
|
'lob))
|
|
|
|
(rep
|
|
|
|
(org-fill-template
|
|
|
|
org-babel-exp-call-line-template
|
|
|
|
`(("line" .
|
|
|
|
,(org-element-property :value element))))))
|
|
|
|
;; If replacement is empty, completely remove
|
|
|
|
;; the object/element, including any extra
|
|
|
|
;; white space that might have been created
|
|
|
|
;; when including results.
|
|
|
|
(if (equal rep "")
|
|
|
|
(delete-region
|
|
|
|
begin
|
|
|
|
(progn (goto-char end)
|
|
|
|
(if (not (eq type 'babel-call))
|
|
|
|
(progn (skip-chars-forward " \t")
|
|
|
|
(point))
|
|
|
|
(skip-chars-forward " \r\t\n")
|
|
|
|
(line-beginning-position))))
|
|
|
|
;; Otherwise, preserve trailing
|
|
|
|
;; spaces/newlines and then, insert
|
|
|
|
;; replacement string.
|
|
|
|
(goto-char begin)
|
|
|
|
(delete-region begin end)
|
|
|
|
(insert rep))))
|
2016-06-18 21:24:22 +00:00
|
|
|
(`src-block
|
2016-06-18 20:11:14 +00:00
|
|
|
(let* ((match-start (copy-marker (match-beginning 0)))
|
|
|
|
(ind (org-get-indentation))
|
|
|
|
(lang
|
|
|
|
(or (org-element-property :language element)
|
|
|
|
(user-error
|
|
|
|
"No language for src block: %s"
|
|
|
|
(or (org-element-property :name element)
|
2016-06-18 21:15:24 +00:00
|
|
|
"(unnamed)")))))
|
2016-06-18 20:11:14 +00:00
|
|
|
;; Take care of matched block: compute
|
|
|
|
;; replacement string. In particular, a nil
|
|
|
|
;; REPLACEMENT means the block is left as-is
|
|
|
|
;; while an empty string removes the block.
|
|
|
|
(let ((replacement
|
|
|
|
(progn (goto-char match-start)
|
2016-06-18 21:15:24 +00:00
|
|
|
(org-babel-exp-src-block))))
|
2016-06-18 20:11:14 +00:00
|
|
|
(cond ((not replacement) (goto-char end))
|
|
|
|
((equal replacement "")
|
|
|
|
(goto-char end)
|
|
|
|
(skip-chars-forward " \r\t\n")
|
|
|
|
(beginning-of-line)
|
|
|
|
(delete-region begin (point)))
|
|
|
|
(t
|
|
|
|
(goto-char match-start)
|
|
|
|
(delete-region (point)
|
|
|
|
(save-excursion
|
|
|
|
(goto-char end)
|
|
|
|
(line-end-position)))
|
|
|
|
(insert replacement)
|
|
|
|
(if (or org-src-preserve-indentation
|
|
|
|
(org-element-property
|
|
|
|
:preserve-indent element))
|
|
|
|
;; Indent only code block
|
|
|
|
;; markers.
|
|
|
|
(save-excursion
|
|
|
|
(skip-chars-backward " \r\t\n")
|
|
|
|
(indent-line-to ind)
|
|
|
|
(goto-char match-start)
|
|
|
|
(indent-line-to ind))
|
|
|
|
;; Indent everything.
|
|
|
|
(indent-rigidly
|
|
|
|
match-start (point) ind)))))
|
|
|
|
(set-marker match-start nil))))
|
|
|
|
(set-marker begin nil)
|
2016-06-18 21:15:24 +00:00
|
|
|
(set-marker end nil)))))
|
|
|
|
(kill-buffer org-babel-exp-reference-buffer)
|
|
|
|
(remove-text-properties (point-min) (point-max) '(org-reference)))))))
|
2012-08-19 20:19:59 +00:00
|
|
|
|
2011-02-27 18:01:56 +00:00
|
|
|
(defun org-babel-exp-do-export (info type &optional hash)
|
2010-07-13 23:04:47 +00:00
|
|
|
"Return a string with the exported content of a code block.
|
|
|
|
The function respects the value of the :exports header argument."
|
2012-08-09 14:13:18 +00:00
|
|
|
(let ((silently (lambda () (let ((session (cdr (assoc :session (nth 2 info)))))
|
2016-02-10 13:48:06 +00:00
|
|
|
(unless (equal "none" session)
|
|
|
|
(org-babel-exp-results info type 'silent)))))
|
2015-01-29 20:05:31 +00:00
|
|
|
(clean (lambda () (if (eq type 'inline)
|
2016-02-10 13:48:06 +00:00
|
|
|
(org-babel-remove-inline-result)
|
|
|
|
(org-babel-remove-result info)))))
|
|
|
|
(pcase (or (cdr (assq :exports (nth 2 info))) "code")
|
|
|
|
("none" (funcall silently) (funcall clean) "")
|
|
|
|
("code" (funcall silently) (funcall clean) (org-babel-exp-code info type))
|
|
|
|
("results" (org-babel-exp-results info type nil hash) "")
|
|
|
|
("both"
|
|
|
|
(org-babel-exp-results info type nil hash)
|
|
|
|
(org-babel-exp-code info type)))))
|
2011-05-19 13:37:33 +00:00
|
|
|
|
2012-03-19 20:38:12 +00:00
|
|
|
(defcustom org-babel-exp-code-template
|
2014-01-29 08:01:43 +00:00
|
|
|
"#+BEGIN_SRC %lang%switches%flags\n%body\n#+END_SRC"
|
2012-03-19 20:38:12 +00:00
|
|
|
"Template used to export the body of code blocks.
|
|
|
|
This template may be customized to include additional information
|
|
|
|
such as the code block name, or the values of particular header
|
|
|
|
arguments. The template is filled out using `org-fill-template',
|
|
|
|
and the following %keys may be used.
|
|
|
|
|
|
|
|
lang ------ the language of the code block
|
|
|
|
name ------ the name of the code block
|
|
|
|
body ------ the body of the code block
|
2014-01-29 08:01:43 +00:00
|
|
|
switches -- the switches associated to the code block
|
2012-03-19 20:38:12 +00:00
|
|
|
flags ----- the flags passed to the code block
|
|
|
|
|
|
|
|
In addition to the keys mentioned above, every header argument
|
|
|
|
defined for the code block may be used as a key and will be
|
|
|
|
replaced with its value."
|
|
|
|
:group 'org-babel
|
|
|
|
:type 'string)
|
|
|
|
|
2014-06-13 13:32:54 +00:00
|
|
|
(defcustom org-babel-exp-inline-code-template
|
|
|
|
"src_%lang[%switches%flags]{%body}"
|
|
|
|
"Template used to export the body of inline code blocks.
|
|
|
|
This template may be customized to include additional information
|
|
|
|
such as the code block name, or the values of particular header
|
|
|
|
arguments. The template is filled out using `org-fill-template',
|
|
|
|
and the following %keys may be used.
|
|
|
|
|
|
|
|
lang ------ the language of the code block
|
|
|
|
name ------ the name of the code block
|
|
|
|
body ------ the body of the code block
|
|
|
|
switches -- the switches associated to the code block
|
|
|
|
flags ----- the flags passed to the code block
|
|
|
|
|
|
|
|
In addition to the keys mentioned above, every header argument
|
|
|
|
defined for the code block may be used as a key and will be
|
|
|
|
replaced with its value."
|
|
|
|
:group 'org-babel
|
|
|
|
:type 'string
|
2014-10-24 09:56:09 +00:00
|
|
|
:version "25.1"
|
2014-06-13 13:32:54 +00:00
|
|
|
:package-version '(Org . "8.3"))
|
|
|
|
|
|
|
|
(defun org-babel-exp-code (info type)
|
2011-05-19 13:37:33 +00:00
|
|
|
"Return the original code block formatted for export."
|
2012-03-31 15:28:37 +00:00
|
|
|
(setf (nth 1 info)
|
|
|
|
(if (string= "strip-export" (cdr (assoc :noweb (nth 2 info))))
|
|
|
|
(replace-regexp-in-string
|
|
|
|
(org-babel-noweb-wrap) "" (nth 1 info))
|
|
|
|
(if (org-babel-noweb-p (nth 2 info) :export)
|
|
|
|
(org-babel-expand-noweb-references
|
2014-03-14 14:27:32 +00:00
|
|
|
info org-babel-exp-reference-buffer)
|
2012-03-31 15:28:37 +00:00
|
|
|
(nth 1 info))))
|
2011-05-19 17:05:41 +00:00
|
|
|
(org-fill-template
|
2014-06-13 13:32:54 +00:00
|
|
|
(if (eq type 'inline)
|
2015-08-10 05:18:52 +00:00
|
|
|
org-babel-exp-inline-code-template
|
2014-06-13 13:32:54 +00:00
|
|
|
org-babel-exp-code-template)
|
2011-05-19 17:05:41 +00:00
|
|
|
`(("lang" . ,(nth 0 info))
|
2016-06-17 12:16:39 +00:00
|
|
|
("body" . ,(nth 1 info))
|
2014-01-29 08:01:43 +00:00
|
|
|
("switches" . ,(let ((f (nth 3 info)))
|
|
|
|
(and (org-string-nw-p f) (concat " " f))))
|
2014-01-20 13:07:57 +00:00
|
|
|
("flags" . ,(let ((f (assq :flags (nth 2 info))))
|
2014-01-29 08:01:43 +00:00
|
|
|
(and f (concat " " (cdr f)))))
|
2012-03-19 20:38:12 +00:00
|
|
|
,@(mapcar (lambda (pair)
|
|
|
|
(cons (substring (symbol-name (car pair)) 1)
|
|
|
|
(format "%S" (cdr pair))))
|
|
|
|
(nth 2 info))
|
|
|
|
("name" . ,(or (nth 4 info) "")))))
|
2009-04-23 22:48:22 +00:00
|
|
|
|
2011-02-27 18:01:56 +00:00
|
|
|
(defun org-babel-exp-results (info type &optional silent hash)
|
2010-07-13 23:04:47 +00:00
|
|
|
"Evaluate and return the results of the current code block for export.
|
2016-02-10 21:47:09 +00:00
|
|
|
Results are prepared in a manner suitable for export by Org mode.
|
2010-07-13 23:04:47 +00:00
|
|
|
This function is called by `org-babel-exp-do-export'. The code
|
|
|
|
block will be evaluated. Optional argument SILENT can be used to
|
|
|
|
inhibit insertion of results into the buffer."
|
2016-04-28 15:25:31 +00:00
|
|
|
(unless (and hash (equal hash (org-babel-current-result-hash)))
|
2011-01-27 19:48:45 +00:00
|
|
|
(let ((lang (nth 0 info))
|
2012-03-31 15:28:37 +00:00
|
|
|
(body (if (org-babel-noweb-p (nth 2 info) :eval)
|
|
|
|
(org-babel-expand-noweb-references
|
2014-03-14 14:27:32 +00:00
|
|
|
info org-babel-exp-reference-buffer)
|
2012-03-31 15:28:37 +00:00
|
|
|
(nth 1 info)))
|
2013-06-08 18:00:53 +00:00
|
|
|
(info (copy-sequence info))
|
2013-06-08 19:19:38 +00:00
|
|
|
(org-babel-current-src-block-location (point-marker)))
|
2016-02-09 23:22:09 +00:00
|
|
|
;; Skip code blocks which we can't evaluate.
|
2011-01-27 19:48:45 +00:00
|
|
|
(when (fboundp (intern (concat "org-babel-execute:" lang)))
|
|
|
|
(org-babel-eval-wipe-error-buffer)
|
2016-06-18 21:15:24 +00:00
|
|
|
(setf (nth 1 info) body)
|
|
|
|
(setf (nth 2 info)
|
|
|
|
(org-babel-exp--at-source
|
|
|
|
(org-babel-process-params
|
|
|
|
(org-babel-merge-params
|
|
|
|
(nth 2 info)
|
|
|
|
`((:results . ,(if silent "silent" "replace")))))))
|
|
|
|
(pcase type
|
|
|
|
(`block (org-babel-execute-src-block nil info))
|
|
|
|
(`inline
|
|
|
|
;; Position the point on the inline source block
|
|
|
|
;; allowing `org-babel-insert-result' to check that the
|
|
|
|
;; block is inline.
|
|
|
|
(goto-char (nth 5 info))
|
|
|
|
(org-babel-execute-src-block nil info))
|
|
|
|
(`lob
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (nth 5 info))
|
|
|
|
(let (org-confirm-babel-evaluate)
|
|
|
|
(org-babel-execute-src-block nil info)))))))))
|
2009-09-12 18:14:09 +00:00
|
|
|
|
2011-08-15 18:04:38 +00:00
|
|
|
|
2012-08-19 20:19:59 +00:00
|
|
|
(provide 'ob-exp)
|
2010-06-25 16:20:39 +00:00
|
|
|
|
2010-06-11 23:02:42 +00:00
|
|
|
;;; ob-exp.el ends here
|