Variable: org-babel-default-header-args

org-babel-default-header-args is a variable defined in ob-core.el.gz.

Value

((:session . "none") (:results . "replace") (:exports . "code")
 (:cache . "no") (:noweb . "no") (:hlines . "no") (:tangle . "no"))

Documentation

Default arguments to use when evaluating a source block.

This is a list in which each element is an alist. Each key corresponds to a header argument, and each value to that header's value. The value can either be a string or a closure that evaluates to a string.

A closure is evaluated when the source block is being evaluated (e.g. during execution or export), with point at the source block. It is not possible to use an arbitrary function symbol (e.g. some-func), since org uses lexical binding. To achieve the same functionality, call the function within a closure (e.g. (lambda () (some-func))).

To understand how closures can be used as default header arguments, imagine you'd like to set the file name output of a latex source block to a sha1 of its contents. We could achieve this with:

  (defun org-src-sha ()
    (let ((elem (org-element-at-point)))
      (concat (sha1 (org-element-property :value elem)) ".svg")))

  (setq org-babel-default-header-args:latex
        `((:results . "file link replace")
          (:file . (lambda () (org-src-sha)))))

Because the closure is evaluated with point at the source block, the call to org-element-at-point above will always retrieve information about the current source block.

Some header arguments can be provided multiple times for a source block. An example of such a header argument is :var. This functionality is also supported for default header arguments by providing the header argument multiple times in the alist. For example:

 ((:var . "foo=\\"bar\"")
  (:var . "bar=\\"foo\""))

Source Code

;; Defined in /usr/src/emacs/lisp/org/ob-core.el.gz
(defvar org-babel-default-header-args
  '((:session . "none") (:results . "replace") (:exports . "code")
    (:cache . "no") (:noweb . "no") (:hlines . "no") (:tangle . "no"))
  "Default arguments to use when evaluating a source block.

This is a list in which each element is an alist.  Each key
corresponds to a header argument, and each value to that header's
value.  The value can either be a string or a closure that
evaluates to a string.

A closure is evaluated when the source block is being
evaluated (e.g. during execution or export), with point at the
source block.  It is not possible to use an arbitrary function
symbol (e.g. `some-func'), since org uses lexical binding.  To
achieve the same functionality, call the function within a
closure (e.g. (lambda () (some-func))).

To understand how closures can be used as default header
arguments, imagine you'd like to set the file name output of a
latex source block to a sha1 of its contents.  We could achieve
this with:

  (defun org-src-sha ()
    (let ((elem (org-element-at-point)))
      (concat (sha1 (org-element-property :value elem)) \".svg\")))

  (setq org-babel-default-header-args:latex
        `((:results . \"file link replace\")
          (:file . (lambda () (org-src-sha)))))

Because the closure is evaluated with point at the source block,
the call to `org-element-at-point' above will always retrieve
information about the current source block.

Some header arguments can be provided multiple times for a source
block.  An example of such a header argument is :var.  This
functionality is also supported for default header arguments by
providing the header argument multiple times in the alist.  For
example:

 ((:var . \"foo=\\\"bar\\\"\")
  (:var . \"bar=\\\"foo\\\"\"))")