Literate Programming using org-babel
Asked Answered
G

1

16

I am on a literate program using org-babel. My source is structured like so,

-imports
-utility fns
-game structure
 - detailed explanations

This is the normal structure of the code, what I would like to do is move explanations of the utility fns to the end so it does not show up first in the generated pdf file. Now this can be done with noweb extension, but the problem is when you have lots of little functions for each one I have to add a src_block with a unique name scroll down the file and add a reference to that in the file which is really annoying. Is there a way to name all the src_blocks in a section? say all code in this section goes into block A.

Gerta answered 14/7, 2011 at 14:18 Comment(0)
R
11

You can give multiple chunks the same name. For example, I generate my .emacs file with org-tangle, and at the top of the org file, I have a master template that looks something like this:

#+begin_src emacs-lisp :tangle "/path/to/.emacs" :comments both :noweb tangle
<<generated-file-warning>
<<includes>>
<<definitions>>
<<settings>>
<<generated-file-warning>
#+end_src

Underneath that, I have my outline with source blocks like so:

* extensions
** yasnippet

#+name: early-includes
#+begin_src emacs-lisp
(require 'yasnippet)
(yas/initialize)
#+end_src

#+name: settings
#+begin_src emacs-lisp
(yas/load/directory "/path/to/my/snippets")
#+end_src

Note: for older versions of org-mode, you may need to use #+srcname: instead of #+name:

You can also create a property called noweb-ref, which applies the same name to all source blocks in a sub-tree.

Runthrough answered 15/12, 2011 at 8:31 Comment(3)
Org manual says: "Names are assumed to be unique and the behavior of Org mode when two or more blocks share the same name is undefined."Salado
Yep. Nonetheless, org-babel-tangle behaves as described.Runthrough
From my limited experiment, it seems code blocks with the same name will be concatenated in the order of their appearance in the literate program file, This may be the behavior that @Hamza needsFanchette

© 2022 - 2024 — McMap. All rights reserved.