0

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.

Refael Sheinker
  • 713
  • 7
  • 20

1 Answers1

2

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.

éric
  • 146
  • 1
  • Great idea. Thank you very much :-) Had to google what `noweb` is, I was not aware of it. I use the `nvim-orgmode` plugin, and it does not seem it supports `noweb` syntax. I've asked them and now waiting for a replay. More ideas? – Refael Sheinker Jul 26 '22 at 19:32