From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: [PATCH] org-babel-execute-src-block-region Date: Wed, 11 Nov 2015 01:08:21 +0100 Message-ID: <87si4d8kju.fsf@nicolasgoaziou.fr> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:59925) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZwIvt-0008QL-0O for emacs-orgmode@gnu.org; Tue, 10 Nov 2015 19:06:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZwIvs-0007BV-2A for emacs-orgmode@gnu.org; Tue, 10 Nov 2015 19:06:36 -0500 Received: from relay4-d.mail.gandi.net ([2001:4b98:c:538::196]:57504) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZwIvr-0007BH-SL for emacs-orgmode@gnu.org; Tue, 10 Nov 2015 19:06:36 -0500 In-Reply-To: (Carlos Henrique Machado S. Esteves's message of "Tue, 10 Nov 2015 13:19:35 -0500") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Carlos Henrique Machado S Esteves Cc: emacs-orgmode@gnu.org, "Charles C. Berry" Hello, Carlos Henrique Machado S Esteves 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