If you want to use the literate programming features in emacs org-mode, you can try this minimal example to get started: Activate org-babel-tangle, then put this into the file noweb-test.org:
Minimal example for noweb in org-mode
* Assign
First we assign abc:
#+begin_src python :noweb-ref assign_abc
abc = "abc"
#+end_src
* Use
Then we use it in a function:
#+begin_src python :noweb tangle :tangle noweb-test.py
def x():
<<assign_abc>>
return abc
print(x())
#+end_src
Hit C-c C-c to evaluate the source block. Hit C-c C-v C-t to put the expanded code into the file noweb-test.py.
The exported code looks like this:
def x(): abc = "abc" return abcnoweb-test.py
print(x())
(html generated with org-export-as-html-to-buffer and slightly reniced to escape the additional parsing I have on my site)
And with org-export-as-pdf we get this:
Add :results output to the #+begin_src line of the second block to see the print results under that block when you hit C-c C-c in the block.
You can also use properties of headlines for giving the noweb-ref. Org-mode can then even concatenate several source blocks into one noweb reference. Just hit C-c C-x p to set a property (or use M-x org-set-property), then set noweb-ref to the name you want to use to embed all blocks under this heading together.
Note: org-babel prefixes each line of an included code-block with the prefix used for the reference (here <<assign_abc>>). This way you can easily include blocks inside python functions.
Have fun with Emacs and org-mode!
| Anhang | Größe |
|---|---|
| noweb-test.pdf | 81.69 KB |
| noweb-test.org | 290 Bytes |
| noweb-test.py.txt | 49 Bytes |
| noweb-test-pdf.png | 6.05 KB |
Diese Seite nutzt Drupal.
Design: Arne Babenhauserheide.
Werke von Arne Babenhauserheide.
Lizensiert unter freien Lizenzen.
![]()