12 KiB
a collection of examples for Babel tests
:noweb
header argument expansion:noweb
header argument expansion using :exports results- excessive id links on tangling
- simple named code block
- Pascal's Triangle – exports both test
- executing an lob call line
- exporting an lob call line
- inline source block
- exported inline source block
- mixed blocks with exports both
- using the
:noweb-ref
header argument - resolving sub-trees as references
- exporting a code block with a name
- noweb no-export and exports both
- in order evaluation on export
- exporting more than just results from a call line
- strip noweb references on export
- use case of reading entry properties
:file-ext
and:output-dir
header args- detangle
:noweb
header argument expansion
(message "expanded1")
(message "expanded2")
;; noweb-1-yes-start
<<noweb-example>>
;; noweb-no-start
<<noweb-example1>>
;; noweb-2-yes-start
<<noweb-example2>>
;; noweb-tangle-start
<<noweb-example1>>
<<noweb-example2>>
:noweb
header argument expansion using :exports results
;; noweb-no-start
<<noweb-example1>>
<<noweb-example1>>
<<noweb-example2>>
excessive id links on tangling
no, don't give me an ID
(message "not to be tangled")
yes, I'd love an ID
(message "for tangling")
simple named code block
42
42
42
Pascal's Triangle – exports both test
(defun pascals-triangle (n)
(if (= n 0)
(list (list 1))
(let* ((prev-triangle (pascals-triangle (- n 1)))
(prev-row (car (reverse prev-triangle))))
(append prev-triangle
(list (cl-map 'list #'+
(append prev-row '(0))
(append '(0) prev-row)))))))
(pascals-triangle n)
executing an lob call line
This is an inline call call_echo(input="testing") embedded in prose. This is an inline call call_echo(input="testing")[:results vector] embedded in prose.
call_echo("testing") call_concat(1,2,3)
(format "%S%S%S" a b c)
exporting an lob call line
(* 2 it)
The following exports as a normal call line
Now here is an inline call call_double(it=1) stuck in the middle of some prose.
This one should not be exported call_double(it=2)
because it is
quoted.
Finally this next one should export, even though it starts a line call_double(it=3) because sometimes inline blocks fold with a paragraph.
And, a call with raw results call_double(4)[:results raw] should not have quoted results.
The following 2*5=call_double(5) should export even when prefixed by an = sign.
inline source block
Here is one in the middle
echo 1
echo 2
echo 3
exported inline source block
Here is one in the middle
echo 1
echo 2
echo 3
echo 4
mixed blocks with exports both
- a
- b
- c
"code block results"
(reverse lst)
using the :noweb-ref
header argument
<<fullest-disk>>
query all mounted disks
df
strip the header row
|sed '1d'
sort by the percent full
|awk '{print $5 " " $6}'|sort -n |tail -1
extract the mount point
|awk '{print $2}'
resolving sub-trees as references
(length text)
<<simple-subtree>>
<<d4faa7b3-072b-4dcf-813c-dd7141c633f3>>
simple subtree with custom ID
this is simple
simple subtree with global ID
has length 14
exporting a code block with a name
exporting a code block with a name
echo bar
noweb no-export and exports both
Weird interaction.
here is one block
and another
# I am inside the code block
<<noweb-no-export-and-exports-both-1>>
in order evaluation on export
First.
(push it *evaluation-collector*)
Second
(push 2 *evaluation-collector*)
Third src_emacs-lisp{(car (push 3 evaluation-collector))}
Fourth
Fifth
(push 5 *evaluation-collector*)
exporting more than just results from a call line
Here is a call line with more than just the results exported.
strip noweb references on export
<<strip-export-1>>
echo "1$i"
use case of reading entry properties
Use case checked and documented with this test: During their evaluation the source blocks read values from properties from the entry where the call has been made unless the value is overridden with the optional argument of the caller.
section
Note: Just export of a property can be done with a macro: .
- sect inline call_src_block_location_shell()[:results raw]
- sect inline call_src_block_location_elisp()[:results raw]
subsection
- sub0 inline call_src_block_location_shell()[:results raw]
- sub0 inline call_src_block_location_elisp()[:results raw]
- sub1 inline call_src_block_location_shell(c=5, e=6)[:results raw]
- sub1 inline call_src_block_location_elisp(c=5, e=6)[:results raw]
function definition
comments for ":var":
- The "or" is to deal with a property not present.
- The t is to get property inheritance.
:file-ext
and :output-dir
header args
nil
nil
nil
nil
nil
nil
detangle
false positive
The [[
causes a false positive which org-babel-detangle
should handle properly
(string-match-p "^#[[:digit:]]+$" "#123")
linked content to detangle
;; detangle