emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] [PATCH] org-babel-execute-src-block-region


From: Nicolas Goaziou
Subject: Re: [O] [PATCH] org-babel-execute-src-block-region
Date: Wed, 11 Nov 2015 01:08:21 +0100

Hello,

Carlos Henrique Machado S Esteves <address@hidden> 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 via email to

[Prev in Thread] Current Thread [Next in Thread]