1 @chapter Working with source code or Embedded Source Code
8 @subsection Source Code Block
9 The basic syntax of source code blocks in Org-babel is as follows:
12 #+begin_src language header-arguments
16 - language :: The language of the code in the source code block. Valid
17 values must be members of =org-babel-interpreters=.
18 - header-arguments :: Header arguments control many facets of the
19 evaluation and output of source code blocks. See the [[header-arguments][Header
20 Arguments]] section for a complete review of available header
22 - body :: The source code to be evaluated. An important key-binding
23 is C-c '. This calls =org-edit-src-code=, a function that brings
24 up an edit buffer containing the code using the Emacs major mode
25 appropriate to the language. You can edit your source code block
26 as you regularly would in Emacs.
28 This syntax can be expanded by naming the source code block.
32 #+begin_src language header-arguments
37 - name :: This name is associated with the source code block. This is
38 similar to the =#+tblname= lines that can be used to name tables
39 in Org-mode files. Referencing the name of a source code
40 block makes it possible to evaluate the block from other places in
41 the file, other files, or inside Org-mode tables. It
42 is also possible to pass arguments to a source code block through
43 this =#+source:= line (see [[alternate-argument-syntax][Alternate argument syntax]]).
45 @subsection Library of Babel
46 [[file:library-of-babel.org][Library of Babel]] functions can be called using the following syntax.
49 #+lob: R-plot(data=R-plot-example-data)
53 Keyword aliases are intended to make Org-babel feel natural to
54 programmers fluent in a variety of languages. For example,
56 #+srcname: alias-example
57 #+begin_src emacs-lisp
59 (source function srcname)
63 #+results: alias-example
65 | source | function | srcname |
66 | results | resname | |
68 - =#+srcname:= can be replaced with either of two aliases, =#+source:= or =#+function:=.
69 - =#+results:= can be replaced with its alias, =#+resname:=.
71 When calling Library of Babel functions, as in the following
72 example, there are two acceptable keywords. The =#+lob= call in
73 the example could be replaced with its alias, =#+call=.
75 #+lob: R-plot(data=R-plot-example-data)
83 Org-babel has support for the following languages.
85 | Language | Documentation | Identifier | Requirements |
86 |----------------+-----------------------------+------------+---------------------------------------------|
87 | Asymptote | org-babel-doc-asymptote | asymptote | [[http://asymptote.sourceforge.net/][asymptote]], [[http://asymptote.sourceforge.net/doc/Editing-modes.html][asy-mode]] |
88 | C | [[file:languages/org-babel-doc-C.org][org-babel-doc-C]] | C | none |
89 | Clojure | [[file:languages/org-babel-doc-clojure.org][org-babel-doc-clojure]] | clojure | [[http://clojure.org/][clojure]], [[http://www.emacswiki.org/emacs/clojure-mode.el][clojure-mode]], [[http://common-lisp.net/project/slime/][slime]], [[http://clojure.codestuffs.com/][swank-clojure]] |
90 | css | org-babel-doc-css | css | none |
91 | ditaa | org-babel-doc-ditaa | ditaa | [[http://ditaa.org/ditaa/][ditaa]] (bundled with Org-mode) |
92 | Graphviz | org-babel-doc-dot | dot | [[http://www.graphviz.org/][dot]] |
93 | Emacs Lisp | org-babel-doc-emacs-lisp | emacs-lisp | none |
94 | gnuplot | org-babel-doc-gnuplot | gnuplot | [[http://www.gnuplot.info/][gnuplot]], [[http://cars9.uchicago.edu/~ravel/software/gnuplot-mode.html][gnuplot-mode]] |
95 | Haskell | org-babel-doc-haskell | haskell | [[http://www.haskell.org/][haskell]], [[http://projects.haskell.org/haskellmode-emacs/][haskell-mode]], [[http://www.haskell.org/haskellwiki/Haskell_mode_for_Emacs#inf-haskell.el:_the_best_thing_since_the_breadknife][inf-haskell]], [[http://people.cs.uu.nl/andres/lhs2tex/][lhs2tex]] |
96 | Matlab | [[file:languages/org-babel-doc-octave-matlab.org][org-babel-doc-octave-matlab]] | matlab | matlab, [[http://sourceforge.net/projects/matlab-emacs/][matlab.el]] |
97 | LaTeX | [[file:languages/org-babel-doc-LaTeX.org][org-babel-doc-latex]] | latex | [[http://www.latex-project.org/][latex]], [[http://www.gnu.org/software/auctex/][auctex]], [[http://www.gnu.org/software/auctex/reftex.html][reftex]] |
98 | Objective Caml | org-babel-doc-ocaml | ocaml | [[http://caml.inria.fr/][ocaml]], [[http://www-rocq.inria.fr/~acohen/tuareg/][tuareg-mode]] |
99 | Octave | [[file:languages/org-babel-doc-octave-matlab.org][org-babel-doc-octave-matlab]] | octave | octave |
100 | OZ | [[file:languages/org-babel-doc-oz.org][org-babel-doc-oz]] | oz | [[http://www.mozart-oz.org/][Mozart]] which includes a major mode |
101 | Perl | org-babel-doc-perl | perl | [[http://www.perl.org/][perl]], [[http://www.emacswiki.org/emacs/CPerlMode][cperl-mode]] (optional) |
102 | Python | org-babel-doc-python | python | [[http://www.python.org/][python]], [[https://launchpad.net/python-mode][python-mode]] (optional) |
103 | R | [[file:languages/org-babel-doc-R.org][org-babel-doc-R]] | R | [[http://www.r-project.org/][R]], [[http://ess.r-project.org/][ess-mode]] |
104 | Ruby | org-babel-doc-ruby | ruby | [[http://www.ruby-lang.org/][ruby]], [[http://www.ruby-lang.org/][irb]], [[http://github.com/eschulte/rinari/raw/master/util/ruby-mode.el][ruby-mode]], [[http://github.com/eschulte/rinari/raw/master/util/inf-ruby.el][inf-ruby mode]] |
105 | Sass | org-babel-doc-sass | sass | [[http://sass-lang.com/][sass]], [[http://github.com/nex3/haml/blob/master/extra/sass-mode.el][sass-mode]] |
106 | GNU Screen | [[file:languages/org-babel-doc-screen.org][org-babel-doc-screen]] | screen | [[http://www.gnu.org/software/screen/][screen]], a terminal |
107 | shell | org-babel-doc-sh | sh[fn:1] | a shell |
108 | SQL | org-babel-doc-sql | sql | none |
110 To add support for a particular language to your Org-babel
111 installation first make sure that the requirements of the language
112 are met, then add a line like the following to your Emacs
113 configuration, (replace "identifier" with one of the
114 entries in the Identifier column of the table).
116 (require 'org-babel-identifier)
119 @section Header Arguments
121 :CUSTOM_ID: header-arguments
124 Definitions of all Org-babel header arguments are given [[header-argument-specific-documentation][below]]. In
125 addition, some languages may add their own header arguments. Please
126 see the language-specific documentation for information on
127 language-specific header arguments.
129 @subsection Using Header Arguments
131 The values of header arguments can be set in three different ways,
132 each more specific than the last.
134 @subsubsection System-wide
136 :CUSTOM_ID: system-wide-header-argument
139 System-wide values of header arguments can be specified by
140 customizing the =org-babel-default-header-args= variable:
142 org-babel-default-header-args is a variable defined in `org-babel.el'.
145 (:results . "replace")
152 Default arguments to use when evaluating a source block.
155 For example, the following example could be used to set the default value
156 of =:noweb= header arguments to =yes=. This would have the effect of
157 expanding =:noweb= references by default when evaluating source code blocks.
159 (setq org-babel-default-header-args
160 (cons '(:noweb . "yes")
161 (assq-delete-all :noweb org-babel-default-header-args)))
164 @subsubsection Org-mode Properties
166 Header arguments are also read from [[http://orgmode.org/manual/Properties-and-Columns.html#Properties-and-Columns][Org-mode properties]], which
167 means they can be set on the outline header level. For example, the
168 value of the =:cache= header argument will default to true in all
169 source code blocks under the following example of an Org-mode outline header:
174 :CUSTOM_ID: property-set-header-arguments
177 Properties defined in this way override the properties set in
178 =org-babel-default-header-args=. It is convenient to use the
179 =org-set-property= function bound to =C-c C-x p= to set properties
180 in Org-mode documents.
182 @subsubsection Source Code Block
184 :CUSTOM_ID: single-block-header-arguments
186 The most common way to assign values to header arguments is at the
187 source code block level. This can be done by listing a sequence of
188 header arguments and their values as part of the =#+begin_src=
189 line. Properties set in this way override both the values of
190 =org-babel-default-header-args= and header argument specified as
191 properties. In the following example, the
192 =:results= header argument is set to =silent=, meaning the results
193 of execution will not be inserted in the buffer, and the =:exports=
194 header argument is set to =code=, meaning only the body of the
196 will be preserved on export to HTML or LaTeX.
199 #+begin_src haskell :results silent :exports code
201 fac n = n * fac (n-1)
205 @subsection Specific Header Arguments
207 :CUSTOM_ID: header-argument-specific-documentation
210 @subsubsection =:var=
212 :CUSTOM_ID: header-argument-var
215 The =:var= header argument is used to pass arguments to
216 source code blocks. The specifics of how arguments are included
217 in a source code block are language specific and are
218 addressed in the language-specific documentation. However, the
219 syntax used to specify arguments is the same across all
220 languages. The values passed to arguments can be or
222 - values from org-mode tables
223 - the results of other source code blocks
225 These values can be indexed in a manner similar to arrays -- see
226 [[var-argument-indexing][argument indexing]].
228 The following syntax is used to pass arguments to source code
229 blocks using the =:var= header argument.
235 where =assign= can take one of the following forms
237 - literal value :: either a string ="string"= or a number =9=.
238 - reference :: a table name:
241 #+tblname: example-table
247 #+source: table-length
248 #+begin_src emacs-lisp :var table=example-table
252 #+results: table-length
256 a source code block name, as assigned by =#+srcname:=,
257 followed by parentheses:
260 #+begin_src emacs-lisp :var length=table-length()
268 In addition, an argument can be passed to the source code
269 block referenced by =:var=. The argument is passed within
270 the parentheses following the source code block name:
274 #+begin_src emacs-lisp :var input=8
282 #+begin_src emacs-lisp :var input=double(input=1)
290 **** alternate argument syntax
292 :CUSTOM_ID: alternate-argument-syntax
295 It is also possible to specify arguments in a potentially more
296 natural way using the =#+source:= line of a source code block.
297 As in the following example arguments can be packed inside of
298 parenthesis following the source name.
300 #+source: double(input=0)
301 #+begin_src emacs-lisp
306 **** indexable variable values
308 :CUSTOM_ID: var-argument-indexing
311 It is possible to assign a portion of a value to a
312 variable in a source block. The following example
313 assigns the second and third rows of the table
314 =example-table= to the variable =data=:
317 :var data=example-table[1:2]
320 *Note:* ranges are indexed using the =:= operator.
322 *Note:* indices are 0 based.
324 The following example assigns the second column of the
325 first row of =example-table= to =data=:
328 :var data=example-table[0,1]
331 It is possible to index into the results of source code blocks
332 as well as tables. Any number of dimensions can be indexed.
333 Dimensions are separated from one another by commas.
335 For more information on indexing behavior see the documentation
336 for the =org-babel-ref-index-list= function -- provided below.
339 org-babel-ref-index-list is a Lisp function in `org-babel-ref.el'.
341 (org-babel-ref-index-list INDEX LIS)
343 Return the subset of LIS indexed by INDEX. If INDEX is
344 separated by ,s then each PORTION is assumed to index into the
345 next deepest nesting or dimension. A valid PORTION can consist
346 of either an integer index, or two integers separated by a : in
347 which case the entire range is returned.
350 *Note:* In Emacs, the documentation for any function or variable
351 can be read using the =describe-function= (M-x describe
352 function) and =describe-variable= (M-x describe variable)
353 functions, respectively.
355 @subsubsection =:results=
357 :CUSTOM_ID: header-argument-results
360 There are three types of results header argument:
361 - *collection* header arguments specify how the results should be collected from
362 the source code block;
363 - *type* header arguments specify what type of result the source code block
364 will return -- which has implications for how they will be
365 inserted into the Org-mode buffer; and
366 - *handling* header arguments specify how the results of
367 evaluating the source code block should be handled.
369 *Note:* only one option from each type may be supplied per source code
374 :CUSTOM_ID: header-argument-results-collection
376 The following options are mutually exclusive, and specify how the
377 results should be collected from the source code block.
379 - value :: This is the default. The result is the value
380 of the last statement in the source code block.
381 This header argument places Org-babel in functional
382 mode. Note that in some languages, e.g., python,
383 use of this result type requires that a =return=
384 statement be included in the body of the source code
385 block. E.g., =:results value=.
386 - output :: The result is the collection of everything printed
387 to stdout during the execution of the source code
388 block. This header argument places Org-babel in scripting
389 mode. E.g., =:results output=.
392 The following options are mutually exclusive and specify what
393 type of results the code block will return. By default, results
394 are inserted as either a *table* or *scalar* depending on their
397 - table, vector :: The results should be interpreted as an Org-mode table.
398 If a single value is returned, Org-babel will convert it
399 into a table with one row and one column. E.g., =:results
401 - scalar, verbatim :: The results should be interpreted
402 literally -- meaning they will not be converted into a table.
403 The results will be inserted into the Org-mode buffer as
404 quoted text. E.g., =:results value verbatim=.
405 - file :: The results will be interpreted as the path to a file,
406 and will be inserted into the Org-mode buffer as a file
407 link. E.g., =:results value file=.
408 - raw, org :: The results are interpreted as raw Org-mode code and
409 are inserted directly into the buffer. If the results look
410 like a table they will be aligned as such by Org-mode.
411 E.g., =:results value raw=.
412 - html :: Results are assumed to be HTML and will be enclosed in
413 a =begin_html= block. E.g., =:results value html=.
414 - latex :: Results assumed to be LaTeX and are enclosed in a
415 =begin_latex= block. E.g., =:results value latex=.
416 - code :: Result are assumed to be parseable code and are
417 enclosed in a code block. E.g., =:results value code=.
418 - pp :: The result is converted to pretty-printed code and is
419 enclosed in a code block. This option currently supports
420 Emacs Lisp, python, and ruby. E.g., =:results value pp=.
423 The following results options indicate what Org-babel should do
424 with the results once they are collected.
426 - silent :: The results will be echoed in the minibuffer but
427 will not be inserted into the Org-mode buffer. E.g.,
428 =:results output silent=.
429 - replace :: The default value. The results will be inserted
430 into the Org-mode buffer. E.g., =:results output
433 @subsubsection =:file=
435 :CUSTOM_ID: header-argument-file
438 =:file= is used to specify a path for file output in which case an
439 [[http://orgmode.org/manual/Link-format.html#Link-format][org style]] =file:= link is inserted into the buffer as the
440 result. Common examples are graphical output from [[file:languages/org-babel-doc-R.org][R]], gnuplot,
441 ditaa and [[file:languages/org-babel-doc-LaTeX.org][latex]] blocks.
443 See the [[#header-argument-dir][=:dir= and remote execution]] section for examples.
445 Note that for some languages, including [[file:languages/org-babel-doc-R.org][R]], gnuplot, [[file:languages/org-babel-doc-LaTeX.org][latex]] and
446 ditaa, graphical output is sent to the specified file without the
447 file being referenced explicitly in the code block. See the
448 documentation for the individual languages for details. In
449 contrast, general purpose languages such as python and ruby
450 require that the code explicitly create output corresponding to
451 the path indicated by =:file=.
453 While the =:file= header argument can be used to specify the path
456 @subsubsection =:dir= and remote execution
458 :CUSTOM_ID: header-argument-dir
460 =:dir= specifies the /default directory/ during code block
461 execution. If it is absent, then the directory associated with the
462 current buffer is used. In other words, supplying =:dir path=
463 temporarily has the same effect as changing the current directory
464 with =M-x cd path=, and then not supplying =:dir=. Under the
465 surface, =:dir= simply sets the value of the emacs variable
468 When using =:dir=, you should supply a relative path for [[#header-argument-file][file
469 output]] (e.g. =:file myfile.jpg= or =:file results/myfile.jpg=) in
470 which case that path will be interpreted relative to the default
473 In other words, if you want your plot to go into a folder called
474 Work in your home directory, you could use
477 #+begin_src R :file myplot.png :dir ~/Work
478 matplot(matrix(rnorm(100), 10), type="l")
482 **** Remote execution
483 A directory on a remote machine can be specified using [[http://www.gnu.org/software/tramp/#Filename-Syntax][tramp
484 filename syntax]], in which case the code will be executed on the
485 remote machine[fn:2]. An example is
488 #+begin_src R :file plot.png :dir /dand@@yakuba.princeton.edu:
489 plot(1:10, main=system("hostname", intern=TRUE))
493 Text results will be returned to the local org buffer as normal, and
494 file output will be created on the remote machine with relative paths
495 interpreted relative to the remote directory. An org link to the
496 remote file will be created.
498 So in the above example a plot will be created on the remote machine,
499 and a link of the following form will be inserted in the org buffer:
502 [[file:/scp:dand@@yakuba.princeton.edu:/home/dand/plot.png][plot.png]]
505 Most of this functionality follows immediately from the fact that
506 =:dir= sets the value of the emacs variable =default-directory=,
507 thanks to [[http://www.gnu.org/software/tramp/][tramp]]. Those using XEmacs, or GNU Emacs prior to
508 version 23 may need to install tramp separately in order for the
509 above features to work correctly.
512 - If =:dir= is used in conjunction with =:session=, although it
513 will determine the starting directory for a new session as
514 expected, no attempt is currently made to alter the directory
515 associated with an existing session.
516 - =:dir= should typically not be used to create files during
517 export with =:exports results= or =:exports both=. The reason
518 is that, in order to retain portability of exported material
519 between machines, during export, links inserted into the buffer
520 will *not* be expanded against default directory. Therefore, if
521 default-directory is altered using =:dir=, it it probable that
522 the file will be created in a location to which the link does
524 @subsubsection =:exports=
526 :CUSTOM_ID: header-argument-exports
529 Specify what should be included in HTML or LaTeX exports of the
532 - code :: the default. The body of code is included
533 into the exported file. E.g., =:exports code=.
534 - results :: the result of evaluating the code is included in the
535 exported file. E.g., =:exports results=.
536 - both :: both the code and results are included in the exported
537 file. E.g., =:exports both=.
538 - none :: nothing is included in the exported file. E.g.,
541 @subsubsection =:tangle=
543 :CUSTOM_ID: tangle-header-arguments
546 Specify whether or not the source code block should be included
547 in tangled extraction of source code files.
549 - yes :: the source code block is exported to a source code file
550 named after the basename (name w/o extension) of the
551 Org-mode file. E.g., =:tangle yes=.
552 - no :: the default. The source code block is not
553 exported to a source code file. E.g., =:tangle no=.
554 - other :: Any other string passed to the =:tangle= header argument
555 is interpreted as a file basename to which the block will
556 be exported. E.g., =:tangle basename=.
558 @subsubsection =:session=
560 :CUSTOM_ID: header-argument-session
563 Start a session for an interpreted language where state is
564 preserved. This applies particularly to the supported languages
567 By default, a session is not started.
569 A string passed to the =:session= header argument will give the
570 session a name. This makes it possible to run concurrent
571 sessions for each interpreted language.
573 @subsubsection =:noweb=
575 :CUSTOM_ID: header-argument-noweb
578 Controls the expansion of [[noweb-reference-syntax][noweb syntax]] references in a
579 source code block. This header argument can have one of two
580 values: =yes= or =no=.
581 - =no= :: the default. No [[noweb-reference-syntax][noweb syntax]] specific action is taken
582 on evaluating source code blocks/ However, noweb references
583 will still be expanded during tangling.
584 - =yes= :: all [[noweb-reference-syntax][noweb syntax]] references in the body of the source
585 code block will be expanded before the block is evaluated.
587 **** Noweb Prefix Lines
589 Noweb insertions are now placed behind the line prefix of the
592 This behavior is illustrated in the following example. Because
593 the =<<example>>= noweb reference appears behind the SQL
594 comment syntax, each line of the expanded noweb reference will
597 This source code block:
608 -- multi-line body of example
611 Note that noweb replacement text that does *not* contain any
612 newlines will not be affected by this change, so it is still
613 possible to use inline noweb references.
615 Thanks to Sébastien Vauban for this idea.
617 @subsubsection =:cache=
619 :CUSTOM_ID: header-argument-cache
622 Controls the use of in-buffer caching of source code block
623 results to avoid re-running unchanged source code blocks. This
624 header argument can have one of two values: =yes= or =no=.
625 - =no= :: The default. No caching takes place and the source
626 code block will be run every time it is executed.
627 - =yes= :: every time the source code block is run a sha1 hash of
628 the code and arguments passed to the block will be
629 generated. This hash is packed into the =#+results:= line
630 of the results and will be checked on subsequent executions
631 of the source code block. If the source code block has not
632 changed since the last time it was evaluated, it will not be
637 :CUSTOM_ID: results-specification
640 The way in which results are handled depends on whether a [[header-argument-session][session]]
641 is invoked, as well as on whether
642 [[header-argument-results-collection][=:results value=] or
643 [[header-argument-results-collection][=:results output=]] is used. The following table shows the
646 | | non-session (default) | =:session= |
647 |-------------------+--------------------------+-------------------------------------|
648 | =:results value= | value of last expression | value of last expression |
649 | =:results output= | contents of stdout | concatenation of interpreter output |
651 *Note:* With =:results value=, the result in both =:session= and
652 non-session is returned to Org-mode as a table (a one- or
653 two-dimensional vector of strings or numbers) when appropriate.
656 ***** =:results value=
657 This is the default. Internally, the value is obtained by
658 wrapping the code in a function definition in the external
659 language, and evaluating that function. Therefore, code should be
660 written as if it were the body of such a function. In particular,
661 note that python does not automatically return a value from a
662 function unless a =return= statement is present, and so a
663 'return' statement will usually be required in python.
665 This is the only one of the four evaluation contexts in which the
666 code is automatically wrapped in a function definition.
668 ***** =:results output=
669 The code is passed to the interpreter as an external process, and
670 the contents of the standard output stream are returned as
671 text. (In certain languages this also contains the error output
672 stream; this is an area for future work.)
675 ***** =:results value=
676 The code is passed to the interpreter running as an interactive
677 Emacs inferior process. The result returned is the result of the
678 last evaluation performed by the interpreter. (This is obtained in
679 a language-specific manner: the value of the variable =_= in
680 python and ruby, and the value of =.Last.value= in R).
682 ***** =:results output=
683 The code is passed to the interpreter running as an interactive
684 Emacs inferior process. The result returned is the concatenation
685 of the sequence of (text) output from the interactive
686 interpreter. Notice that this is not necessarily the same as what
687 would be sent to stdout if the same code were passed to a
688 non-interactive interpreter running as an external process. For
689 example, compare the following two blocks:
692 #+begin_src python :results output
703 In non-session mode, the '2' is not printed and does not appear.
705 #+begin_src python :results output :session
717 But in =:session= mode, the interactive interpreter receives input '2'
718 and prints out its value, '2'. (Indeed, the other print statements are
721 @section Noweb Reference Syntax
723 :CUSTOM_ID: noweb-reference-syntax
726 The [[http://www.cs.tufts.edu/~nr/noweb/][Noweb]] Literate Programming system allows named blocks of code to
727 be referenced by using the familiar Noweb syntax:
728 : <<code-block-name>>
730 Noweb references are handled differently during evaluation and
733 When a document is tangled, Noweb references are replaced with the
734 named source code block.
736 When a source code block is evaluated, the action depends upon the
737 value of the =:noweb= header argument. If =:noweb yes=, then a
738 Noweb reference is expanded before evaluation. If =:noweb no=,
739 the default, then the reference is not expanded before
742 *Note:* the default value, =:noweb no=, was chosen to ensure that
743 Org-babel does not break correct code in a language, such as Ruby,
744 where =<<arg>>= is a syntactically valid construct. If =<<arg>>= is
745 not syntactically valid in languages that you use, then please
746 consider [[*System%20wide][setting the default value]].
748 An example that uses the Noweb reference syntax is provided in the
749 [[literate programming example]].
751 @section Key Bindings & Useful Functions
753 Org-babel re-binds many common Org-mode key sequences depending on
754 the context. Within a source-code block the following sequences
756 | =C-c C-c= | [[function-org-babel-execute][org-babel-execute-src-block]] |
757 | =C-c C-o= | [[function-org-babel-open-src-block-result][org-babel-open-src-block-result]] |
758 | =C-up= | [[function-org-babel-load-in-session][org-babel-load-in-session]] |
759 | =M-down= | [[function-org-babel-pop-to-session][org-babel-pop-to-session]] |
761 Org-babel also exposes a number of functions behind the common
762 =org-babel-key-prefix= of =C-c M-b=:
763 #+begin_src emacs-lisp :exports none
765 (list (format "\\C-c \\M-b %s"
767 (format "[[function-%s][%s]]"
768 (cdr binding) (cdr binding))))
769 org-babel-key-bindings)
771 | =C-c M-b t= | [[function-org-babel-tangle][org-babel-tangle]] |
772 | =C-c M-b T= | [[function-org-babel-tangle-file][org-babel-tangle-file]] |
773 | =C-c M-b e= | [[function-org-babel-execute-src-block][org-babel-execute-src-block]] |
774 | =C-c M-b s= | [[function-org-babel-execute-subtree][org-babel-execute-subtree]] |
775 | =C-c M-b b= | [[function-org-babel-execute-buffer][org-babel-execute-buffer]] |
776 | =C-c M-b h= | [[function-org-babel-sha1-hash][org-babel-sha1-hash]] |
777 | =C-c M-b g= | [[function-org-babel-goto-named-source-block][org-babel-goto-named-source-block]] |
778 | =C-c M-b l= | [[function-org-babel-lob-ingest][org-babel-lob-ingest]] |
781 @subsection Functions
782 @subsubsection org-babel-execute-src-block
784 :CUSTOM_ID: function-org-babel-execute-src-block
788 org-babel-execute-src-block is an interactive Lisp function in
791 (org-babel-execute-src-block &optional ARG INFO PARAMS)
793 Execute the current source code block, and insert the results
794 into the buffer. Source code execution and the collection and
795 formatting of results can be controlled through a variety of
798 Optionally supply a value for INFO in the form returned by
799 `org-babel-get-src-block-info'.
801 Optionally supply a value for PARAMS which will be merged with
802 the header arguments specified at the front of the source code
806 @subsubsection org-babel-open-src-block-result
808 :CUSTOM_ID: function-org-babel-open-src-block-result
812 org-babel-open-src-block-result is an interactive Lisp function in
815 (org-babel-open-src-block-result &optional RE-RUN)
817 If `point' is on a src block then open the results of the
818 source code block, otherwise return nil. With optional prefix
819 argument RE-RUN the source-code block is evaluated even if
820 results already exist.
823 @subsubsection org-babel-load-in-session
825 :CUSTOM_ID: function-org-babel-load-in-session
829 org-babel-load-in-session is an interactive Lisp function in
832 (org-babel-load-in-session &optional ARG INFO)
834 Load the body of the current source-code block. Evaluate the
835 header arguments for the source block before entering the
836 session. After loading the body this pops open the session.
841 @subsubsection org-babel-pop-to-session
843 :CUSTOM_ID: function-org-babel-pop-to-session
847 org-babel-pop-to-session is an interactive Lisp function in
850 (org-babel-pop-to-session &optional ARG INFO)
852 Pop to the session of the current source-code block. If
853 called with a prefix argument then evaluate the header arguments
854 for the source block before entering the session. Copy the body
855 of the source block to the kill ring.
860 @subsubsection org-babel-tangle
862 :CUSTOM_ID: function-org-babel-tangle
866 org-babel-tangle is an interactive Lisp function in
867 `org-babel-tangle.el'.
869 It is bound to C-c M-b t.
871 (org-babel-tangle &optional TARGET-FILE LANG)
873 Extract the bodies of all source code blocks from the current
874 file into their own source-specific files. Optional argument
875 TARGET-FILE can be used to specify a default export file for all
876 source blocks. Optional argument LANG can be used to limit the
877 exported source code blocks by language.
880 @subsubsection org-babel-execute-subtree
882 :CUSTOM_ID: function-org-babel-execute-subtree
886 org-babel-execute-subtree is an interactive Lisp function in
889 It is bound to C-c M-b s.
891 (org-babel-execute-subtree &optional ARG)
893 Replace EVAL snippets in the entire subtree.
896 @subsubsection org-babel-execute-buffer
898 :CUSTOM_ID: function-org-babel-execute-buffer
902 org-babel-execute-buffer is an interactive Lisp function in
905 It is bound to C-c M-b b.
907 (org-babel-execute-buffer &optional ARG)
909 Replace EVAL snippets in the entire buffer.
912 @subsubsection org-babel-sha1-hash
914 :CUSTOM_ID: function-org-babel-sha1-hash
918 org-babel-sha1-hash is an interactive Lisp function in `org-babel.el'.
920 It is bound to C-c M-b h.
922 (org-babel-sha1-hash &optional INFO)
927 @subsubsection org-babel-goto-named-source-block
929 :CUSTOM_ID: function-org-babel-goto-named-source-block
933 org-babel-goto-named-source-block is an interactive Lisp function in
936 It is bound to C-c M-b g.
938 (org-babel-goto-named-source-block &optional NAME)
940 Go to a named source-code block.
943 @subsubsection org-babel-lob-ingest
945 :CUSTOM_ID: function-org-babel-lob-ingest
949 org-babel-lob-ingest is an interactive Lisp function in
952 It is bound to C-c M-b l.
954 (org-babel-lob-ingest &optional FILE)
956 Add all source-blocks defined in FILE to `org-babel-library-of-babel'.
959 @section Batch Execution
960 It is possible to call Org-babel functions from the command line.
961 This shell script calls [[function-org-babel-tangle][org-babel-tangle]] on every one of its
964 Be sure to adjust the paths to fit your system.
967 # -*- mode: shell-script -*-
969 # tangle a file with org-babel
974 # wrap each argument in the code required to call tangle on it
976 FILES="$FILES \"$i\""
981 (add-to-list 'load-path (expand-file-name \"~/src/org/lisp/\"))
982 (add-to-list 'load-path (expand-file-name \"~/src/org/contrib/lisp/\"))
983 (require 'org)(require 'org-exp)(require 'org-babel)
985 (find-file (expand-file-name file \"$DIR\"))
987 (kill-buffer)) '($FILES)))"
992 [fn:1] The former use of the =shell= identifier is now deprecated.
994 [fn:2] As long as the interpreter executable is found on the remote
995 machine: see the variable =tramp-remote-path=