emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] org-babel-execute-src-block-region
@ 2015-11-02  2:17 Carlos Henrique Machado S Esteves
  2015-11-02 18:19 ` Charles C. Berry
  0 siblings, 1 reply; 9+ messages in thread
From: Carlos Henrique Machado S Esteves @ 2015-11-02  2:17 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 262 bytes --]

Hello, I find it useful to be able to execute only a region of a source
code block, so I've implemented a new function for that. I've tested it
with MATLAB and Python, but it should work for any mode, since it calls
org-babel-execute-src-block.

Thanks,

Carlos

[-- Attachment #1.2: Type: text/html, Size: 341 bytes --]

[-- Attachment #2: 0001-ob-core.el-Allow-execution-of-region-of-source-code-.patch --]
[-- Type: text/x-patch, Size: 1353 bytes --]

From d3f67fb0f37667af39a30c527221a43ea37999a9 Mon Sep 17 00:00:00 2001
From: Carlos HMS Esteves <ch.machado.esteves@gmail.com>
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 | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 51a34f3..98ed69e 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -740,6 +740,15 @@ 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")
+  (let ((info (org-babel-get-src-block-info)))
+    (setcar (nthcdr 1 info) (buffer-substring beg end))
+    (org-babel-execute-src-block nil info)))
+
 (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


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-11-11 21:53 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-02  2:17 [PATCH] org-babel-execute-src-block-region Carlos Henrique Machado S Esteves
2015-11-02 18:19 ` Charles C. Berry
2015-11-10 18:19   ` Carlos Henrique Machado S Esteves
2015-11-11  0:08     ` Nicolas Goaziou
2015-11-11  5:10     ` Xebar Saram
2015-11-11 13:44       ` Ista Zahn
2015-11-11 17:43         ` Charles C. Berry
2015-11-11 18:55           ` Xebar Saram
2015-11-11 21:53             ` Charles C. Berry

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).