optionally export additional information with call lines
[org-mode/org-mode-NeilSmithlineMods.git] / testing / examples / babel.org
blobbfa366f33c71e2f89565f2c36daa41f691d4a80c
1 #+Title: a collection of examples for Babel tests
2 #+OPTIONS: ^:nil
4 * =:noweb= header argument expansion
5   :PROPERTIES:
6   :ID:       eb1f6498-5bd9-45e0-9c56-50717053e7b7
7   :END:
9 #+name: noweb-example
10 #+begin_src emacs-lisp :results silent :exports code
11   (message "expanded1")
12 #+end_src
14 #+name: noweb-example2
15 #+begin_src emacs-lisp :results silent
16   (message "expanded2")
17 #+end_src
19 #+begin_src emacs-lisp :noweb yes :results silent
20 ;; noweb-1-yes-start
21   <<noweb-example>>
22 #+end_src
24 #+begin_src emacs-lisp :noweb no  :results silent
25 ;; noweb-no-start
26   <<noweb-example1>>
27 #+end_src
29 #+begin_src emacs-lisp :noweb yes :results silent
30 ;; noweb-2-yes-start
31   <<noweb-example2>>
32 #+end_src
34 #+begin_src emacs-lisp :noweb tangle :results silent
35   ;; noweb-tangle-start
36   <<noweb-example1>>
37   <<noweb-example2>>
38 #+end_src
40 * =:noweb= header argument expansion using :exports results
41   :PROPERTIES:
42   :ID:       8701beb4-13d9-468c-997a-8e63e8b66f8d
43   :END:
45 #+name: noweb-example
46 #+begin_src emacs-lisp :exports results
47   (message "expanded1")
48 #+end_src
50 #+name: noweb-example2
51 #+begin_src emacs-lisp :exports results
52   (message "expanded2")
53 #+end_src
55 #+begin_src emacs-lisp :noweb yes :exports results
56 ;; noweb-1-yes-start
57   <<noweb-example>>
58 #+end_src
60 #+begin_src emacs-lisp :noweb no :exports code
61 ;; noweb-no-start
62   <<noweb-example1>>
63 #+end_src
65 #+begin_src emacs-lisp :noweb yes :exports results
66 ;; noweb-2-yes-start
67   <<noweb-example2>>
68 #+end_src
70 #+begin_src emacs-lisp :noweb tangle :exports code
71   <<noweb-example1>>
72   <<noweb-example2>>
73 #+end_src
75 * excessive id links on tangling
76   :PROPERTIES:
77   :ID:       ef06fd7f-012b-4fde-87a2-2ae91504ea7e
78   :END:
80 ** no, don't give me an ID
81 #+begin_src emacs-lisp :tangle no
82   (message "not to be tangled")
83 #+end_src
85 ** yes, I'd love an ID
86    :PROPERTIES:
87    :ID:       ae7b55ca-9ef2-4d30-bd48-da30e35fd0f3
88    :END:
89 #+begin_src emacs-lisp :tangle no
90   (message "for tangling")
91 #+end_src
92 * simple named code block
93   :PROPERTIES:
94   :ID:       0d82b52d-1bb9-4916-816b-2c67c8108dbb
95   :END:
97 #+name: i-have-a-name
98 #+begin_src emacs-lisp
99   42
100 #+end_src
102 #+name:
103 : 42
105 #+name: i-have-a-name
106 : 42
108 * Pascal's Triangle -- exports both test
109   :PROPERTIES:
110   :ID:       92518f2a-a46a-4205-a3ab-bcce1008a4bb
111   :END:
113 #+name: pascals-triangle
114 #+begin_src emacs-lisp :var n=5 :exports both
115   (defun pascals-triangle (n)
116     (if (= n 0)
117         (list (list 1))
118       (let* ((prev-triangle (pascals-triangle (- n 1)))
119              (prev-row (car (reverse prev-triangle))))
120         (append prev-triangle
121                 (list (map 'list #'+
122                            (append prev-row '(0))
123                            (append '(0) prev-row)))))))
125   (pascals-triangle n)
126 #+end_src
128 * calling code blocks from inside table
129   :PROPERTIES:
130   :ID:       6d2ff4ce-4489-4e2a-9c65-e3f71f77d975
131   :END:
133 #+name: take-sqrt
134 #+begin_src emacs-lisp :var n=9
135   (sqrt n)
136 #+end_src
138 * executing an lob call line
139   :PROPERTIES:
140   :results:  silent
141   :ID:       fab7e291-fde6-45fc-bf6e-a485b8bca2f0
142   :END:
144 #+call: echo(input="testing")
145 #+call: echo(input="testing") :results vector
146 #+call: echo[:var input="testing"]()
147 #+call: echo[:var input="testing"]() :results vector
148 #+call: echo("testing")
149 #+call: echo("testing") :results vector
150 This is an inline call call_echo(input="testing") embedded in prose.
151 This is an inline call call_echo(input="testing")[:results vector] embedded in prose.
152 #+call: lob-minus(8, 4)
153 call_echo("testing")
154 call_concat(1,2,3)
156 #+name: concat
157 #+begin_src emacs-lisp :var a=0 :var b=0 :var c=0
158   (format "%S%S%S" a b c)
159 #+end_src
161 * exporting an lob call line
162   :PROPERTIES:
163   :ID:       72ddeed3-2d17-4c7f-8192-a575d535d3fc
164   :END:
166 #+name: double
167 #+begin_src emacs-lisp :var it=0
168   (* 2 it)
169 #+end_src
171 The following exports as a normal call line
172 #+call: double(it=0)
174 Now here is an inline call call_double(it=1) stuck in the middle of
175 some prose.
177 This one should not be exported =call_double(it=2)= because it is
178 quoted.
180 Finally this next one should export, even though it starts a line
181 call_double(it=3) because sometimes inline blocks fold with a
182 paragraph.
184 And, a call with raw results call_double(4)[:results raw] should not
185 have quoted results.
187 The following 2*5=call_double(5) should export even when prefixed by
188 an = sign.
190 * inline source block
191   :PROPERTIES:
192   :results:  silent
193   :ID:       54cb8dc3-298c-4883-a933-029b3c9d4b18
194   :END:
195 Here is one in the middle src_sh{echo 1} of a line.
196 Here is one at the end of a line. src_sh{echo 2}
197 src_sh{echo 3} Here is one at the beginning of a line.
199 * mixed blocks with exports both
200   :PROPERTIES:
201   :ID:       5daa4d03-e3ea-46b7-b093-62c1b7632df3
202   :END:
204 #+name: a-list
205 - a
206 - b
207 - c
209 #+begin_src emacs-lisp :exports both
210     "code block results"
211 #+end_src
213 #+begin_src emacs-lisp :var lst=a-list :results list :exports both
214   (reverse lst)
215 #+end_src
217 * using the =:noweb-ref= header argument
218   :PROPERTIES:
219   :ID:       54d68d4b-1544-4745-85ab-4f03b3cbd8a0
220   :END:
222 #+begin_src sh :tangle yes :noweb yes :shebang #!/bin/sh
223   <<fullest-disk>>
224 #+end_src
226 ** query all mounted disks
227 #+begin_src sh :noweb-ref fullest-disk
228   df
229 #+end_src
231 ** strip the header row
232 #+begin_src sh :noweb-ref fullest-disk
233   |sed '1d'
234 #+end_src
236 ** sort by the percent full
237 #+begin_src sh :noweb-ref fullest-disk
238   |awk '{print $5 " " $6}'|sort -n |tail -1
239 #+end_src
241 ** extract the mount point
242 #+begin_src sh :noweb-ref fullest-disk
243   |awk '{print $2}'
244 #+end_src
245 * resolving sub-trees as references
246   :PROPERTIES:
247   :ID:       2409e8ba-7b5f-4678-8888-e48aa02d8cb4
248   :results:  silent
249   :END:
251 #+begin_src emacs-lisp :var text=d4faa7b3-072b-4dcf-813c-dd7141c633f3
252   (length text)
253 #+end_src
255 #+begin_src org :noweb yes
256   <<simple-subtree>>
257   <<d4faa7b3-072b-4dcf-813c-dd7141c633f3>>
258 #+end_src
260 ** simple subtree with custom ID
261    :PROPERTIES:
262    :CUSTOM_ID: simple-subtree
263    :END:
264 this is simple
266 ** simple subtree with global ID
267    :PROPERTIES:
268    :ID:       d4faa7b3-072b-4dcf-813c-dd7141c633f3
269    :END:
270 has length 14
272 * org-babel-get-inline-src-block-matches
273   :PROPERTIES:
274   :results:  silent
275   :ID:       0D0983D4-DE33-400A-8A05-A225A567BC74
276   :END:
277 src_sh{echo "One"} block at start of line
278  One spaced block in  src_sh{ echo "middle" } of line
279 src_sh{echo 2} blocks on the src_emacs-lisp{"same"} line
280  Inline block with src_sh[:results silent]{ echo "parameters" }.
281 * exporting a code block with a name
282   :PROPERTIES:
283   :ID:       b02ddd8a-eeb8-42ab-8664-8a759e6f43d9
284   :END:
286 exporting a code block with a name
287 #+name: qux
288 #+begin_src sh :foo "baz"
289   echo bar
290 #+end_src
291 * noweb no-export and exports both
292   :PROPERTIES:
293   :ID:       8a820f6c-7980-43db-8a24-0710d33729c9
294   :END:
295 Weird interaction.
297 here is one block
299 #+name: noweb-no-export-and-exports-both-1
300 #+BEGIN_SRC sh :exports none
301   echo 1
302 #+END_SRC
304 and another
306 #+BEGIN_SRC sh :noweb no-export :exports both
307   # I am inside the code block
308   <<noweb-no-export-and-exports-both-1>>
309 #+END_SRC
311 * in order evaluation on export
312   :PROPERTIES:
313   :exports: results
314   :ID:       96cc7073-97ec-4556-87cf-1f9bffafd317
315   :END:
317 First.
318 #+name: foo-for-order-of-evaluation
319 #+begin_src emacs-lisp :var it=1
320   (push it *evaluation-collector*)
321 #+end_src
323 Second
324 #+begin_src emacs-lisp
325   (push 2 *evaluation-collector*)
326 #+end_src
328 Third src_emacs-lisp{(push 3 *evaluation-collector*)}
330 Fourth
331 #+call: foo-for-order-of-evaluation(4)
333 Fifth
334 #+begin_src emacs-lisp
335   (push 5 *evaluation-collector*)
336 #+end_src
337 * exporting more than just results from a call line
338   :PROPERTIES:
339   :ID:       bec63a04-491e-4caa-97f5-108f3020365c
340   :END:
341 Here is a call line with more than just the results exported.
342 #+call: double(8)