From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 4OSTGtjfJWCGQwAA0tVLHw (envelope-from ) for ; Fri, 12 Feb 2021 01:54:32 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id 6I81FtjfJWCvPAAAbx9fmQ (envelope-from ) for ; Fri, 12 Feb 2021 01:54:32 +0000 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 D0423940276 for ; Fri, 12 Feb 2021 01:54:31 +0000 (UTC) Received: from localhost ([::1]:58252 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lANfB-0000my-B4 for larch@yhetil.org; Thu, 11 Feb 2021 20:54:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43832) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lANeP-0000lU-AI for emacs-orgmode@gnu.org; Thu, 11 Feb 2021 20:53:42 -0500 Received: from mail-qt1-x830.google.com ([2607:f8b0:4864:20::830]:46470) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lANeK-0006KX-Tz for emacs-orgmode@gnu.org; Thu, 11 Feb 2021 20:53:40 -0500 Received: by mail-qt1-x830.google.com with SMTP id b24so5696617qtp.13 for ; Thu, 11 Feb 2021 17:53:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=user-agent:from:to:subject:message-id:date:mime-version; bh=F2bF3XB2u6CfPAoKjlELpbkxTgADVST8TT7eXScx148=; b=NmJGeibaX3k2pKWLQtsgNFiaqzG/9uC5c2CuO4fO40TwvXrNbUBeCgD129l3eyVBuS RIOUtaZKWrw6Z4Fa/UfFVkM4cylXBkOgWQX0axv/f5SrnDWkoub7KX6sKPzGwtXsktzQ Av6l5hesUVIBcuhigBicT8xKJSH6kXZwt7ZPf7Bxl5FVvFhN7ojgxXxDkYrQOkutSQLG sgOG2y1upEUEOiiN1fdRk6/A/NE25Hh1bmabwonKrw3G1PndSED0uPDy9dMdwVTbEnRW lNKG8bB80xaOaie+9tjC10DDGKxy9drFnIb7HIxf8OXwMUYMp3U5JJjoZIS63XrzuBwn e8GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:user-agent:from:to:subject:message-id:date :mime-version; bh=F2bF3XB2u6CfPAoKjlELpbkxTgADVST8TT7eXScx148=; b=XpqaMvkVotr/VeYDLePrS4hCV9S4sjeRi1haMcKDar3Gy3yHD0nlHv4mQ9konMnVRm 95PJXsV38ADEwB78CEwJa3+2g/XvDkTjHWoRIryp1iWzbbwFOVlcSl2kN76h9fS0NU+N +Kg36iEVcLX2SzijSx0qV4co4i6Zia9bdCJAkEVwbzv1Cfmb4t7ya4d47ZOOUgUnzGeG kuNFqTCuHP1mpxeBw4sbf524/fK8r1Zmb4jJ+6GqurUcvG65VYgAIJQrAcOXv3l9jGXB TYVGS/4IcPXzMbw8f+dypyPfWNa02Wg62MvINmJMBbfKtdSyuOfxQ60KCYGcYuLscblN gJsw== X-Gm-Message-State: AOAM531uLWSTeHgjmbJ3XyYe6k3rtqLicY/NpQmDoQdNkdGsBSFdNIRq ZXdF7BpbeSELcVsU5Jh+UCxVGShEO5o= X-Google-Smtp-Source: ABdhPJz0yhbQVWjIg1fPab49nnHDLQFa9ZmwkQQKK2DYpG6LFZAqlvlLabsSCnwGT0fgNiopyMNgkg== X-Received: by 2002:aed:34c5:: with SMTP id x63mr559499qtd.349.1613094814970; Thu, 11 Feb 2021 17:53:34 -0800 (PST) Received: from localhost ([190.239.232.181]) by smtp.gmail.com with ESMTPSA id 196sm5157326qkn.64.2021.02.11.17.53.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Feb 2021 17:53:34 -0800 (PST) User-agent: mu4e 1.4.14; emacs 27.1 From: Rodrigo Morales To: emacs-orgmode@gnu.org Subject: How to call a code block by its name in the :prologue header argument? Message-ID: <87ft22hx6d.fsf@gmail.com> Date: Thu, 11 Feb 2021 20:50:02 -0500 MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::830; envelope-from=moralesrodrigo1100@gmail.com; helo=mail-qt1-x830.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 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" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -2.06 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=NmJGeiba; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: D0423940276 X-Spam-Score: -2.06 X-Migadu-Scanner: scn1.migadu.com X-TUID: 2mRn4m2HT1vb * The problem Let's suppose we have this simple code block #+NAME: my-named-code-block #+begin_src bash echo foo-1 echo foo-2 #+end_src which contain some commands that we want to execute before the commands that are presented below. Therefore, we use the =:prologue= header argument #+begin_src bash :noweb yes :prologue "<>" echo a #+end_src However, when evaluating the code block, the buffer =*Org-Babel Error Output*= is opened with the following content. Apparently, this happens because the noweb reference added in the prologue is not expanded. Therefore, =bash= executes =<>= which results in the error shown below. #+begin_example bash: line 2: warning: here-document at line 1 delimited by end-of-file (wanted `my-named-code-block') bash: line 2: syntax error near unexpected token `newline' bash: line 2: `<>' #+end_example * The question How can I add the content of a code block as the =:prologue= of another code block? * Additional information I don't want to add =<>= inside the code block (see below for example) since that would imply that the content of the code block is explicitly changed. Note that this doesn't happen when using =:prologue= because it can be set through different ways that don't imply changing the content of the code block where the commands are intended to be executed. #+begin_src bash <> echo a #+end_src * A possible solution I was thinking in the following solution: Find/Create a function which gets the content of a code block as an string given its name so that it could be called as it follows #+begin_src bash :prologue (get-code-block-as-string "my-named-code-block") echo a #+end_src Recall that this would work because =:prologue= accept strings (see below). #+begin_src bash :prologue "echo foo\necho bar" echo a #+end_src #+RESULTS: #+begin_example foo bar a #+end_example * Relevant information Found the following relevant sources of information [1] A user had asked this in a question in Stack Overflow but he didn't get any significant response. [2] Some user created a thread in the emacs-orgmode mailing list asking why noweb expansion occurs before prologue expansion and presents an example similar to mine. The thread didn't get any response. [3, 4] In a thread in the emacs-orgmode mailing list, this was asked before but the only solution provided was to insert a noweb reference inside the code block. [1] https://stackoverflow.com/questions/50555643/how-to-add-one-code-block-as-prologue-to-another-code-block-for-noweb-style-exp [2] https://lists.gnu.org/archive/html/emacs-orgmode/2019-08/msg00244.html [3] https://lists.gnu.org/archive/html/emacs-orgmode/2020-08/msg00116.html [4] https://lists.gnu.org/archive/html/emacs-orgmode/2020-08/msg00118.html -- Greetings, Rodrigo Morales. IRC: rdrg109 (freenode)