DONE code block body expansion for table and preview

  • State "DONE" from "" 2010-04-23 Fri 09:44

In org-babel, code is "expanded" prior to evaluation. I.e. the code that is actually evaluated comprises the code block contents, augmented with the extra code which assigns the referenced data to variables. It is now possible to preview expanded contents, and also to expand code during during tangling. This expansion takes into account all header arguments, and variables.

preview
A new key-binding C-c M-b p bound to `org-babel-expand-src-block' can be used from inside of a source code block to preview its expanded contents (which can be very useful for debugging).
tangling
The expanded body can now be tangled, this includes variable values which may be the results of other source-code blocks, or stored in headline properties or tables. One possible use for this is to allow those using org-babel for their emacs initialization to store values (e.g. usernames, passwords, etc…) in headline properties or in tables. The :no-expand header argument can be used to inhibit expansion of a code block body during tangling.

Here is an example of a code block and its resulting expanded body.

The data in the file.

usernamejohn-doe
passwordabc123

The actual code block

(setq my-special-username (first (first data)))
(setq my-special-password (first (second data)))

its expanded contents, as seen with C-c M-b p

(let ((data (quote (("john-doe") ("abc123")))))
(setq my-special-username (first (first data)))
(setq my-special-password (first (second data)))
)