0
0
Fork 1
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-09-19 08:10:04 +00:00
org-mode/testing/examples/babel.org
Bastien Guerry ecd0562c5f Fix the master branch.
I started from the 78ec8e commit then cherry-picked and squashed
commits that have been done in master since then, except the bad
commits that overwrote the tree (in master) with the tree in maint.

This commit also bumps the version number to 7.8.06.

The only "fix" that was made between 78ec8e and the previous commit
is e0072f which has been reported to break stuff.
2012-03-19 22:01:29 +01:00

358 lines
7.8 KiB
Org Mode

#+Title: a collection of examples for Babel tests
#+OPTIONS: ^:nil
* =:noweb= header argument expansion
:PROPERTIES:
:ID: eb1f6498-5bd9-45e0-9c56-50717053e7b7
:END:
#+name: noweb-example
#+begin_src emacs-lisp :results silent :exports code
(message "expanded1")
#+end_src
#+name: noweb-example2
#+begin_src emacs-lisp :results silent
(message "expanded2")
#+end_src
#+begin_src emacs-lisp :noweb yes :results silent
;; noweb-1-yes-start
<<noweb-example>>
#+end_src
#+begin_src emacs-lisp :noweb no :results silent
;; noweb-no-start
<<noweb-example1>>
#+end_src
#+begin_src emacs-lisp :noweb yes :results silent
;; noweb-2-yes-start
<<noweb-example2>>
#+end_src
#+begin_src emacs-lisp :noweb tangle :results silent
;; noweb-tangle-start
<<noweb-example1>>
<<noweb-example2>>
#+end_src
* =:noweb= header argument expansion using :exports results
:PROPERTIES:
:ID: 8701beb4-13d9-468c-997a-8e63e8b66f8d
:END:
#+name: noweb-example
#+begin_src emacs-lisp :exports results
(message "expanded1")
#+end_src
#+name: noweb-example2
#+begin_src emacs-lisp :exports results
(message "expanded2")
#+end_src
#+begin_src emacs-lisp :noweb yes :exports results
;; noweb-1-yes-start
<<noweb-example>>
#+end_src
#+begin_src emacs-lisp :noweb no :exports code
;; noweb-no-start
<<noweb-example1>>
#+end_src
#+begin_src emacs-lisp :noweb yes :exports results
;; noweb-2-yes-start
<<noweb-example2>>
#+end_src
#+begin_src emacs-lisp :noweb tangle :exports code
<<noweb-example1>>
<<noweb-example2>>
#+end_src
* excessive id links on tangling
:PROPERTIES:
:ID: ef06fd7f-012b-4fde-87a2-2ae91504ea7e
:END:
** no, don't give me an ID
#+begin_src emacs-lisp :tangle no
(message "not to be tangled")
#+end_src
** yes, I'd love an ID
:PROPERTIES:
:ID: ae7b55ca-9ef2-4d30-bd48-da30e35fd0f3
:END:
#+begin_src emacs-lisp :tangle no
(message "for tangling")
#+end_src
* simple named code block
:PROPERTIES:
:ID: 0d82b52d-1bb9-4916-816b-2c67c8108dbb
:END:
#+name: i-have-a-name
#+begin_src emacs-lisp
42
#+end_src
#+name:
: 42
#+name: i-have-a-name
: 42
* Pascal's Triangle -- exports both test
:PROPERTIES:
:ID: 92518f2a-a46a-4205-a3ab-bcce1008a4bb
:END:
#+name: pascals-triangle
#+begin_src emacs-lisp :var n=5 :exports both
(defun pascals-triangle (n)
(if (= n 0)
(list (list 1))
(let* ((prev-triangle (pascals-triangle (- n 1)))
(prev-row (car (reverse prev-triangle))))
(append prev-triangle
(list (map 'list #'+
(append prev-row '(0))
(append '(0) prev-row)))))))
(pascals-triangle n)
#+end_src
* calling code blocks from inside table
:PROPERTIES:
:ID: 6d2ff4ce-4489-4e2a-9c65-e3f71f77d975
:END:
#+name: take-sqrt
#+begin_src emacs-lisp :var n=9
(sqrt n)
#+end_src
* executing an lob call line
:PROPERTIES:
:results: silent
:ID: fab7e291-fde6-45fc-bf6e-a485b8bca2f0
:END:
#+call: echo(input="testing")
#+call: echo(input="testing") :results vector
#+call: echo[:var input="testing"]()
#+call: echo[:var input="testing"]() :results vector
#+call: echo("testing")
#+call: echo("testing") :results vector
This is an inline call call_echo(input="testing") embedded in prose.
This is an inline call call_echo(input="testing")[:results vector] embedded in prose.
#+call: lob-minus(8, 4)
call_echo("testing")
call_concat(1,2,3)
#+name: concat
#+begin_src emacs-lisp :var a=0 :var b=0 :var c=0
(format "%S%S%S" a b c)
#+end_src
* exporting an lob call line
:PROPERTIES:
:ID: 72ddeed3-2d17-4c7f-8192-a575d535d3fc
:END:
#+name: double
#+begin_src emacs-lisp :var it=0
(* 2 it)
#+end_src
The following exports as a normal call line
#+call: double(it=0)
Now here is an inline call call_double(it=1) stuck in the middle of
some prose.
This one should not be exported =call_double(it=2)= because it is
quoted.
Finally this next one should export, even though it starts a line
call_double(it=3) because sometimes inline blocks fold with a
paragraph.
And, a call with raw results call_double(4)[:results raw] should not
have quoted results.
The following 2*5=call_double(5) should export even when prefixed by
an = sign.
* inline source block
:PROPERTIES:
:results: silent
:ID: 54cb8dc3-298c-4883-a933-029b3c9d4b18
:END:
Here is one in the middle src_sh{echo 1} of a line.
Here is one at the end of a line. src_sh{echo 2}
src_sh{echo 3} Here is one at the beginning of a line.
* mixed blocks with exports both
:PROPERTIES:
:ID: 5daa4d03-e3ea-46b7-b093-62c1b7632df3
:END:
#+name: a-list
- a
- b
- c
#+begin_src emacs-lisp :exports both
"code block results"
#+end_src
#+begin_src emacs-lisp :var lst=a-list :results list :exports both
(reverse lst)
#+end_src
* using the =:noweb-ref= header argument
:PROPERTIES:
:ID: 54d68d4b-1544-4745-85ab-4f03b3cbd8a0
:noweb-sep: ""
:END:
#+begin_src sh :tangle yes :noweb yes :shebang #!/bin/sh
<<fullest-disk>>
#+end_src
** query all mounted disks
#+begin_src sh :noweb-ref fullest-disk
df
#+end_src
** strip the header row
#+begin_src sh :noweb-ref fullest-disk
|sed '1d'
#+end_src
** sort by the percent full
#+begin_src sh :noweb-ref fullest-disk
|awk '{print $5 " " $6}'|sort -n |tail -1
#+end_src
** extract the mount point
#+begin_src sh :noweb-ref fullest-disk
|awk '{print $2}'
#+end_src
* resolving sub-trees as references
:PROPERTIES:
:ID: 2409e8ba-7b5f-4678-8888-e48aa02d8cb4
:results: silent
:END:
#+begin_src emacs-lisp :var text=d4faa7b3-072b-4dcf-813c-dd7141c633f3
(length text)
#+end_src
#+begin_src org :noweb yes
<<simple-subtree>>
<<d4faa7b3-072b-4dcf-813c-dd7141c633f3>>
#+end_src
** simple subtree with custom ID
:PROPERTIES:
:CUSTOM_ID: simple-subtree
:END:
this is simple
** simple subtree with global ID
:PROPERTIES:
:ID: d4faa7b3-072b-4dcf-813c-dd7141c633f3
:END:
has length 14
* org-babel-get-inline-src-block-matches
:PROPERTIES:
:results: silent
:ID: 0D0983D4-DE33-400A-8A05-A225A567BC74
:END:
src_sh{echo "One"} block at start of line
One spaced block in src_sh{ echo "middle" } of line
src_sh{echo 2} blocks on the src_emacs-lisp{"same"} line
Inline block with src_sh[:results silent]{ echo "parameters" }.
* exporting a code block with a name
:PROPERTIES:
:ID: b02ddd8a-eeb8-42ab-8664-8a759e6f43d9
:END:
exporting a code block with a name
#+name: qux
#+begin_src sh :foo "baz"
echo bar
#+end_src
* noweb no-export and exports both
:PROPERTIES:
:ID: 8a820f6c-7980-43db-8a24-0710d33729c9
:END:
Weird interaction.
here is one block
#+name: noweb-no-export-and-exports-both-1
#+BEGIN_SRC sh :exports none
echo 1
#+END_SRC
and another
#+BEGIN_SRC sh :noweb no-export :exports both
# I am inside the code block
<<noweb-no-export-and-exports-both-1>>
#+END_SRC
* in order evaluation on export
:PROPERTIES:
:exports: results
:ID: 96cc7073-97ec-4556-87cf-1f9bffafd317
:END:
First.
#+name: foo-for-order-of-evaluation
#+begin_src emacs-lisp :var it=1
(push it *evaluation-collector*)
#+end_src
Second
#+begin_src emacs-lisp
(push 2 *evaluation-collector*)
#+end_src
Third src_emacs-lisp{(push 3 *evaluation-collector*)}
Fourth
#+call: foo-for-order-of-evaluation(4)
Fifth
#+begin_src emacs-lisp
(push 5 *evaluation-collector*)
#+end_src
* exporting more than just results from a call line
:PROPERTIES:
:ID: bec63a04-491e-4caa-97f5-108f3020365c
:END:
Here is a call line with more than just the results exported.
#+call: double(8)
* strip noweb references on export
:PROPERTIES:
:ID: 8e7bd234-99b2-4b14-8cd6-53945e409775
:END:
#+name: strip-export-1
#+BEGIN_SRC sh :exports none
i="10"
#+END_SRC
#+BEGIN_SRC sh :noweb strip-export :exports code :results silent
<<strip-export-1>>
echo "1$i"
#+END_SRC