org-lparse.el: don't need to be executable.
[org-mode/org-mode-NeilSmithlineMods.git] / testing / examples / babel.org
blobbb9cab9197e793c4c087360118b1e2aacf1bd4f6
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 * elisp forms in header arguments
33   :PROPERTIES:
34   :ID:       22d67284-bf14-4cdc-8319-f4bd876829d7
35   :var:      prop=(+ 2 2)
36   :END:
38 #+begin_src emacs-lisp
39   prop
40 #+end_src
42 #+name:
43 : 4
45 * excessive id links on tangling
46   :PROPERTIES:
47   :ID:       ef06fd7f-012b-4fde-87a2-2ae91504ea7e
48   :END:
50 ** no, don't give me an ID
51 #+begin_src emacs-lisp :tangle no
52   (message "not to be tangled")
53 #+end_src
55 ** yes, I'd love an ID
56    :PROPERTIES:
57    :ID:       ae7b55ca-9ef2-4d30-bd48-da30e35fd0f3
58    :END:
59 #+begin_src emacs-lisp :tangle no
60   (message "for tangling")
61 #+end_src
62 * simple variable resolution
63   :PROPERTIES:
64   :ID:       f68821bc-7f49-4389-85b5-914791ee3718
65   :END:
67 #+name: four
68 #+begin_src emacs-lisp
69   (list 1 2 3 4)
70 #+end_src
72 #+begin_src emacs-lisp :var four=four
73   (length four)
74 #+end_src
76 #+name:
77 : 4
79 * multi-line header arguments
80   :PROPERTIES:
81   :ID:       b77c8857-6c76-4ea9-8a61-ddc2648d96c4
82   :END:
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)
87 #+end_src
89 #+name:
90 | 1 | a |
91 | 2 | b |
92 | 3 | c |
93 | 4 | d |
94 | 5 | e |
95 | 6 | f |
96 | 7 | g |
98 * simple named code block
99   :PROPERTIES:
100   :ID:       0d82b52d-1bb9-4916-816b-2c67c8108dbb
101   :END:
103 #+name: i-have-a-name
104 #+begin_src emacs-lisp
105   42
106 #+end_src
108 #+name:
109 : 42
111 #+name: i-have-a-name
112 : 42
114 * Pascal's Triangle -- export test
115   :PROPERTIES:
116   :ID:       92518f2a-a46a-4205-a3ab-bcce1008a4bb
117   :END:
119 #+name: pascals-triangle
120 #+begin_src emacs-lisp :var n=5 :exports both
121   (defun pascals-triangle (n)
122     (if (= n 0)
123         (list (list 1))
124       (let* ((prev-triangle (pascals-triangle (- n 1)))
125              (prev-row (car (reverse prev-triangle))))
126         (append prev-triangle
127                 (list (map 'list #'+
128                            (append prev-row '(0))
129                            (append '(0) prev-row)))))))
131   (pascals-triangle n)
132 #+end_src
134 * calling code blocks from inside table
135   :PROPERTIES:
136   :ID:       6d2ff4ce-4489-4e2a-9c65-e3f71f77d975
137   :END:
139 #+name: take-sqrt
140 #+begin_src emacs-lisp :var n=9
141   (sqrt n)
142 #+end_src
144 * executing an lob call line
145   :PROPERTIES:
146   :results:  silent
147   :ID:       fab7e291-fde6-45fc-bf6e-a485b8bca2f0
148   :END:
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)
159 call_echo("testing")
160 call_concat(1,2,3)
162 #+name: concat
163 #+begin_src emacs-lisp :var a=0 :var b=0 :var c=0
164   (format "%S%S%S" a b c)
165 #+end_src
167 * exporting an lob call line
168   :PROPERTIES:
169   :ID:       72ddeed3-2d17-4c7f-8192-a575d535d3fc
170   :END:
172 #+name: double
173 #+begin_src emacs-lisp :var it=0
174   (* 2 it)
175 #+end_src
177 The following exports as a normal call line
178 #+call: double(it=0)
180 Now here is an inline call call_double(it=1) stuck in the middle of
181 some prose.
183 This one should not be exported =call_double(it=2)= because it is
184 quoted.
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
188 paragraph.
190 And, a call with raw results call_double(4)[:results raw] should not
191 have quoted results.
193 The following 2*5=call_double(5) should export even when prefixed by
194 an = sign.
196 * inline source block
197   :PROPERTIES:
198   :results:  silent
199   :ID:       54cb8dc3-298c-4883-a933-029b3c9d4b18
200   :END:
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
206   :PROPERTIES:
207   :ID:       7eb0dc6e-1c53-4275-88b3-b22f3113b9c3
208   :END:
210 #+begin_src example-lang :session     :results output :var num=9
211   the body
212 #+end_src
213 * conflicting blocks on export
214   :PROPERTIES:
215   :ID:       5daa4d03-e3ea-46b7-b093-62c1b7632df3
216   :END:
217 #+name: a-list
218 - a
219 - b
220 - c
222 #+begin_src emacs-lisp :results wrap :exports both
223     "code block results"
224 #+end_src
225 #+begin_src emacs-lisp :var lst=a-list :results list
226   (reverse lst)
227 #+end_src
228 * using the =:noweb-ref= header argument
229   :PROPERTIES:
230   :ID:       54d68d4b-1544-4745-85ab-4f03b3cbd8a0
231   :END:
233 #+begin_src sh :tangle yes :noweb yes :shebang #!/bin/sh
234   <<fullest-disk>>
235 #+end_src
237 ** query all mounted disks
238 #+begin_src sh :noweb-ref fullest-disk
239   df
240 #+end_src
242 ** strip the header row
243 #+begin_src sh :noweb-ref fullest-disk
244   |sed '1d'
245 #+end_src
247 ** sort by the percent full
248 #+begin_src sh :noweb-ref fullest-disk
249   |awk '{print $5 " " $6}'|sort -n |tail -1
250 #+end_src
252 ** extract the mount point
253 #+begin_src sh :noweb-ref fullest-disk
254   |awk '{print $2}'
255 #+end_src
256 * resolving sub-trees as references
257   :PROPERTIES:
258   :ID:       2409e8ba-7b5f-4678-8888-e48aa02d8cb4
259   :results:  silent
260   :END:
262 #+begin_src emacs-lisp :var text=d4faa7b3-072b-4dcf-813c-dd7141c633f3
263   (length text)
264 #+end_src
266 #+begin_src org :noweb yes
267   <<simple-subtree>>
268   <<d4faa7b3-072b-4dcf-813c-dd7141c633f3>>
269 #+end_src
271 ** simple subtree with custom ID
272    :PROPERTIES:
273    :CUSTOM_ID: simple-subtree
274    :END:
275 this is simple
277 ** simple subtree with global ID
278    :PROPERTIES:
279    :ID:       d4faa7b3-072b-4dcf-813c-dd7141c633f3
280    :END:
281 has length 14
283 * org-babel-get-inline-src-block-matches
284   :PROPERTIES:  
285   :results:  silent
286   :ID:       0D0983D4-DE33-400A-8A05-A225A567BC74
287   :END:
288 src_sh{echo "One"} block at start of line
289  One spaced block in  src_sh{ echo "middle" } of line 
290 src_sh{echo 2} blocks on the src_emacs-lisp{"same"} line
291  Inline block with src_sh[:results silent]{ echo "parameters" }.
292 * returning file names -- interpreted as lists
293   :PROPERTIES:
294   :ID:       a73a2ab6-b8b2-4c0e-ae7f-23ad14eab7bc
295   :END:
297 #+begin_src sh :results scalar
298   echo "[[file:./cv.cls]]"
299 #+end_src
301 #+name:
302 : [[file:./cv.cls]]
304 #+begin_src sh :results raw scalar
305    echo "[[file:./cv.cls]]"
306 #+end_src
308 #+name:
309 [[file:./cv.cls]]