summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2020-09-05 23:39:08 -0400
committerKyle Meyer <kyle@kyleam.com>2020-09-05 23:39:08 -0400
commite535da6e4f885dc2c09d3fc7057bee98b99bc6af (patch)
treece00366ccb27f6ebc2edc94f0f5d1c970606bfcf
parentf24c3d11cc65e223950b6be6adcae78fcbd7b972 (diff)
downloadorg-mode-e535da6e4f885dc2c09d3fc7057bee98b99bc6af.tar.gz
ob-core: Avoid duplicate body expansion logic
* lisp/ob-core.el (org-babel--expand-body): New function. (org-babel-check-confirm-evaluate): (org-babel-execute-src-block): Use org-babel--expand-body. As of 727c6d7fe (lisp/ob-core.el: org-babel-check-confirm-evaluate strip coderefs, 2020-09-04), org-babel-check-confirm-evaluate and org-babel-execute-src-block use the same logic to expand the body and strip coderefs. Move that code to a helper function. This patch is functionally equivalent to the patch originally proposed by Tom Gillespie at https://orgmode.org/list/CA+G3_PNi3uMvBiWgBdKuC3C6VJt1T1j-RKH43LRqYbr+4NS8ZA@mail.gmail.com
-rw-r--r--lisp/ob-core.el32
1 files changed, 13 insertions, 19 deletions
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index b13d061..07c20bb 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -240,14 +240,7 @@ should be asked whether to allow evaluation."
(funcall org-confirm-babel-evaluate
;; Language, code block body.
(nth 0 info)
- (let ((coderef (nth 6 info))
- (expand
- (if (org-babel-noweb-p headers :eval)
- (org-babel-expand-noweb-references info)
- (nth 1 info))))
- (if (not coderef) expand
- (replace-regexp-in-string
- (org-src-coderef-regexp coderef) "" expand nil nil 1))))
+ (org-babel--expand-body info))
org-confirm-babel-evaluate))))
(cond
(noeval nil)
@@ -631,6 +624,17 @@ a list with the following pattern:
(setf (nth 2 info) (org-babel-generate-file-param name (nth 2 info)))
info))))
+(defun org-babel--expand-body (info)
+ "Expand noweb references in body and remove any coderefs."
+ (let ((coderef (nth 6 info))
+ (expand
+ (if (org-babel-noweb-p (nth 2 info) :eval)
+ (org-babel-expand-noweb-references info)
+ (nth 1 info))))
+ (if (not coderef) expand
+ (replace-regexp-in-string
+ (org-src-coderef-regexp coderef) "" expand nil nil 1))))
+
;;;###autoload
(defun org-babel-execute-src-block (&optional arg info params)
"Execute the current source code block.
@@ -676,17 +680,7 @@ block."
((org-babel-confirm-evaluate info)
(let* ((lang (nth 0 info))
(result-params (cdr (assq :result-params params)))
- ;; Expand noweb references in BODY and remove any
- ;; coderef.
- (body
- (let ((coderef (nth 6 info))
- (expand
- (if (org-babel-noweb-p params :eval)
- (org-babel-expand-noweb-references info)
- (nth 1 info))))
- (if (not coderef) expand
- (replace-regexp-in-string
- (org-src-coderef-regexp coderef) "" expand nil nil 1))))
+ (body (org-babel--expand-body info))
(dir (cdr (assq :dir params)))
(mkdirp (cdr (assq :mkdirp params)))
(default-directory