From: Arthur Miller <arthur.miller@live.com>
To: Bob Heffernan <bob.heffernan@gmail.com>
Cc: Emacs mailing list <help-gnu-emacs@gnu.org>
Subject: Re: Org mode & "literate programming": including files
Date: Wed, 07 Apr 2021 05:54:48 +0200 [thread overview]
Message-ID: <AM9PR09MB4977C896AB5FF031E90CECAE96759@AM9PR09MB4977.eurprd09.prod.outlook.com> (raw)
In-Reply-To: <20210406183852.67ucwze6yxugvgrl@bob-nuc> (Bob Heffernan's message of "Tue, 6 Apr 2021 19:38:52 +0100")
Bob Heffernan <bob.heffernan@gmail.com> writes:
> Dear all,
>
> I am new to Emacs (as a long-time vim user) so apologies if this
> question has an easy answer, but I've done a bit of searching before
> asking.
>
> I am looking at using org-mode for (a fairly simplistic version of)
> literate programming. The programming language I'm using is Scheme,
> although this probably doesn't matter. I've set things up so that
> code blocks share a session:
>
> #+PROPERTY: header-args :session *scheme*
>
> and I can then have several code blocks that work nicely together
> (these would usually be sprinkled throughout the document, of course,
> with text in between):
>
> #+begin_src scheme :results silent (define (f n) (+ n 1)) #+end_src
> #+begin_src scheme
> (f 1)
> #+end_src
>
> If I run the code in each block in turn with C-c C-c, which I guess
> calls org-babel-execute-src-block, I get
>
> #+RESULTS:
> : 2
>
> So far so good and this is perfect for simple programs.
>
> However, once things get more complicated I will want to include
> another such org file, as a library as it were. For example, I'd like
> to be able to write a second org file that includes the stuff above
> and now knows what the definition of the procedure f is. I know that
> there is #+INCLUDE but I guess what I really need is to include a file
> and, at the same time, execute all src blocks in that file so that
> they are present in the same session as that of my current file.
>
> To give an example, let's say I'm working on writing solutions to
> Project Euler problems. After a while, I'll want a little library of
> procedures relating to prime numbers (since these come up a lot) which
> I can include as needed. It would be nice for this to also be written
> up nicely in org mode.
>
> I asked this question on the emacs subreddit and the library of babel
> was mentioned. This would work, I guess, but isn't quite what I'm
> looking for. Somebody else mentioned "transclusion" which seems
> perhaps more powerful than what I'm looking for. It seems like this
> should be a common problem to solve, but Google hasn't found anything
> for me.
I saw your question on reddit, and I saw somebody already posted you an
answer. You are looking for `org-babel-lob-ingest`.
Check the SX link posted to you on Reddit, it has what you are asking for:
https://emacs.stackexchange.com/questions/31999/config-examples-and-use-cases-of-library-of-babel
Hope it works for you and don't forgett to say thanks to the guy on Reddit.
next prev parent reply other threads:[~2021-04-07 3:54 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-06 18:38 Org mode & "literate programming": including files Bob Heffernan
2021-04-06 20:18 ` Nikolay Kudryavtsev
2021-04-06 21:59 ` Bob Heffernan
2021-04-07 3:54 ` Arthur Miller [this message]
2021-04-07 8:28 ` Bob Heffernan
2021-04-07 16:47 ` Arthur Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AM9PR09MB4977C896AB5FF031E90CECAE96759@AM9PR09MB4977.eurprd09.prod.outlook.com \
--to=arthur.miller@live.com \
--cc=bob.heffernan@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).