Delete trailing whitespaces.
[org-mode.git] / testing / examples / babel.org
blobbcb7e578688f9ceee6516ca7f5bff5ddc495c893
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
11   (message "expanded")
12 #+end_src
14 #+begin_src emacs-lisp :noweb yes
15   ;; noweb-yes-start
16   <<noweb-example>>
17   ;; noweb-yes-end
18 #+end_src
20 #+begin_src emacs-lisp :noweb no
21   ;; noweb-no-start
22   <<noweb-example>>
23   ;; noweb-no-end
24 #+end_src
26 #+begin_src emacs-lisp :noweb tangle
27   ;; noweb-tangle-start
28   <<noweb-example>>
29   ;; noweb-tangle-end
30 #+end_src
32 * excessive id links on tangling
33   :PROPERTIES:
34   :ID:       ef06fd7f-012b-4fde-87a2-2ae91504ea7e
35   :END:
37 ** no, don't give me an ID
38 #+begin_src emacs-lisp :tangle no
39   (message "not to be tangled")
40 #+end_src
42 ** yes, I'd love an ID
43    :PROPERTIES:
44    :ID:       ae7b55ca-9ef2-4d30-bd48-da30e35fd0f3
45    :END:
46 #+begin_src emacs-lisp :tangle no
47   (message "for tangling")
48 #+end_src
49 * simple named code block
50   :PROPERTIES:
51   :ID:       0d82b52d-1bb9-4916-816b-2c67c8108dbb
52   :END:
54 #+name: i-have-a-name
55 #+begin_src emacs-lisp
56   42
57 #+end_src
59 #+name:
60 : 42
62 #+name: i-have-a-name
63 : 42
65 * Pascal's Triangle -- export test
66   :PROPERTIES:
67   :ID:       92518f2a-a46a-4205-a3ab-bcce1008a4bb
68   :END:
70 #+name: pascals-triangle
71 #+begin_src emacs-lisp :var n=5 :exports both
72   (defun pascals-triangle (n)
73     (if (= n 0)
74         (list (list 1))
75       (let* ((prev-triangle (pascals-triangle (- n 1)))
76              (prev-row (car (reverse prev-triangle))))
77         (append prev-triangle
78                 (list (map 'list #'+
79                            (append prev-row '(0))
80                            (append '(0) prev-row)))))))
82   (pascals-triangle n)
83 #+end_src
85 * calling code blocks from inside table
86   :PROPERTIES:
87   :ID:       6d2ff4ce-4489-4e2a-9c65-e3f71f77d975
88   :END:
90 #+name: take-sqrt
91 #+begin_src emacs-lisp :var n=9
92   (sqrt n)
93 #+end_src
95 * executing an lob call line
96   :PROPERTIES:
97   :results:  silent
98   :ID:       fab7e291-fde6-45fc-bf6e-a485b8bca2f0
99   :END:
101 #+call: echo(input="testing")
102 #+call: echo(input="testing") :results vector
103 #+call: echo[:var input="testing"]()
104 #+call: echo[:var input="testing"]() :results vector
105 #+call: echo("testing")
106 #+call: echo("testing") :results vector
107 This is an inline call call_echo(input="testing") embedded in prose.
108 This is an inline call call_echo(input="testing")[:results vector] embedded in prose.
109 #+call: lob-minus(8, 4)
110 call_echo("testing")
111 call_concat(1,2,3)
113 #+name: concat
114 #+begin_src emacs-lisp :var a=0 :var b=0 :var c=0
115   (format "%S%S%S" a b c)
116 #+end_src
118 * exporting an lob call line
119   :PROPERTIES:
120   :ID:       72ddeed3-2d17-4c7f-8192-a575d535d3fc
121   :END:
123 #+name: double
124 #+begin_src emacs-lisp :var it=0
125   (* 2 it)
126 #+end_src
128 The following exports as a normal call line
129 #+call: double(it=0)
131 Now here is an inline call call_double(it=1) stuck in the middle of
132 some prose.
134 This one should not be exported =call_double(it=2)= because it is
135 quoted.
137 Finally this next one should export, even though it starts a line
138 call_double(it=3) because sometimes inline blocks fold with a
139 paragraph.
141 And, a call with raw results call_double(4)[:results raw] should not
142 have quoted results.
144 The following 2*5=call_double(5) should export even when prefixed by
145 an = sign.
147 * inline source block
148   :PROPERTIES:
149   :results:  silent
150   :ID:       54cb8dc3-298c-4883-a933-029b3c9d4b18
151   :END:
152 Here is one in the middle src_sh{echo 1} of a line.
153 Here is one at the end of a line. src_sh{echo 2}
154 src_sh{echo 3} Here is one at the beginning of a line.
156 * conflicting blocks on export
157   :PROPERTIES:
158   :ID:       5daa4d03-e3ea-46b7-b093-62c1b7632df3
159   :END:
160 #+name: a-list
161 - a
162 - b
163 - c
165 #+begin_src emacs-lisp :results wrap :exports both
166     "code block results"
167 #+end_src
168 #+begin_src emacs-lisp :var lst=a-list :results list
169   (reverse lst)
170 #+end_src
171 * using the =:noweb-ref= header argument
172   :PROPERTIES:
173   :ID:       54d68d4b-1544-4745-85ab-4f03b3cbd8a0
174   :END:
176 #+begin_src sh :tangle yes :noweb yes :shebang #!/bin/sh
177   <<fullest-disk>>
178 #+end_src
180 ** query all mounted disks
181 #+begin_src sh :noweb-ref fullest-disk
182   df
183 #+end_src
185 ** strip the header row
186 #+begin_src sh :noweb-ref fullest-disk
187   |sed '1d'
188 #+end_src
190 ** sort by the percent full
191 #+begin_src sh :noweb-ref fullest-disk
192   |awk '{print $5 " " $6}'|sort -n |tail -1
193 #+end_src
195 ** extract the mount point
196 #+begin_src sh :noweb-ref fullest-disk
197   |awk '{print $2}'
198 #+end_src
199 * resolving sub-trees as references
200   :PROPERTIES:
201   :ID:       2409e8ba-7b5f-4678-8888-e48aa02d8cb4
202   :results:  silent
203   :END:
205 #+begin_src emacs-lisp :var text=d4faa7b3-072b-4dcf-813c-dd7141c633f3
206   (length text)
207 #+end_src
209 #+begin_src org :noweb yes
210   <<simple-subtree>>
211   <<d4faa7b3-072b-4dcf-813c-dd7141c633f3>>
212 #+end_src
214 ** simple subtree with custom ID
215    :PROPERTIES:
216    :CUSTOM_ID: simple-subtree
217    :END:
218 this is simple
220 ** simple subtree with global ID
221    :PROPERTIES:
222    :ID:       d4faa7b3-072b-4dcf-813c-dd7141c633f3
223    :END:
224 has length 14
226 * org-babel-get-inline-src-block-matches
227   :PROPERTIES:
228   :results:  silent
229   :ID:       0D0983D4-DE33-400A-8A05-A225A567BC74
230   :END:
231 src_sh{echo "One"} block at start of line
232  One spaced block in  src_sh{ echo "middle" } of line
233 src_sh{echo 2} blocks on the src_emacs-lisp{"same"} line
234  Inline block with src_sh[:results silent]{ echo "parameters" }.