From: Carlos Henrique Machado S Esteves <ch.machado.esteves@gmail.com>
To: "Charles C. Berry" <ccberry@ucsd.edu>
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH] org-babel-execute-src-block-region
Date: Tue, 10 Nov 2015 13:19:35 -0500 [thread overview]
Message-ID: <CAMXw3=ZvyBYH40HSrduY_99sWEf3wmaxjAnpaJXKxivYz+_U5g@mail.gmail.com> (raw)
In-Reply-To: <alpine.OSX.2.20.1511020942130.633@charles-berrys-macbook.local>
[-- Attachment #1.1: Type: text/plain, Size: 1968 bytes --]
Hello Chuck,
Thank you for the feedback.
> You might want to check that point and mark are both inside the src
block. Otherwise, the results are unpredictable.
You are right, I've updated the patch.
> ess-mode, python-mode, sh-mode and octave-mode already provide this
capability (and a lot more) for R, python, shell scripts, octave/matlab and
some other languages from the edit buffer.
I understand that. My idea is to avoid the need to C-c ' back and forth.
Actually that's a problem I have with org-babel; I usually find myself
coding inside the src block and losing many of the major mode
functionalities; switching to the edit buffer often seem too much of a
hassle. Any tips about how to get more major-mode functionalities inside
the src-block? Or should I develop the muscle memory to switch back and
forth to the edit buffer all the time?
> `org-babel-demarcate-block' gives the user the ability to break up src
blocks into smaller pieces so they can be run independently.
Thanks for pointing that; I didn't know about `org-babel-demarcate-block'.
Best,
Carlos
2015-11-02 13:19 GMT-05:00 Charles C. Berry <ccberry@ucsd.edu>:
> On Sun, 1 Nov 2015, Carlos Henrique Machado S Esteves wrote:
>
> 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.
>>
>>
> You might want to check that point and mark are both inside the src block.
> Otherwise, the results are unpredictable.
>
> Also note that:
>
> ess-mode, python-mode, sh-mode and octave-mode already provide this
> capability (and a lot more) for R, python, shell scripts, octave/matlab and
> some other languages from the edit buffer.
>
> `org-babel-demarcate-block' gives the user the ability to break up src
> blocks into smaller pieces so they can be run independently.
>
> Best,
>
> Chuck
>
>
[-- Attachment #1.2: Type: text/html, Size: 2623 bytes --]
[-- Attachment #2: 0001-ob-core.el-Allow-execution-of-region-of-source-code-.patch --]
[-- Type: text/x-patch, Size: 1988 bytes --]
From b677ad4416d9e8dd564a46fcb4136cf6f5a90b29 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 | 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
next prev parent reply other threads:[~2015-11-10 18:19 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAMXw3=ZvyBYH40HSrduY_99sWEf3wmaxjAnpaJXKxivYz+_U5g@mail.gmail.com' \
--to=ch.machado.esteves@gmail.com \
--cc=ccberry@ucsd.edu \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).