From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id yD5nLX5RUmSnmQAASxT56A (envelope-from ) for ; Wed, 03 May 2023 14:20:14 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id 4A+JLH5RUmQDbwEAG6o9tA (envelope-from ) for ; Wed, 03 May 2023 14:20:14 +0200 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 36BD88A1E for ; Wed, 3 May 2023 14:20:14 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1puBSL-0007us-Ob; Wed, 03 May 2023 08:19:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIbc-0001yu-Dg for emacs-orgmode@gnu.org; Tue, 25 Apr 2023 09:21:17 -0400 Received: from forward1.bravehost.com ([65.39.211.71]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIbZ-00087h-Kd for emacs-orgmode@gnu.org; Tue, 25 Apr 2023 09:21:15 -0400 X-Virus-Scanned: amavisd-new at mboxlogin.com DKIM-Filter: OpenDKIM Filter v2.11.0 forward1.bravehost.com 82482202AD From: Samuel Culpepper To: emacs-orgmode@gnu.org Subject: org-babel-expand-call-block Date: Tue, 25 Apr 2023 15:20:51 +0200 Message-ID: <87leigm72k.fsf@samuelculpepper.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" Received-SPF: pass client-ip=65.39.211.71; envelope-from=samuel@samuelculpepper.com; helo=forward1.bravehost.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Wed, 03 May 2023 08:19:35 -0400 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: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Seal: i=1; s=key1; d=yhetil.org; t=1683116414; a=rsa-sha256; cv=none; b=oayGIvrKEW8RkXGRXdYDVXPzJBaFHFiAwrQLa/b4LCGFVWeLf8Xq/Dt6dI2CmhQ0e5qn9d Qt4IolDV03v5lk8D4n+ke23b7VkvOvn4ZYzY4piEYeHF/Vi8F8yFd6+f1V5uo9Z7bH0LVh 3dXd9vY2m9DsMXtpBBORluVvssetV+6xNkvFxqIkb7qdkxToRYyRYX1QemGfcvjVl+ahtI baWfwmYbcrDJm1Tx3zXA5L13+VgJoWZ9CCUY8fKbloMRN46ftFXJhYPW0n0eLItZAi5gHR uOq4nsDarBvttP2XVPitA77figDuz9ySl9s7DmHkQbEnUitzkqUMhLtp65yZ4w== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; 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" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1683116414; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=tuZFTDy8+F+wE3HsoWugELUIzU/cesfrH1Xl35XlVQU=; b=CWp0kdLR7AVvrJVYCjMnQRr4X/NVlNG6KiN1Hz9mj0b9MZGA3+eBMICG9dQwocfP0hFiaJ V7roEQlw883SA+8qJ6UfHPNpD66Bsn6Mw/e0SErsTTbMjboYBxJhEmJXRawijxNRlY+HL8 Q5kOvP0FkpoOVFRdPYJXQ6nlbpcFnT8E53xaFO2lFaY7Veezeb0Ef6W4NLbt22qMS0G9qi WPVzK04l8Jc2Kz8i3DeE72Y9iW1LU/s8+F1K5mIxLlRmKyzxWbb4+Bi5JHnAnku67RLEZT O5GIgrf3yucyj68PuO8IdqWkOweULVNn0F7GF2uXZrSTgG1A90W4PS1iV/Rw1w== X-Migadu-Spam-Score: -2.11 X-Spam-Score: -2.11 X-Migadu-Queue-Id: 36BD88A1E X-Migadu-Scanner: scn0.migadu.com Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; 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-TUID: /AkC9BfFPMgP --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Hi orgmode, I thought it would be nice share a little excursion into babel's code expansion; nothing groundbreaking, and nobody asked, but it may address a more comprehensive tangling, or maybe just some ergonomics for copying code. #+name: babel-lob-info #+begin_src emacs-lisp :var ya=3D"dooby" (when-let* ((context (org-element-lineage (org-element-context) ;; limit to call, src '(inline-babel-call babel-call inline-src-block src-block) t))) (cl-case (org-element-type context) ((or babel-call inline-babel-call) (let ((info (org-babel-lob-get-info context))) ;; this setf is to convert the the 'call args to 'src args. ;; ;; call :: (:var . "ya=3D\"dooby\"") ;; src :: (:var ya . "dooby") ;; ;; in org proper 'org-babel-execute-src-block, this parameter ;; normalization also happens before the 'expand call (let ((old-info (copy-tree info))) (setf (nth 2 info) (org-babel-process-params (nth 2 info))) ;; META if you're copying this to use, just return the car, ;; as :info-src, :info-call are just here for the demo ;; (list (org-babel-expand-src-block nil info) :info-src info :info-call old-info)))) (t ;; META as above (list (org-babel-expand-src-block))))) #+end_src You may try this out by calling the below, with the point on the line: #+call: babel-lob-info(ya=3D"scoooby") :results code I use this primarily to template things -- mostly very repetitive SQL, for data analysis -- over arbitrarily deep nowebs and call blocks, but have always struggled to share the resulting artifact with non-emacs users, or tangle such noweb-call-dynamic-variable monstrosities. I will at some point (TM) look into the tangling story, so would welcome any suggestions, but the former -- sharing -- is made rather pleasant, interactively: #+begin_src emacs-lisp :noweb yes (defun my/org-kill-expanded-block () (interactive) (kill-new (car <> ))) ;; META test it! {C-c C-v M-w} (define-key org-babel-map (kbd "M-w") 'my/org-kill-expanded-block) #+end_src #+RESULTS: : my/org-kill-expanded-block LOB has been a staple tool for me, if you feel enthused, do read more of these exploits in my literate config :: https://github.com/qzdl/rde/blob= /ixy/master/examples/src/qzdl/configs.org#library-of-babel =2D-=20 Yours, Samuel Culpepper --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEETrB91awggJ73S4He7iDiU5GqubsFAmRH07MACgkQ7iDiU5Gq ubuENg/+JiyKyQz7ik+xLi4DxSj6OIHjseBcZ4R+Van6/7FCmIJUcraQcRBIUdPv WsSR4lXp7J1QdsqNhj3PqO60fx6BU9VAYzmvEuYTdMiRK9+rX13SPYl7z1/zVQzi ENGM2h7gtbNPkGLtsWxQVCBBweMkotc9HrdeblFmOnrUAGma2lnE4ygXKtkOiy43 iAQXm2OJy3ZU6cTm9Qii8I1jq6UBtlDLHZdDR22B1HTgS/Xv46rtmGj2BCIfrWlb 4bsTK2xuUzr2uD1YZfxL24KWbn8Amw273nuvX0V5wkfsD343dZkfXh9RFRaXYYCg OrK/z5gA7JMtQRqxzA3TIYIV0GbiE8iiG+5jSuaFMwj3HZD2yEPL38FjgHGBoUnt JNXVXf8HfHrIF6kkUY4cGUwk0gDXe0wSHuhGg8zUWvmGi4LlwDeaWBixbdwWH11C OPd2wMsKyZ32UOz7dqwDZInHy9g7rGx5exDzy/CT4BlwKwTttLvb6eti7kElidYt yxDEbbCm8KWJc4LTZZTkzGLmI4aeiB+apRfe31CtuK2O+ZAsN6fo1cEey9b8RGCT NkWGk0cAe6Hs4njMu6fdNwV4XNZEa50v2FQU+kHaCGF7UQHuZw0zsY0fc2E4smfB uTerlI27aeoEN94mxUuFtG2v+9uf35l2rNrUVHD1v8TFp/QUfeM= =O+BC -----END PGP SIGNATURE----- --=-=-=--