From b677ad4416d9e8dd564a46fcb4136cf6f5a90b29 Mon Sep 17 00:00:00 2001 From: Carlos HMS Esteves Date: Sun, 1 Nov 2015 20:52:26 -0500 Subject: [PATCH] ob-core.el: Allow execution of region of source code block * ob-core.el (org-babel-execute-src-block-region): Execute only active region of the current source block. Same as `org-babel-execute-src-block', but use only the active region instead of the whole block. TINYCHANGE --- lisp/ob-core.el | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lisp/ob-core.el b/lisp/ob-core.el index b8ea12d..a2ef6c1 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -739,6 +739,34 @@ block." (setq call-process-region 'org-babel-call-process-region-original))))))))) +(defun org-babel-execute-src-block-region (beg end) + "Execute region in the current source code block. +`org-babel-execure-src-block' is called; the only change is that +only the active region is sent, instead of the whole block." + (interactive "r") + (if (org-babel-is-region-within-src-block beg end) + (let ((info (org-babel-get-src-block-info))) + (setcar (nthcdr 1 info) (buffer-substring beg end)) + (org-babel-execute-src-block nil info)) + (message "Region not in src-block!"))) + +(defun org-babel-is-region-within-src-block (beg end) + "Check if region is within a single src-block. +Block header and footer are ignored, so we are checking for the +source code only. +Used by `org-babel-execute-src-block-region' to check if region +is executable." + (save-excursion + (eq + (progn + (goto-char beg) + (forward-line -1) + (org-babel-where-is-src-block-head)) + (progn + (goto-char end) + (forward-line 1) + (org-babel-where-is-src-block-head))))) + (defun org-babel-expand-body:generic (body params &optional var-lines) "Expand BODY with PARAMS. Expand a block of code with org-babel according to its header -- 2.1.4