From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id YFI9ATZu6GEmDAEAgWs5BA (envelope-from ) for ; Wed, 19 Jan 2022 21:01:58 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id 4HAQOjVu6GGyEwAA9RJhRA (envelope-from ) for ; Wed, 19 Jan 2022 21:01:57 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id AFF309FA2 for ; Wed, 19 Jan 2022 21:01:57 +0100 (CET) Received: from localhost ([::1]:33018 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAH9Y-0004dI-Hu for larch@yhetil.org; Wed, 19 Jan 2022 15:01:56 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55994) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAH88-0004cm-Tc for emacs-orgmode@gnu.org; Wed, 19 Jan 2022 15:00:32 -0500 Received: from [2a00:1450:4864:20::334] (port=51130 helo=mail-wm1-x334.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nAH87-0002Ws-AZ for emacs-orgmode@gnu.org; Wed, 19 Jan 2022 15:00:28 -0500 Received: by mail-wm1-x334.google.com with SMTP id w26so7497316wmi.0 for ; Wed, 19 Jan 2022 12:00:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=TqrFJblKzyxIlzSAUCnT7nWxU2E+1fudDwfDt3CogfI=; b=PqM71Wd14J3urGKkXJ5Dr/yS2Fg4225DuOuUWBB/i7YYyAL4rQKoRhpo0+ibGlCX6q BdJoHYbpKii6GGwsDyqRfUhncAASEtjLfrDxfv2IjjfYvyWyrSnftqoSOt+wqqHzYiPv q/NZdIDMRo3b0Tsw/nTOmQZ/wyKLz/52EdzEionNM8d1/4zfqOpRCg7AB6F2VuCmSa5s LWHbj5gaBZv+/f1e6KxoBMwADjd/hXHP39jv3Qo9x6EqTlkflZl/QrQ4L2t/1NAobp+G ivP4H9Yz9Tty8R9VjTAvSOcTaDvEk+0G0BPkX/TfR4asL4ef+zr2wCg0vE4mujLYMHIb ptAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=TqrFJblKzyxIlzSAUCnT7nWxU2E+1fudDwfDt3CogfI=; b=3pNAyz1uyKHULD8Guobs4rEl4+osZ3i3EdkXqzvGlojIaCpiDlO/0D3urwkKPBFbXb SRj/aIYOpMhFZnEc0g9opTny4o9qUsfCplgYBrUpv6Ylh+z9gtQYvtkUtTBKJ1cCFo1e toabKUptTb0yknXdwwKOymizIXw6kbNP6k5IfoLR+EScTta8u5t6FEOQNA+q4WDqs6jQ 2EfctIETYE6BiLmD5LkZ2RrWTKLBO2o+lTijOG5iMOa3/SlLNDq8roxLm9LoFkQ8qS4f Bn+Ulwd8CDPhprKmsQyXw3+qN6I3RevQs/mF5QtXuyImve0iC8SgMgLAmxO3tLdYx3lg bHHg== X-Gm-Message-State: AOAM532IjdIpXVzT6aGEPOATitYhFTJ+rOJ1jQdb7Pr7vK6jVd4599jA Glqvz7mv3qY0+19NRDg7qS47EIa/asvpkJlQuh38HkpUGeE= X-Google-Smtp-Source: ABdhPJz1DBswRMRChtclOs7VJ4Cp9DR8pfwR8+e0O6aSk40azLiE/27YAFZy00h06oxf6isjwQUxrr0Vl+LePn4ILHo= X-Received: by 2002:adf:a1d0:: with SMTP id v16mr29835040wrv.622.1642622425490; Wed, 19 Jan 2022 12:00:25 -0800 (PST) MIME-Version: 1.0 References: <87bl07oev3.fsf@ucl.ac.uk> In-Reply-To: <87bl07oev3.fsf@ucl.ac.uk> From: Tom Gillespie Date: Wed, 19 Jan 2022 15:00:14 -0500 Message-ID: Subject: Re: call blocks as a function from inside elisp code To: Org Mode List Content-Type: text/plain; charset="UTF-8" X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::334 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=tgbugs@gmail.com; helo=mail-wm1-x334.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: George Mauer Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1642622517; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=TqrFJblKzyxIlzSAUCnT7nWxU2E+1fudDwfDt3CogfI=; b=tNXrf3La7sgXovbvIVf3HA7xjNo17lzpas7p9nPuIKux4XgfNZ5fV2LpYbil74Sej1ROX8 +E9/sw/ZnReyI1TH7ARL08XOfFrnaCrST/3uv0kLmPYH5EQDLQ29q5EokGJh4fk4/cmNby zTFx8QP1RMXhqbcNNoB5hfj2XjVhz0tpmO/fGTd+VE638+AXNa8kIBJ12r/Wu5J64KcQXK muSOUW4WROMNmaL/F2WQP4u+tFBE1TUgfUyQa19RsdMLLZgpHMgX4s0dsgAiFX17TluioT Jqzo+GQRZeuVuaXum0Nl24kCYmy/TkXoazoM/ohZhlzSEfgpXAFIin7NfsbjTA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1642622517; a=rsa-sha256; cv=none; b=Fx7jGOWNcdiIZRujvX1MdyoA8WPe2Mp6vIl9IWEbMgKQXj5lpot/hWEOpOUYAJrjdGyP/w zDKRPgvpgwidVc09ND1ph1MW3mUu8pGVu+oWHE3LqE+HpeulMCd38p1D6nBcbfT+W3tB1V Bs476sQiY0Dt6WkdRULDfVpGrjQB8oPI8TCdv9OwTE2EQywaza7dPLdK2ghzOedpbVD3pD hCpg4je0JKkCjhtk0gZ4FxLOUDvTzEvG+IXPNtbxfpO4GZpWhYAodGW0wp0HuuuyP0uIF2 40rr5c7a3DVwZNIsR6c8UJVVhNP7s9fjrCWn3DAa2udbJZB7xEvA6ZLsZhV+Eg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=PqM71Wd1; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -5.62 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=PqM71Wd1; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: AFF309FA2 X-Spam-Score: -5.62 X-Migadu-Scanner: scn0.migadu.com X-TUID: nVtLOfjZ0Dmg Hi George, Here is an example of how I call nested elisp and python. The python block is an input argument to the elisp block in this case, but the python block could be called directly as well. I'm not sure how to pass arguments to the block from inside elisp via org-babel-eval though, that seems like it would require some deeper tampering/advising of functions. Best, Tom https://github.com/SciCrunch/sparc-curation/blame/master/docs/queries.org#L1704-L1707 #+begin_src elisp :results none :exports none (ow-babel-eval "neru-simplified") #+end_src The implementation I use is included below and is source dfrom https://github.com/tgbugs/orgstrap/blob/bc981b957967be8d872c08be9ba7f2dbde5caf1d/ow.el#L786-L803 (defun ow-babel-eval (block-name &optional universal-argument) "Use to confirm running a chain of dependent blocks starting with BLOCK-NAME. This retains single confirmation at the entry point for the block." ;; TODO consider a header arg for a variant of this in org babel proper (interactive "P") (let ((org-confirm-babel-evaluate (lambda (_l _b) nil))) ;; FIXME TODO set messages buffer size to nil (save-excursion (when (org-babel-find-named-block block-name) ;; goto won't raise an error which results in the block where ;; `ow-confirm-once' is being used being called an infinite ;; number of times and blowing the stack (org-babel-goto-named-src-block block-name) (unwind-protect (progn ;; FIXME optionally raise errors on failure here !? (advice-add #'org-babel-insert-result :around #'ow--results-silent) (org-babel-execute-src-block)) (advice-remove #'org-babel-insert-result #'ow--results-silent)))))) (defun ow--results-silent (fun &rest args) "Whoever named the original version of this has a strange sense of humor." ;; so :results silent, which is what org babel calls between vars ;; set automatically is completely broken when one block calls another ;; there likely needs to be an internal gensymed value that babel blocks ;; can pass to eachother so that a malicious user cannot actually slience ;; values, along with an option to still print, but until then we have this (let ((result (car args)) (result-params (cadr args))) (if (member "silent" result-params) result (apply fun args))))