emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: Carlos Henrique Machado S Esteves <ch.machado.esteves@gmail.com>
Cc: emacs-orgmode@gnu.org, "Charles C. Berry" <ccberry@ucsd.edu>
Subject: Re: [PATCH] org-babel-execute-src-block-region
Date: Wed, 11 Nov 2015 01:08:21 +0100	[thread overview]
Message-ID: <87si4d8kju.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <CAMXw3=ZvyBYH40HSrduY_99sWEf3wmaxjAnpaJXKxivYz+_U5g@mail.gmail.com> (Carlos Henrique Machado S. Esteves's message of "Tue, 10 Nov 2015 13:19:35 -0500")

Hello,

Carlos Henrique Machado S Esteves <ch.machado.esteves@gmail.com> writes:

> You are right, I've updated the patch.

Thank you. Some comments follow.

> * 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.

It should be:

* ob-core.el (org-babel-execute-src-block-region,
  org-babel-is-region-within-src-block): New functions.

Note that you may want to rename the latter
`org-babel--region-within-src-block-p' since it is an internal
predicate.

> +(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."

You need to reference BEG and END arguments. It could be as simple as

  "BEG and END mark the limit of the region."

> +  (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))

Nitpick time:

  (setf (nth 1 info) (buffer-substring beg end))

is clearer, IMO.

> +	(org-babel-execute-src-block nil info))
> +    (message "Region not in src-block!")))

Isn't it a user error instead? In this case, please remove exclamation
mark the end of the message.

> +(defun org-babel-is-region-within-src-block (beg end)
> +  "Check if region is within a single src-block.

Non-nil if region is within the code part of a source 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)))))

I think the following is more efficient (untested, though)

  (org-with-wide-buffer
   (goto-char beg)
   (let ((case-fold-search t)
         (element (org-element-at-point)))
     (and (eq (org-element-type element) 'src-block)
          (> (line-beginning-position)
             (org-element-property :post-affiliated element))
          (> (progn (goto-char (org-element-property :end element))
                    (skip-chars-backward " \t\n")
                    (line-beginning-position))
             end))))

Regards,

-- 
Nicolas Goaziou

  reply	other threads:[~2015-11-11  0:06 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
2015-11-11  0:08     ` Nicolas Goaziou [this message]
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=87si4d8kju.fsf@nicolasgoaziou.fr \
    --to=mail@nicolasgoaziou.fr \
    --cc=ccberry@ucsd.edu \
    --cc=ch.machado.esteves@gmail.com \
    --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).