Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Literate Programming using org-babel

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.

like image 494
Hamza Yerlikaya Avatar asked Jul 14 '11 14:07

Hamza Yerlikaya


1 Answers

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.

like image 145
tangentstorm Avatar answered Sep 22 '22 01:09

tangentstorm