emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Babel: Store script in external file
@ 2019-12-16  1:21 Nathan Neff
  2019-12-16 10:09 ` Michael Welle
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Nathan Neff @ 2019-12-16  1:21 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 480 bytes --]

Hello all,

I think I'm missing something basic:  I'd like to have something like this:

#+begin_src python
#+filename: foo.py

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.

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.

Any ideas?  I feel like I'm missing something obvious.

Thanks,
--Nate

[-- Attachment #2: Type: text/html, Size: 704 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Babel: Store script in external file
  2019-12-16  1:21 Babel: Store script in external file Nathan Neff
@ 2019-12-16 10:09 ` Michael Welle
  2019-12-16 18:35 ` Berry, Charles
  2019-12-16 21:53 ` Michael Gauland
  2 siblings, 0 replies; 5+ messages in thread
From: Michael Welle @ 2019-12-16 10:09 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

Nathan Neff <nathan.neff@gmail.com> writes:

> Hello all,
>
> I think I'm missing something basic:  I'd like to have something like this:
>
> #+begin_src python
> #+filename: foo.py
>
> 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.
>
> 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.
>
> Any ideas?  I feel like I'm missing something obvious.
either put some Python code into your Python src block that executes
your external script. Or use a shell|elisp|whatever src block that
executes your script.

Regards
hmw

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Babel: Store script in external file
  2019-12-16  1:21 Babel: Store script in external file Nathan Neff
  2019-12-16 10:09 ` Michael Welle
@ 2019-12-16 18:35 ` Berry, Charles
  2019-12-16 21:53 ` Michael Gauland
  2 siblings, 0 replies; 5+ messages in thread
From: Berry, Charles @ 2019-12-16 18:35 UTC (permalink / raw)
  To: Nathan Neff; +Cc: emacs-orgmode



> On Dec 15, 2019, at 5:21 PM, Nathan Neff <nathan.neff@gmail.com> wrote:
> 
> Hello all,
> 
> I think I'm missing something basic:  I'd like to have something like this:
> 
> #+begin_src python
> #+filename: foo.py
> 
> 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.
> 
> 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.
> 
> 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 file

2. noweb chunks :: let you insert code into src blocks

See https://orgmode.org/worg/library-of-babel.html and (info "(org) Noweb Reference Syntax")

For your example, a file `my-lob.org' with a src-block named foo-py that contains what foo.py contains will do it.

Then you eval `(org-babel-lob-ingest "my-lob.org")' any time before executing the file that contains this:

#+begin_src python :noweb yes
<<foo-py>>
...

HTH,

Chuck

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Babel: Store script in external file
  2019-12-16  1:21 Babel: Store script in external file Nathan Neff
  2019-12-16 10:09 ` Michael Welle
  2019-12-16 18:35 ` Berry, Charles
@ 2019-12-16 21:53 ` Michael Gauland
  2019-12-17 18:08   ` Berry, Charles
  2 siblings, 1 reply; 5+ messages in thread
From: Michael Gauland @ 2019-12-16 21:53 UTC (permalink / raw)
  To: Nathan Neff; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 995 bytes --]

I've just started playing with #+INCLUDE, so I may not be using it
correctly, but this works for me.

I have a file 'sh_test', which looks like:
for i in $(seq 10); do
    echo $i
done

My org file:
#+HEADER: :exports both
#+INCLUDE: "sh_test" src sh

And the results:

,----
| for i in $(seq 10); do
|     echo $i
| done
`----

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10

Hope that helps.

Kind regards,
Mike


On Mon, Dec 16, 2019 at 2:22 PM Nathan Neff <nathan.neff@gmail.com> wrote:

> Hello all,
>
> I think I'm missing something basic:  I'd like to have something like this:
>
> #+begin_src python
> #+filename: foo.py
>
> 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.
>
> 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.
>
> Any ideas?  I feel like I'm missing something obvious.
>
> Thanks,
> --Nate
>

[-- Attachment #2: Type: text/html, Size: 2798 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Babel: Store script in external file
  2019-12-16 21:53 ` Michael Gauland
@ 2019-12-17 18:08   ` Berry, Charles
  0 siblings, 0 replies; 5+ messages in thread
From: Berry, Charles @ 2019-12-17 18:08 UTC (permalink / raw)
  To: Michael Gauland; +Cc: emacs-orgmode



> On Dec 16, 2019, at 1:53 PM, Michael Gauland <mikelygee@gmail.com> wrote:
> 
> I've just started playing with #+INCLUDE, so I may not be using it correctly, but this works for me.

Indeed, if what the OP wants is to wrap just that code as a src block and export it and any results it produces during export then that is the way to go. 

However, `org-babel-execute-buffer' , `org-babel-tangle' and so on will not honor the #+INCLUDE directive unless an export is in progress.

HTH,

Chuck

> 
> I have a file 'sh_test', which looks like:
> for i in $(seq 10); do
>     echo $i
> done
> 
> My org file:
> #+HEADER: :exports both
> #+INCLUDE: "sh_test" src sh
> 
> And the results:
> 
> ,----
> | for i in $(seq 10); do
> |     echo $i
> | done
> `----
> 
>   1
>   2
>   3
>   4
>   5
>   6
>   7
>   8
>   9
>  10
> 
> Hope that helps.
> 
> Kind regards,
> Mike
> 
> 
> On Mon, Dec 16, 2019 at 2:22 PM Nathan Neff <nathan.neff@gmail.com> wrote:
> Hello all,
> 
> I think I'm missing something basic:  I'd like to have something like this:
> 
> #+begin_src python
> #+filename: foo.py
> 
> 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.
> 
> 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.
> 
> Any ideas?  I feel like I'm missing something obvious.
> 
> Thanks,
> --Nate

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-12-17 18:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-12-16  1:21 Babel: Store script in external file Nathan Neff
2019-12-16 10:09 ` Michael Welle
2019-12-16 18:35 ` Berry, Charles
2019-12-16 21:53 ` Michael Gauland
2019-12-17 18:08   ` Berry, Charles

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).