1 #+Title: a collection of examples for Babel tests
4 * =:noweb= header argument expansion
6 :ID: eb1f6498-5bd9-45e0-9c56-50717053e7b7
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 #+name: i-have-a-name
104 #+begin_src emacs-lisp
111 #+name: i-have-a-name
114 * Pascal's Triangle -- export test
116 :ID: 92518f2a-a46a-4205-a3ab-bcce1008a4bb
119 #+name: 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 * inline source block
199 :ID: 54cb8dc3-298c-4883-a933-029b3c9d4b18
201 Here is one in the middle src_sh{echo 1} of a line.
202 Here is one at the end of a line. src_sh{echo 2}
203 src_sh{echo 3} Here is one at the beginning of a line.
205 * parsing header arguments
207 :ID: 7eb0dc6e-1c53-4275-88b3-b22f3113b9c3
210 #+begin_src example-lang :session :results output :var num=9
213 * conflicting blocks on export
215 :ID: 5daa4d03-e3ea-46b7-b093-62c1b7632df3
222 #+begin_src emacs-lisp :results wrap :exports both
225 #+begin_src emacs-lisp :var lst=a-list :results list
228 * using the =:noweb-ref= header argument
230 :ID: 54d68d4b-1544-4745-85ab-4f03b3cbd8a0
234 #+begin_src sh :tangle yes :noweb yes :shebang #!/bin/sh
238 ** query all mounted disks
239 #+begin_src sh :noweb-ref fullest-disk
243 ** strip the header row
244 #+begin_src sh :noweb-ref fullest-disk
248 ** sort by the percent full
249 #+begin_src sh :noweb-ref fullest-disk
250 |awk '{print $5 " " $6}'|sort -n |tail -1
253 ** extract the mount point
254 #+begin_src sh :noweb-ref fullest-disk
257 * resolving sub-trees as references
259 :ID: 2409e8ba-7b5f-4678-8888-e48aa02d8cb4
263 #+begin_src emacs-lisp :var text=d4faa7b3-072b-4dcf-813c-dd7141c633f3
267 #+begin_src org :noweb yes
269 <<d4faa7b3-072b-4dcf-813c-dd7141c633f3>>
272 ** simple subtree with custom ID
274 :CUSTOM_ID: simple-subtree
278 ** simple subtree with global ID
280 :ID: d4faa7b3-072b-4dcf-813c-dd7141c633f3
284 * org-babel-get-inline-src-block-matches
287 :ID: 0D0983D4-DE33-400A-8A05-A225A567BC74
289 src_sh{echo "One"} block at start of line
290 One spaced block in src_sh{ echo "middle" } of line
291 src_sh{echo 2} blocks on the src_emacs-lisp{"same"} line
292 Inline block with src_sh[:results silent]{ echo "parameters" }.
293 * returning file names -- interpreted as lists
295 :ID: a73a2ab6-b8b2-4c0e-ae7f-23ad14eab7bc
298 #+begin_src sh :results scalar
299 echo "[[file:./cv.cls]]"
305 #+begin_src sh :results raw scalar
306 echo "[[file:./cv.cls]]"
312 * in order evaluation on export
315 :ID: 96cc7073-97ec-4556-87cf-1f9bffafd317
319 #+name: foo-for-order-of-evaluation
320 #+begin_src emacs-lisp :var it=1
321 (push it *evaluation-collector*)
325 #+begin_src emacs-lisp
326 (push 2 *evaluation-collector*)
329 Third src_emacs-lisp{(push 3 *evaluation-collector*)}
332 #+call: foo-for-order-of-evaluation(4)
335 #+begin_src emacs-lisp
336 (push 5 *evaluation-collector*)