Source code can be included in Org mode documents using a ‘src’ block, e.g.:
#+BEGIN_SRC emacs-lisp (defun org-xor (a b) "Exclusive or." (if a (not b) b)) #+END_SRC
Org mode provides a number of features for working with live source code, including editing of code blocks in their native major-mode, evaluation of code blocks, converting code blocks into source files (known as tangling in literate programming), and exporting code blocks and their results in several formats. This functionality was contributed by Eric Schulte and Dan Davison, and was originally named Org-babel.
The following sections describe Org mode’s code block handling facilities.
|• Structure of code blocks:||Code block syntax described|
|• Editing source code:||Language major-mode editing|
|• Exporting code blocks:||Export contents and/or results|
|• Extracting source code:||Create pure source code files|
|• Evaluating code blocks:||Place results of evaluation in the Org mode buffer|
|• Library of Babel:||Use and contribute to a library of useful code blocks|
|• Languages:||List of supported code block languages|
|• Header arguments:||Configure code block functionality|
|• Results of evaluation:||How evaluation results are handled|
|• Noweb reference syntax:||Literate programming in Org mode|
|• Key bindings and useful functions:||Work quickly with code blocks|
|• Batch execution:||Call functions from the command line|