1 #+Title: a collection of examples for Babel tests
4 * =:noweb= header argument expansion
6 :ID: eb1f6498-5bd9-45e0-9c56-50717053e7b7
9 #+source: noweb-example
10 #+begin_src emacs-lisp
14 #+begin_src emacs-lisp :noweb yes
20 #+begin_src emacs-lisp :noweb no
26 #+begin_src emacs-lisp :noweb tangle
32 * elisp forms in header arguments
34 :ID: 22d67284-bf14-4cdc-8319-f4bd876829d7
38 #+begin_src emacs-lisp
45 * excessive id links on tangling
47 :ID: ef06fd7f-012b-4fde-87a2-2ae91504ea7e
50 ** no, don't give me an ID
51 #+begin_src emacs-lisp :tangle no
52 (message "not to be tangled")
55 ** yes, I'd love an ID
57 :ID: ae7b55ca-9ef2-4d30-bd48-da30e35fd0f3
59 #+begin_src emacs-lisp :tangle no
60 (message "for tangling")
62 * simple variable resolution
64 :ID: f68821bc-7f49-4389-85b5-914791ee3718
68 #+begin_src emacs-lisp
72 #+begin_src emacs-lisp :var four=four
79 * multi-line header arguments
81 :ID: b77c8857-6c76-4ea9-8a61-ddc2648d96c4
84 #+headers: :var letters='(a b c d e f g)
85 #+begin_src emacs-lisp :var numbers='(1 2 3 4 5 6 7)
86 (map 'list #'list numbers letters)
98 * simple named code block
100 :ID: 0d82b52d-1bb9-4916-816b-2c67c8108dbb
103 #+source: i-have-a-name
104 #+begin_src emacs-lisp
111 #+results: i-have-a-name
114 * Pascal's Triangle -- export test
116 :ID: 92518f2a-a46a-4205-a3ab-bcce1008a4bb
119 #+source: pascals-triangle
120 #+begin_src emacs-lisp :var n=5 :exports both
121 (defun pascals-triangle (n)
124 (let* ((prev-triangle (pascals-triangle (- n 1)))
125 (prev-row (car (reverse prev-triangle))))
126 (append prev-triangle
128 (append prev-row '(0))
129 (append '(0) prev-row)))))))
134 * calling code blocks from inside table
136 :ID: 6d2ff4ce-4489-4e2a-9c65-e3f71f77d975
140 #+begin_src emacs-lisp :var n=9
144 * executing an lob call line
147 :ID: fab7e291-fde6-45fc-bf6e-a485b8bca2f0
150 #+call: echo(input="testing")
151 #+call: echo(input="testing") :results vector
152 #+call: echo[:var input="testing"]()
153 #+call: echo[:var input="testing"]() :results vector
154 #+call: echo("testing")
155 #+call: echo("testing") :results vector
156 This is an inline call call_echo(input="testing") embedded in prose.
157 This is an inline call call_echo(input="testing")[:results vector] embedded in prose.
158 #+call: lob-minus(8, 4)
163 #+begin_src emacs-lisp :var a=0 :var b=0 :var c=0
164 (format "%S%S%S" a b c)
167 * exporting an lob call line
169 :ID: 72ddeed3-2d17-4c7f-8192-a575d535d3fc
173 #+begin_src emacs-lisp :var it=0
177 The following exports as a normal call line
180 Now here is an inline call call_double(it=1) stuck in the middle of
183 This one should not be exported =call_double(it=2)= because it is
186 Finally this next one should export, even though it starts a line
187 call_double(it=3) because sometimes inline blocks fold with a
190 And, a call with raw results call_double(4)[:results raw] should not
193 The following 2*5=call_double(5) should export even when prefixed by
196 * parsing header arguments
198 :ID: 7eb0dc6e-1c53-4275-88b3-b22f3113b9c3
201 #+begin_src example-lang :session :results output :var num=9
204 * conflicting blocks on export
206 :ID: 5daa4d03-e3ea-46b7-b093-62c1b7632df3
213 #+begin_src emacs-lisp :results wrap :exports both
216 #+begin_src emacs-lisp :var lst=a-list :results list
219 * using the =:noweb-ref= header argument
221 :ID: 54d68d4b-1544-4745-85ab-4f03b3cbd8a0
224 #+begin_src sh :tangle yes :noweb yes :shebang #!/bin/sh
228 ** query all mounted disks
229 #+begin_src sh :noweb-ref fullest-disk
233 ** strip the header row
234 #+begin_src sh :noweb-ref fullest-disk
238 ** sort by the percent full
239 #+begin_src sh :noweb-ref fullest-disk
240 |awk '{print $5 " " $6}'|sort -n |tail -1
243 ** extract the mount point
244 #+begin_src sh :noweb-ref fullest-disk
247 * resolving sub-trees as references
249 :ID: 2409e8ba-7b5f-4678-8888-e48aa02d8cb4
253 #+begin_src emacs-lisp :var text=d4faa7b3-072b-4dcf-813c-dd7141c633f3
257 #+begin_src org :noweb yes
259 <<d4faa7b3-072b-4dcf-813c-dd7141c633f3>>
262 ** simple subtree with custom ID
264 :CUSTOM_ID: simple-subtree
268 ** simple subtree with global ID
270 :ID: d4faa7b3-072b-4dcf-813c-dd7141c633f3