From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: [PATCH 03/10] Clean up various org-babel-*-maybe commands Date: Sat, 20 Apr 2013 04:10:05 -0600 Message-ID: <87ehe47pwy.fsf@gmail.com> References: <1364794944-13826-1-git-send-email-aaronecay@gmail.com> <1364794944-13826-4-git-send-email-aaronecay@gmail.com> <87sj37snn0.fsf@bzg.ath.cx> <87li8gs4kn.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([208.118.235.92]:51356) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UTh29-0003N9-KK for emacs-orgmode@gnu.org; Sat, 20 Apr 2013 19:17:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UTh28-0005Re-6Z for emacs-orgmode@gnu.org; Sat, 20 Apr 2013 19:17:29 -0400 Received: from mail-pd0-f181.google.com ([209.85.192.181]:36647) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UTh28-0005RY-0a for emacs-orgmode@gnu.org; Sat, 20 Apr 2013 19:17:28 -0400 Received: by mail-pd0-f181.google.com with SMTP id y10so2861234pdj.12 for ; Sat, 20 Apr 2013 16:17:27 -0700 (PDT) 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: Bastien Cc: emacs-orgmode@gnu.org Aaron Ecay writes: > Hi Bastien, > > Thanks for your comments. > > 2013ko apirilak 3an, Bastien-ek idatzi zuen: > > [...] > >>> org-babel-get-src-block-info is a potentially expensive operation, which >>> is why its =E2=80=98light=E2=80=99 argument exists. But in any case, i= t is overkill to >>> query the whole info, if all that is needed is whether point is in a >>> block or not. Factor the simplified common code out into a macro. >>=20 >> The let-bound info variable is not only used to check if we are within >> a src block, it is also passed as an argument to functions, see the ^^ >> marks below. > > All of these functions will re-calculate the info if it is not > passed, using org-babel-get-src-block-info. So not passing it does no > harm. > Could re-calculating the info cause referenced blocks to be executed more than once? If so then we should continue passing the info and *not* simply re-calculate it later on. Cheers, > >>=20 >>> --- >>> lisp/ob-core.el | 31 +++++++++++++++++-------------- >>> 1 file changed, 17 insertions(+), 14 deletions(-) >>>=20 >>> diff --git a/lisp/ob-core.el b/lisp/ob-core.el >>> index 723aa9d..283628e 100644 >>> --- a/lisp/ob-core.el >>> +++ b/lisp/ob-core.el >>> @@ -365,15 +365,22 @@ of potentially harmful code." >>> (or (org-babel-execute-src-block-maybe) >>> (org-babel-lob-execute-maybe))) >>>=20 >>> +(defmacro org-babel-when-in-src-block (&rest body) >>> + `(if (or (org-babel-where-is-src-block-head) >>> + (org-babel-get-inline-src-block-matches)) >>> + (progn >>> + ,@body >>> + t) >>> + nil)) >>=20 >> (Please always add a docstring of defuns and defmacros) > > I=E2=80=99ll resend the patch with a docstring and fixing the commit mess= age > problems you and Achim pointed out. > > > [...] > > >>> @@ -433,8 +436,8 @@ then run `org-babel-load-in-session'." >>> Detect if this is context for a org-babel src-block and if so >>> then run `org-babel-pop-to-session'." >>> (interactive) >>> - (let ((info (org-babel-get-src-block-info))) >>> - (if info (progn (org-babel-pop-to-session current-prefix-arg info)= t) nil))) >> ^^^^ >>> + (org-babel-when-in-src-block >>> + (org-babel-pop-to-session current-prefix-arg))) >>=20 >> (Let's use the current name `org-babel-switch-to-session' instead of >> the obsolete alias.) > > OK. > >>=20 >> Maybe we don't always need to pass the info as an argument, but at >> least for this last example it is needed. > > o-b-switch-to-session does nothing with the info argument but pass it > along to o-b-initiate-session, which will recalculate it if it is > missing. So it takes 2 hops in contrast to the 1 in the other cases, > but it still gets recalculated. --=20 Eric Schulte http://cs.unm.edu/~eschulte