12 KB

:noweb header argument expansion

:PROPERTIES: :ID: eb1f6498-5bd9-45e0-9c56-50717053e7 :END:

(message "expanded1")

(message "expanded2")

;; noweb-1-yes-start <>

;; noweb-no-start <>

;; noweb-2-yes-start <>

;; noweb-tangle-start <> <>

:noweb header argument expansion using

:PROPERTIES: :ID: 8701beb4-13d9-468c-997a-8e63e8b66f :END:

(message "expanded1")

(message "expanded2")

;; noweb-1-yes-start <>

;; noweb-no-start <>

;; noweb-2-yes-start <>

<> <>

excessive id links on tangling

:PROPERTIES: :ID: ef06fd7f-012b-4fde-87a2-2ae91504ea :END:

no, don't give me an ID

(message "not to be tangled")

yes, I'd love an ID

:PROPERTIES: :ID: ae7b55ca-9ef2-4d30-bd48-da30e35fd0 :END:

(message "for tangling")

simple named code block

:PROPERTIES: :ID: 0d82b52d-1bb9-4916-816b-2c67c8108d :END:



Pascal's Triangle -- exports both test

:PROPERTIES: :ID: 92518f2a-a46a-4205-a3ab-bcce1008a4 :END:

(require 'cl) (defalias 'my-map (if (org-version-check "24.2.50" "cl" :predicate) 'cl-map 'map)) (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 (my-map 'list #'+ (append prev-row '(0)) (append '(0) prev-row)))))))

(pascals-triangle n)

calling code blocks from inside table

:PROPERTIES: :ID: 6d2ff4ce-4489-4e2a-9c65-e3f71f77d9 :END:

(sqrt n)

executing an lob call line

:PROPERTIES: :header-args: :results silent :ID: fab7e291-fde6-45fc-bf6e-a485b8bca2 :END:

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_echo("testing") call_concat(1,2,3)

(format "%S%S%S" a b c)

exporting an lob call line

:PROPERTIES: :ID: 72ddeed3-2d17-4c7f-8192-a575d535d3 :END:

(* 2 it)

The following exports as a normal call line

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: :ID: 54cb8dc3-298c-4883-a933-029b3c9d4b :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.

exported inline source block

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. Here is one that is also evaluated: src_sh[:exports both]{echo 4}

mixed blocks with exports both

:PROPERTIES: :ID: 5daa4d03-e3ea-46b7-b093-62c1b7632d :END:

  • a
  • b
  • c

"code block results"

(reverse lst)

using the :noweb-ref header argument

:PROPERTIES: :ID: 54d68d4b-1544-4745-85ab-4f03b3cbd8 :header-args: :noweb-sep "" :END:


query all mounted disks


strip the header row

|sed '1d'

sort by the percent full

|awk '{print $5 " " $6}'|sort -n |tail -1

extract the mount point

|awk '{print $2}'

resolving sub-trees as references

:PROPERTIES: :ID: 2409e8ba-7b5f-4678-8888-e48aa02d8c :header-args: :results silent :END:

(length text)

<> <>

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-dd7141c633 :END: has length 14

exporting a code block with a name

:PROPERTIES: :ID: b02ddd8a-eeb8-42ab-8664-8a759e6f43 :END:

exporting a code block with a name

echo bar

noweb no-export and exports both

:PROPERTIES: :ID: 8a820f6c-7980-43db-8a24-0710d33729 :END: Weird interaction.

here is one block

  echo 1

and another

  # I am inside the code block

in order evaluation on export

:PROPERTIES: :header-args: :exports results :ID: 96cc7073-97ec-4556-87cf-1f9bffafd3 :END:


(push it evaluation-collector)


(push 2 evaluation-collector)

Third src_emacs-lisp{(car (push 3 evaluation-collector))}



(push 5 evaluation-collector)

exporting more than just results from a call line

:PROPERTIES: :ID: bec63a04-491e-4caa-97f5-108f302036 :END: Here is a call line with more than just the results exported.

strip noweb references on export

:PROPERTIES: :ID: 8e7bd234-99b2-4b14-8cd6-53945e4097 :END:


  echo "1$i"

use case of reading entry properties

:PROPERTIES: :ID: cc5fbc20-bca5-437a-a7b8-2b4d7a03f8 :END:

Use case checked and documented with this test: During their evaluation the source blocks read values from properties from the entry where the call has been made unless the value is overridden with the optional argument of the caller.


:PROPERTIES: :a: 1 :c: 3 :END:

Note: Just export of a property can be done with a macro: {{{property(a)}}}.

  • sect inline call_src_block_location_shell()[:results raw]
  • sect inline call_src_block_location_elisp()[:results raw]


:PROPERTIES: :b: 2 :c: 4 :END:

  • sub0 inline call_src_block_location_shell()[:results raw]
  • sub0 inline call_src_block_location_elisp()[:results raw]
  • sub1 inline call_src_block_location_shell(c=5, e=6)[:results raw]
  • sub1 inline call_src_block_location_elisp(c=5, e=6)[:results raw]

function definition

    comments for ":var":
  • The "or" is to deal with a property not present.
  • The t is to get property inheritance.

  printf "shell a:$a, b:$b, c:$c, d:$d, e:$e"

   ;; - The first `or' together with ":var <var>='nil" is to check for
   ;;   a value bound from an optional call argument, in the examples
   ;;   here: c=5, e=6
   ;; - The second `or' is to deal with a property not present
   ;; - The t is to get property inheritance
   a (or a (string-to-number
            (or (org-entry-get org-babel-current-src-block-location "a" t)
   b (or b (string-to-number
            (or (org-entry-get org-babel-current-src-block-location "b" t)
   c (or c (string-to-number
            (or (org-entry-get org-babel-current-src-block-location "c" t)
   d (or d (string-to-number
            (or (org-entry-get org-babel-current-src-block-location "e" t)
   e (or e (string-to-number
            (or (org-entry-get org-babel-current-src-block-location "d" t)
  (format "elisp a:%d, b:%d, c:%d, d:%d, e:%d" a b c d e)

:file-ext and :output-dir header args

:PROPERTIES: :ID: 93573e1d-6486-442e-b6d0-3fedbdc37c :END: