Refael Sheinker
Refael Sheinker

Reputation: 911

Literate programming, org mode, function declaration

I want to write a Literate Program with org-mode. Let's say I have the following function:

fn do_stuff()
{
    // 200 lines of code go here.
}

I would write something like that in org-mode:

#+BEGIN_SRC rust :tangle /some/path
fn do_stuff()
{
#+END_SRC

// Many more blocks of `BEGIN_SRC` go here to exlpain 200 lines of code mentioned above.
// They will have formatting, and prose between them, and headings with different nesting levels.
// The whole shebang in short.

#+BEGIN_SRC rust :tangle /some/path
}
#+END_SRC

Now, here is the question. I hope I will explain it well, it's kinda hard to put in words. What do I do with the first and last #+BEGIN_SRC blocks shown above? How do I style the function declaration with org-mode and/or Literate Programming? It seems kind of out of place with all the “formatting, prose, headings” of the 200 lines of code mentioned above.

I need ideas please :-)

Thanks in advance.

Upvotes: 0

Views: 237

Answers (1)

éric
éric

Reputation: 156

I would use noweb to tangle the full code without necessarily presenting it all in order. That is, I would do something like this:

The core code is

#+name: code1
#+begin_src rust :noweb yes :tangle no
...
#+end_src

More code etc. and then, at the end:

#+BEGIN_SRC rust :tangle /some/path
fn do_stuff()
{
<<code1>>
}
#+END_SRC

You may need :noweb yes on the full code block as well.

Upvotes: 2

Related Questions