From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Berry, Charles" Subject: Re: Babel: Store script in external file Date: Mon, 16 Dec 2019 18:35:00 +0000 Message-ID: <623D2117-E7A0-4372-85E0-CC5D5244E50E@ucsd.edu> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:53202) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1igvDV-00069B-6p for emacs-orgmode@gnu.org; Mon, 16 Dec 2019 13:35:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1igvDS-0002VY-Mi for emacs-orgmode@gnu.org; Mon, 16 Dec 2019 13:35:36 -0500 Received: from mx0a-00395d01.pphosted.com ([148.163.133.170]:9412) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1igvDS-0002Tq-2Y for emacs-orgmode@gnu.org; Mon, 16 Dec 2019 13:35:34 -0500 In-Reply-To: Content-Language: en-US Content-ID: <69FE68D90F34A44D9D72CE8D52D28CFB@AD.UCSD.EDU> 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" To: Nathan Neff Cc: emacs-orgmode > On Dec 15, 2019, at 5:21 PM, Nathan Neff wrote: >=20 > Hello all, >=20 > I think I'm missing something basic: I'd like to have something like thi= s: >=20 > #+begin_src python > #+filename: foo.py >=20 > Instead of storing my Python code in the current org file, I would like > Babel to read foo.py and execute it, as if it was inside the .org file. >=20 > The foo.py mentioned above is fairly large, and I would like the code > to be stored in a different file than my .org file, for brevity. >=20 > Any ideas? I feel like I'm missing something obvious. Two things: 1. Library-of-Babel :: lets you store src blocks of code in an external fil= e 2. noweb chunks :: let you insert code into src blocks See https://orgmode.org/worg/library-of-babel.html and (info "(org) Noweb R= eference Syntax") For your example, a file `my-lob.org' with a src-block named foo-py that co= ntains what foo.py contains will do it. Then you eval `(org-babel-lob-ingest "my-lob.org")' any time before executi= ng the file that contains this: #+begin_src python :noweb yes <> ... HTH, Chuck