Merge branch 'master' of orgmode.org:org-mode

This commit is contained in:
Carsten Dominik 2011-11-17 18:06:20 +01:00
commit 78f7382879
21 changed files with 705 additions and 423 deletions

View File

@ -22,7 +22,7 @@
A collection of simple utility functions:
#+srcname: echo
#+name: echo
#+begin_src emacs-lisp :var input="echo'd"
input
#+end_src
@ -35,7 +35,7 @@ Read the contents of the file at =file=. The =:results vector= and
=:results scalar= header arguments can be used to read the contents of
file as either a table or a string.
#+srcname: read
#+name: read
#+begin_src emacs-lisp :var file="" :var format=""
(if (string= format "csv")
(with-temp-buffer
@ -49,7 +49,7 @@ file as either a table or a string.
Write =data= to a file at =file=. If =data= is a list, then write it
as a table in traditional Org-mode table syntax.
#+srcname: write
#+name: write
#+begin_src emacs-lisp :var data="" :var file="" :var ext='()
(flet ((echo (r) (if (stringp r) r (format "%S" r))))
(with-temp-file file
@ -67,7 +67,7 @@ as a table in traditional Org-mode table syntax.
Read local or remote file in [[http://www.json.org/][json]] format into emacs-lisp objects.
#+srcname: json
#+name: json
#+begin_src emacs-lisp :var file='() :var url='()
(require 'json)
(cond
@ -96,7 +96,7 @@ The =google= command seems to be throwing "Moved Temporarily" errors
when trying to download textual documents, but this is working fine
for spreadsheets.
#+source: gdoc-read
#+name: gdoc-read
#+begin_src emacs-lisp :var title="example" :var format="csv"
(let* ((file (concat title "." format))
(cmd (format "google docs get --format %S --title %S" format title)))
@ -126,7 +126,7 @@ Write =data= to a google document named =title=. If =data= is tabular
it will be saved to a spreadsheet, otherwise it will be saved as a
normal document.
#+source: gdoc-write
#+name: gdoc-write
#+begin_src emacs-lisp :var title="babel-upload" :var data=fibs(n=10) :results silent
(let* ((format (if (listp data) "csv" "txt"))
(tmp-file (make-temp-file "org-babel-google-doc" nil (concat "." format)))
@ -157,7 +157,7 @@ example usage
Plot column 2 (y axis) against column 1 (x axis). Columns 3 and
beyond, if present, are ignored.
#+srcname: R-plot(data=R-plot-example-data)
#+name: R-plot(data=R-plot-example-data)
#+begin_src R
plot(data)
#+end_src
@ -169,7 +169,7 @@ plot(data)
| 4 | 16 |
| 5 | 25 |
#+lob: R-plot(data=R-plot-example-data)
#+call: R-plot(data=R-plot-example-data)
#+resname: R-plot(data=R-plot-example-data)
: nil
@ -180,7 +180,7 @@ plot(data)
** Headline references
#+source: headline
#+name: headline
#+begin_src emacs-lisp :var headline=top :var file='()
(save-excursion
(when file (get-file-buffer file))
@ -217,7 +217,7 @@ optional.
| env | optional environment, default to "tabular" |
| width | optional width specification string |
#+srcname: booktabs
#+name: booktabs
#+begin_src emacs-lisp :var table='((:head) hline (:body)) :var align='() :var env="tabular" :var width='() :noweb yes :results latex
(flet ((to-tab (tab)
(orgtbl-to-generic
@ -266,7 +266,7 @@ are optional.
| foot | optional "foot" string |
| lastfoot | optional "lastfoot" string |
#+srcname: longtable
#+name: longtable
#+begin_src emacs-lisp :var table='((:table)) :var align='() :var width='() :var hline="\\hline" :var firsthead='() :var head='() :var foot='() :var lastfoot='() :noweb yes :results latex
(org-fill-template
"
@ -314,7 +314,7 @@ span. Note the use of LaTeX, rather than Org-mode, markup.
#+tblname: arguments-notes
| \multicolumn{2}{l}{This is a footnote to the \emph{arguments} table.} |
#+srcname: booktabs-notes
#+name: booktabs-notes
#+begin_src emacs-lisp :var table='((:head) hline (:body)) :var notes='() :var align='() :var env="tabular" :var width='() :var lspace='() :noweb yes :results latex
(flet ((to-tab (tab)
(orgtbl-to-generic
@ -356,7 +356,7 @@ span. Note the use of LaTeX, rather than Org-mode, markup.
| 1 | 2 | 3 |
| 4 | 5 | 6 |
#+srcname: transpose
#+name: transpose
#+begin_src emacs-lisp :var table=transpose-example
(apply #'mapcar* #'list table)
#+end_src
@ -372,7 +372,7 @@ span. Note the use of LaTeX, rather than Org-mode, markup.
| 1 | 2 | 3 |
| a | b | c |
#+source: all-to-string
#+name: all-to-string
#+begin_src emacs-lisp :var tbl='()
(defun all-to-string (tbl)
(if (listp tbl)
@ -387,7 +387,7 @@ span. Note the use of LaTeX, rather than Org-mode, markup.
(mapcar (lambda (row) (mapcar (lambda (cell) (stringp cell)) row)) tbl)
#+end_src
#+results:
#+name:
| nil | nil | nil |
| t | t | t |
@ -395,7 +395,7 @@ span. Note the use of LaTeX, rather than Org-mode, markup.
(mapcar (lambda (row) (mapcar (lambda (cell) (stringp cell)) row)) tbl)
#+end_src
#+results:
#+name:
| t | t | t |
| t | t | t |
@ -412,7 +412,7 @@ export. The function uses the Emacs VC commands to interface to the
local version control system, but has only been tested to work with
Git. 'limit' is currently unsupported.
#+source: vc-log
#+name: vc-log
#+headers: :var limit=-1
#+headers: :var buf=(buffer-name (current-buffer))
#+begin_src emacs-lisp
@ -440,34 +440,34 @@ Git. 'limit' is currently unsupported.
** Trivial python code blocks
#+srcname: python-identity(a=1)
#+name: python-identity(a=1)
#+begin_src python
a
#+end_src
#+srcname: python-add(a=1, b=2)
#+name: python-add(a=1, b=2)
#+begin_src python
a + b
#+end_src
** Arithmetic
#+source: lob-add
#+name: lob-add
#+begin_src emacs-lisp :var a=0 :var b=0
(+ a b)
#+end_src
#+source: lob-minus
#+name: lob-minus
#+begin_src emacs-lisp :var a=0 :var b=0
(- a b)
#+end_src
#+source: lob-times
#+name: lob-times
#+begin_src emacs-lisp :var a=0 :var b=0
(* a b)
#+end_src
#+source: lob-div
#+name: lob-div
#+begin_src emacs-lisp :var a=0 :var b=0
(/ a b)
#+end_src
@ -477,7 +477,7 @@ a + b
The =elispgantt= source block was sent to the mailing list by Eric
Fraga. It was modified slightly by Tom Dye.
#+source: elispgantt
#+name: elispgantt
#+begin_src emacs-lisp :var table=gantttest
(let ((dates "")
(entries (nthcdr 2 table))

View File

@ -5685,7 +5685,7 @@ an item:
@orgcmd{C-c C-d,org-deadline}
Insert @samp{DEADLINE} keyword along with a stamp. The insertion will happen
in the line directly following the headline. Any CLOSED timestamp will be
removed. When called with a prefix arg, an existing deadline will be removed
removed. When called with a prefix arg, an existing deadline will be removed
from the entry. Depending on the variable @code{org-log-redeadline}@footnote{with corresponding
@code{#+STARTUP} keywords @code{logredeadline}, @code{lognoteredeadline},
and @code{nologredeadline}}, a note will be taken when changing an existing
@ -11651,19 +11651,26 @@ The following sections describe Org-mode's code block handling facilities.
@section Structure of code blocks
@cindex code block, structure
@cindex source code, block structure
@cindex #+NAME
@cindex #+BEGIN_SRC
The structure of code blocks is as follows (empty code blocks may be inserted
using Org-mode's @ref{Easy Templates} system):
Live code blocks can be specified with a @samp{src} block or
inline@footnote{Note that @samp{src} blocks may be inserted using Org-mode's
@ref{Easy Templates} system}. The structure of a @samp{src} block is
@example
#+srcname: <name>
#+begin_src <language> <switches> <header arguments>
#+NAME: <name>
#+BEGIN_SRC <language> <switches> <header arguments>
<body>
#+end_src
#+END_SRC
@end example
Switches and header arguments are optional. Code can also be embedded in text
inline using
The @code{#+NAME:} line is optional, and can be used to name the code
block. Live code blocks require that a language be specified on the
@code{#+BEGIN_SRC} line. Switches and header arguments are optional.
@cindex source code, inline
Live code blocks can also be specified inline using
@example
src_<language>@{<body>@}
@ -11676,26 +11683,30 @@ src_<language>[<header arguments>]@{<body>@}
@end example
@table @code
@item <name>
This name is associated with the code block. This is similar to the
@samp{#+tblname} lines that can be used to name tables in Org-mode files.
Referencing the name of a code block makes it possible to evaluate the
block from other places in the file, other files, or from Org-mode table
formulas (see @ref{The spreadsheet}). Names are assumed to be unique by
evaluation functions and the behavior of multiple blocks of the same name is
@item <#+NAME: name>
This line associates a name with the code block. This is similar to the
@code{#+TBLNAME: NAME} lines that can be used to name tables in Org-mode
files. Referencing the name of a code block makes it possible to evaluate
the block from other places in the file, from other files, or from Org-mode
table formulas (see @ref{The spreadsheet}). Names are assumed to be unique
and the behavior of Org-mode when two or more blocks share the same name is
undefined.
@cindex #+NAME
@item <language>
The language of the code in the block.
The language of the code in the block (see @ref{Languages}).
@cindex source code, language
@item <switches>
Optional switches controlling exportation of the code block (see switches discussion in
Optional switches control code block export (see the discussion of switches in
@ref{Literal examples})
@cindex source code, switches
@item <header arguments>
Optional header arguments control many aspects of evaluation, export and
tangling of code blocks. See the @ref{Header arguments}.
tangling of code blocks (see @ref{Header arguments}).
Header arguments can also be set on a per-buffer or per-subtree
basis using properties.
@item source code, header arguments
@item <body>
The source code.
Source code in the specified language.
@end table
@comment node-name, next, previous, up
@ -11744,12 +11755,12 @@ variable @code{org-src-fontify-natively}.
@cindex code block, exporting
@cindex source code, exporting
It is possible to export the @emph{contents} of code blocks, the
@emph{results} of code block evaluation, @emph{neither}, or @emph{both}. For
most languages, the default exports the contents of code blocks. However, for
some languages (e.g.@: @code{ditaa}) the default exports the results of code
block evaluation. For information on exporting code block bodies, see
@ref{Literal examples}.
It is possible to export the @emph{code} of code blocks, the @emph{results}
of code block evaluation, @emph{both} the code and the results of code block
evaluation, or @emph{none}. For most languages, the default exports code.
However, for some languages (e.g.@: @code{ditaa}) the default exports the
results of code block evaluation. For information on exporting code block
bodies, see @ref{Literal examples}.
The @code{:exports} header argument can be used to specify export
behavior:
@ -11827,14 +11838,15 @@ of tangled code files.
@cindex source code, evaluating
Code blocks can be evaluated@footnote{Whenever code is evaluated there is a
potential for that code to do harm. Org-mode provides a number of safeguards
to ensure that it only evaluates code with explicit confirmation from the
user. For information on these safeguards (and on how to disable them) see
@ref{Code evaluation security}.} and the results placed in the Org-mode
buffer. By default, evaluation is only turned on for @code{emacs-lisp} code
blocks, however support exists for evaluating blocks in many languages. See
@ref{Languages} for a list of supported languages. See @ref{Structure of
code blocks} for information on the syntax used to define a code block.
potential for that code to do harm. Org-mode provides safeguards to ensure
that code is only evaluated after explicit confirmation from the user. For
information on these safeguards (and on how to disable them) see @ref{Code
evaluation security}.} and the results of evaluation optionally placed in the
Org-mode buffer. By default, the evaluation facility is only enabled for
Lisp code blocks specified as @code{emacs-lisp}. However, souce code blocks
in many languages can be evaluated within Org-mode (see @ref{Languages} for a
list of supported languages and @ref{Structure of code blocks} for
information on the syntax used to define a code block).
@kindex C-c C-c
There are a number of ways to evaluate code blocks. The simplest is to press
@ -11843,63 +11855,51 @@ There are a number of ways to evaluate code blocks. The simplest is to press
evaluation from the @kbd{C-c C-c} key binding.}. This will call the
@code{org-babel-execute-src-block} function to evaluate the block and insert
its results into the Org-mode buffer.
@cindex #+CALL
It is also possible to evaluate named code blocks from anywhere in an
Org-mode buffer or an Org-mode table. @code{#+call} (or synonymously
@code{#+function} or @code{#+lob}) lines can be used to remotely execute code
blocks located in the current Org-mode buffer or in the ``Library of Babel''
(see @ref{Library of Babel}). These lines use the following syntax to place
a call on a line by itself.
Org-mode buffer or an Org-mode table. Live code blocks located in the current
Org-mode buffer or in the ``Library of Babel'' (see @ref{Library of Babel})
can be executed. Named code blocks can be executed with a separate
@code{#+CALL:} line or inline within a block of text.
The syntax of the @code{#+CALL:} line is
@example
#+call: <name>(<arguments>)
#+call: <name>[<header args>](<arguments>) <header args>
#+CALL: <name>(<arguments>)
#+CALL: <name>[<inside header arguments>](<arguments>) <end header arguments>
@end example
The following syntax can be used to place these calls within a block of
prose.
The syntax for inline evaluation of named code blocks is
@example
...prose... call_<name>(<arguments>) ...prose...
...prose... call_<name>[<header args>](<arguments>)[<header args>] ...prose...
... call_<name>(<arguments>) ...
... call_<name>[<inside header arguments>](<arguments>)[<end header arguments>] ...
@end example
@table @code
@item <name>
The name of the code block to be evaluated.
The name of the code block to be evaluated (see @ref{Structure of code blocks}).
@item <arguments>
Arguments specified in this section will be passed to the code block. These
arguments should relate to @code{:var} header arguments in the called code
block expressed using standard function call syntax. For example if the
original code block named @code{double} has the header argument @code{:var
n=2}, then the call line passing the number four to that block would be
written as @code{#+call: double(n=2)}.
@item <header args>
Header arguments can be placed either inside the call to the code block or at
the end of the line as shown below.
arguments use standard function call syntax, rather than
header argument syntax. For example, a @code{#+CALL:} line that passes the
number four to a code block named @code{double}, which declares the header
argument @code{:var n=2}, would be written as @code{#+CALL: double(n=4)}.
@item <inside header arguments>
Inside header arguments are passed through and applied to the named code
block. These arguments use header argument syntax rather than standard
function call syntax. Inside header arguments affect how the code block is
evaluated. For example, @code{[:results output]} will collect the results of
everything printed to @code{STDOUT} during execution of the code block.
@item <end header arguments>
End header arguments are applied to the calling instance and do not affect
evaluation of the named code block. They affect how the results are
incorporated into the Org-mode buffer and how the call line is exported. For
example, @code{:results html} will insert the results of the call line
evaluation in the Org buffer, wrapped in a @code{BEGIN_HTML:} block.
@example
#+call: code_bloc_name[XXXX](arguments) YYYY
@end example
Header arguments located in these two locations are treated differently.
@table @code
@item XXXX
Those placed in the @code{XXXX} location are passed through and applied to
the code block being called. These header arguments affect how the code
block is evaluated, for example @code{[:results output]} will collect the
results from @code{STDOUT} of the called code block.
@item YYYY
Those placed in the @code{YYYY} location are applied to the call line and do
not affect the code block being called. These header arguments affect how
the results are incorporated into the Org-mode buffer when the call line is
evaluated, and how the call line is exported. For example @code{:results
org} at the end of the call line will insert the results of the call line
inside of an Org-mode block.
@end table
For more examples of passing header arguments to @code{#+call:} lines see
For more examples of passing header arguments to @code{#+CALL:} lines see
@ref{Header arguments in function calls}.
@end table
@ -11909,15 +11909,19 @@ For more examples of passing header arguments to @code{#+call:} lines see
@cindex source code, library
@cindex code block, library
The ``Library of Babel'' is a library of code blocks
that can be called from any Org-mode file. The library is housed in an
Org-mode file located in the @samp{contrib} directory of Org-mode.
Org-mode users can deposit functions they believe to be generally
useful in the library.
The ``Library of Babel'' consists of code blocks that can be called from any
Org-mode file. Code blocks defined in the ``Library of Babel'' can be called
remotely as if they were in the current Org-mode buffer (see @ref{Evaluating
code blocks} for information on the syntax of remote code block evaluation).
The central repository of code blocks in the ``Library of Babel'' is housed
in an Org-mode file located in the @samp{contrib} directory of Org-mode.
Users can add code blocks they believe to be generally useful to their
``Library of Babel.'' The code blocks can be stored in any Org-mode file and
then loaded into the library with @code{org-babel-lob-ingest}.
Code blocks defined in the ``Library of Babel'' can be called remotely as if
they were in the current Org-mode buffer (see @ref{Evaluating code blocks}
for information on the syntax of remote code block evaluation).
@kindex C-c C-v i
Code blocks located in any Org-mode file can be loaded into the ``Library of
@ -12111,7 +12115,7 @@ in Org-mode documents.
The most common way to assign values to header arguments is at the
code block level. This can be done by listing a sequence of header
arguments and their values as part of the @code{#+begin_src} line.
arguments and their values as part of the @code{#+BEGIN_SRC} line.
Properties set in this way override both the values of
@code{org-babel-default-header-args} and header arguments specified as
properties. In the following example, the @code{:results} header argument
@ -12121,28 +12125,30 @@ inserted in the buffer, and the @code{:exports} header argument is set to
preserved on export to HTML or LaTeX.
@example
#+source: factorial
#+begin_src haskell :results silent :exports code :var n=0
#+NAME: factorial
#+BEGIN_SRC haskell :results silent :exports code :var n=0
fac 0 = 1
fac n = n * fac (n-1)
#+end_src
#+END_SRC
@end example
Similarly, it is possible to set header arguments for inline code blocks:
Similarly, it is possible to set header arguments for inline code blocks
@example
src_haskell[:exports both]@{fac 5@}
@end example
Code block header arguments can span multiple lines using =#+header:= or
=#+headers:= lines preceding a code block or nested in between the name and
body of a named code block.
Code block header arguments can span multiple lines using @code{#+HEADER:} or
@code{#+HEADERS:} lines preceding a code block or nested between the
@code{#+NAME:} line and the @code{#+BEGIN_SRC} line of a named code block.
@cindex #+HEADER:
@cindex #+HEADERS:
Multi-line header arguments on an un-named code block:
@example
#+headers: :var data1=1
#+begin_src emacs-lisp :var data2=2
#+HEADERS: :var data1=1
#+BEGIN_SRC emacs-lisp :var data2=2
(message "data1:%S, data2:%S" data1 data2)
#+end_src
#+END_SRC
#+results:
: data1:1, data2:2
@ -12150,11 +12156,11 @@ Multi-line header arguments on an un-named code block:
Multi-line header arguments on a named code block:
@example
#+source: named-block
#+header: :var data=2
#+begin_src emacs-lisp
#+NAME: named-block
#+HEADER: :var data=2
#+BEGIN_SRC emacs-lisp
(message "data:%S" data)
#+end_src
#+END_SRC
#+results: named-block
: data:2
@ -12165,20 +12171,20 @@ Multi-line header arguments on a named code block:
@subsubheading Header arguments in function calls
At the most specific level, header arguments for ``Library of Babel'' or
function call lines can be set as shown in the two examples below. For more
information on the structure of @code{#+call:} lines see @ref{Evaluating code
@code{#+CALL:} lines can be set as shown in the two examples below. For more
information on the structure of @code{#+CALL:} lines see @ref{Evaluating code
blocks}.
The following will apply the @code{:exports results} header argument to the
evaluation of the @code{#+call:} line.
evaluation of the @code{#+CALL:} line.
@example
#+call: factorial(n=5) :exports results
#+CALL: factorial(n=5) :exports results
@end example
The following will apply the @code{:session special} header argument to the
evaluation of the @code{factorial} code block.
@example
#+call: factorial[:session special](n=5)
#+CALL: factorial[:session special](n=5)
@end example
@node Specific header arguments, , Using header arguments, Header arguments
@ -12223,14 +12229,18 @@ Additional header arguments are defined on a language-specific basis, see
The @code{:var} header argument is used to pass arguments to code blocks.
The specifics of how arguments are included in a code block vary by language;
these are addressed in the language-specific documentation. However, the
syntax used to specify arguments is the same across all languages. The
values passed to arguments can be literal values, values from org-mode tables
and literal example blocks, the results of other code blocks, or Emacs Lisp
code---see the ``Emacs Lisp evaluation of variables'' heading below. In
every case, variables require a default value when they are declared.
syntax used to specify arguments is the same across all languages. In every
case, variables require a default value when they are declared.
These values can be indexed in a manner similar to arrays---see the
``indexable variable values'' heading below.
The values passed to arguments can either be literal values, references, or
Emacs Lisp code (see @ref{var, Emacs Lisp evaluation of variables}). References
include anything in the Org-mode file that takes a @code{#+NAME:},
@code{#+TBLNAME:}, or @code{#+RESULTS:} line. This includes tables, lists,
@code{#+BEGIN_EXAMPLE} blocks, other code blocks, and the results of other
code blocks.
Argument values can be indexed in a manner similar to arrays (see @ref{var,
Indexable variable values}).
The following syntax is used to pass arguments to code blocks using the
@code{:var} header argument.
@ -12239,76 +12249,135 @@ The following syntax is used to pass arguments to code blocks using the
:var name=assign
@end example
where @code{assign} can take one of the following forms
The argument, @code{assign}, can either be a literal value, such as a string
@samp{"string"} or a number @samp{9}, or a reference to a table, a list, a
literal example, another code block (with or without arguments), or the
results of evaluating another code block.
@itemize @bullet
@item literal value
either a string @code{"string"} or a number @code{9}.
@item reference
a table name:
Here are examples of passing values by reference:
@table @dfn
@item table
an Org mode table named with either a @code{#+NAME:} or @code{#+TBLNAME:} line
@example
#+tblname: example-table
#+TBLNAME: example-table
| 1 |
| 2 |
| 3 |
| 4 |
#+source: table-length
#+begin_src emacs-lisp :var table=example-table
#+NAME: table-length
#+BEGIN_SRC emacs-lisp :var table=example-table
(length table)
#+end_src
#+END_SRC
#+results: table-length
: 4
@end example
a code block name, as assigned by @code{#+srcname:}, followed by
parentheses:
@item list
a simple list named with a @code{#+NAME:} line (note that nesting is not
carried through to the source code block)
@example
#+begin_src emacs-lisp :var length=table-length()
#+NAME: example-list
- simple
- not
- nested
- list
#+BEGIN_SRC emacs-lisp :var x=example-list
(print x)
#+END_SRC
#+results:
| simple | list |
@end example
@item code block without arguments
a code block name (from the example above), as assigned by @code{#+NAME:},
followed by parentheses
@example
#+BEGIN_SRC emacs-lisp :var length=table-length()
(* 2 length)
#+end_src
#+END_SRC
#+results:
: 8
@end example
In addition, an argument can be passed to the code block referenced
by @code{:var}. The argument is passed within the parentheses following the
code block name:
@item code block with arguments
a code block name, as assigned by @code{#+NAME:}, followed by parentheses and
optional arguments passed within the parentheses following the
code block name using standard function call syntax
@example
#+source: double
#+begin_src emacs-lisp :var input=8
#+NAME: double
#+BEGIN_SRC emacs-lisp :var input=8
(* 2 input)
#+end_src
#+END_SRC
#+results: double
: 16
#+source: squared
#+begin_src emacs-lisp :var input=double(input=1)
#+NAME: squared
#+BEGIN_SRC emacs-lisp :var input=double(input=1)
(* input input)
#+end_src
#+END_SRC
#+results: squared
: 4
@end example
@end itemize
@item literal example
a literal example block named with a @code{#+NAME:} line
@example
#+NAME: literal-example
#+BEGIN_EXAMPLE
A literal example
on two lines
#+END_EXAMPLE
#+NAME: read-literal-example
#+BEGIN_SRC emacs-lisp :var x=literal-example
(concatenate 'string x " for you.")
#+END_SRC
#+results: read-literal-example
: A literal example
: on two lines for you.
@end example
@item results block
named results blocks, such as the results of the previous example, are passed
intact
@example
#+BEGIN_SRC emacs-lisp :var x=read-literal-example
(concatenate 'string x " Again.")
#+END_SRC
#+results:
: A literal example
: on two lines for you. Again.
@end example
@end table
@subsubheading Alternate argument syntax
It is also possible to specify arguments in a potentially more natural way
using the @code{#+source:} line of a code block. As in the following
example arguments can be packed inside of parenthesis, separated by commas,
using the @code{#+NAME:} line of a code block. As in the following
example, arguments can be packed inside of parentheses, separated by commas,
following the source name.
@example
#+source: double(input=0, x=2)
#+begin_src emacs-lisp
#+NAME: double(input=0, x=2)
#+BEGIN_SRC emacs-lisp
(* 2 (+ input x))
#+end_src
#+END_SRC
@end example
@subsubheading Indexable variable values
@ -12322,15 +12391,15 @@ following example assigns the last cell of the first row the table
@code{example-table} to the variable @code{data}:
@example
#+results: example-table
#+NAME: example-table
| 1 | a |
| 2 | b |
| 3 | c |
| 4 | d |
#+begin_src emacs-lisp :var data=example-table[0,-1]
#+BEGIN_SRC emacs-lisp :var data=example-table[0,-1]
data
#+end_src
#+END_SRC
#+results:
: a
@ -12342,16 +12411,16 @@ example the following assigns the middle three rows of @code{example-table}
to @code{data}.
@example
#+results: example-table
#+NAME: example-table
| 1 | a |
| 2 | b |
| 3 | c |
| 4 | d |
| 5 | 3 |
#+begin_src emacs-lisp :var data=example-table[1:3]
#+BEGIN_SRC emacs-lisp :var data=example-table[1:3]
data
#+end_src
#+END_SRC
#+results:
| 2 | b |
@ -12365,15 +12434,15 @@ interpreted to mean the entire range and as such are equivalent to
column is referenced.
@example
#+results: example-table
#+NAME: example-table
| 1 | a |
| 2 | b |
| 3 | c |
| 4 | d |
#+begin_src emacs-lisp :var data=example-table[,0]
#+BEGIN_SRC emacs-lisp :var data=example-table[,0]
data
#+end_src
#+END_SRC
#+results:
| 1 | 2 | 3 | 4 |
@ -12384,16 +12453,16 @@ Any number of dimensions can be indexed. Dimensions are separated from one
another by commas, as shown in the following example.
@example
#+source: 3D
#+begin_src emacs-lisp
#+NAME: 3D
#+BEGIN_SRC emacs-lisp
'(((1 2 3) (4 5 6) (7 8 9))
((10 11 12) (13 14 15) (16 17 18))
((19 20 21) (22 23 24) (25 26 27)))
#+end_src
#+END_SRC
#+begin_src emacs-lisp :var data=3D[1,,1]
#+BEGIN_SRC emacs-lisp :var data=3D[1,,1]
data
#+end_src
#+END_SRC
#+results:
| 11 | 14 | 17 |
@ -12402,31 +12471,31 @@ another by commas, as shown in the following example.
@subsubheading Emacs Lisp evaluation of variables
Emacs lisp code can be used to initialize variable values. When a variable
value starts with @code{(}, @code{[}, @code{'} or @code{`} it will be evaluated as
Emacs Lisp and the result of the evaluation will be assigned as the variable
value. The following example demonstrates use of this evaluation to reliably
pass the file-name of the org-mode buffer to a code block---note that
evaluation of header arguments is guaranteed to take place in the original
org-mode file, while there is no such guarantee for evaluation of the code
block body.
value starts with @code{(}, @code{[}, @code{'} or @code{`} it will be
evaluated as Emacs Lisp and the result of the evaluation will be assigned as
the variable value. The following example demonstrates use of this
evaluation to reliably pass the file-name of the org-mode buffer to a code
block---note that evaluation of header arguments is guaranteed to take place
in the original Org-mode file, while there is no such guarantee for
evaluation of the code block body.
@example
#+begin_src sh :var filename=(buffer-file-name) :exports both
#+BEGIN_SRC sh :var filename=(buffer-file-name) :exports both
wc -w $filename
#+end_src
#+END_SRC
@end example
Note that values read from tables and lists will not be evaluated as
Emacs Lisp, as shown in the following example.
@example
#+results: table
#+NAME: table
| (a b c) |
#+headers: :var data=table[0,0]
#+begin_src perl
#+HEADERS: :var data=table[0,0]
#+BEGIN_SRC perl
$data
#+end_src
#+END_SRC
#+results:
: (a b c)
@ -12569,9 +12638,9 @@ In other words, if you want your plot to go into a folder called @file{Work}
in your home directory, you could use
@example
#+begin_src R :file myplot.png :dir ~/Work
#+BEGIN_SRC R :file myplot.png :dir ~/Work
matplot(matrix(rnorm(100), 10), type="l")
#+end_src
#+END_SRC
@end example
@subsubheading Remote execution
@ -12579,9 +12648,9 @@ A directory on a remote machine can be specified using tramp file syntax, in
which case the code will be evaluated on the remote machine. An example is
@example
#+begin_src R :file plot.png :dir /dand@@yakuba.princeton.edu:
#+BEGIN_SRC R :file plot.png :dir /dand@@yakuba.princeton.edu:
plot(1:10, main=system("hostname", intern=TRUE))
#+end_src
#+END_SRC
@end example
Text results will be returned to the local Org-mode buffer as usual, and file
@ -12612,7 +12681,7 @@ currently made to alter the directory associated with an existing session.
@code{:dir} should typically not be used to create files during export with
@code{:exports results} or @code{:exports both}. The reason is that, in order
to retain portability of exported material between machines, during export
links inserted into the buffer will *not* be expanded against @code{default
links inserted into the buffer will @emph{not} be expanded against @code{default
directory}. Therefore, if @code{default-directory} is altered using
@code{:dir}, it is probable that the file will be created in a location to
which the link does not point.
@ -12786,33 +12855,33 @@ following Org-mode file, the bodies of code blocks will be concatenated into
the resulting pure code file.
@example
#+begin_src sh :tangle yes :noweb yes :shebang #!/bin/sh
#+BEGIN_SRC sh :tangle yes :noweb yes :shebang #!/bin/sh
<<fullest-disk>>
#+end_src
#+END_SRC
* the mount point of the fullest disk
:PROPERTIES:
:noweb-ref: fullest-disk
:END:
** query all mounted disks
#+begin_src sh
#+BEGIN_SRC sh
df \
#+end_src
#+END_SRC
** strip the header row
#+begin_src sh
#+BEGIN_SRC sh
|sed '1d' \
#+end_src
#+END_SRC
** sort by the percent full
#+begin_src sh
#+BEGIN_SRC sh
|awk '@{print $5 " " $6@}'|sort -n |tail -1 \
#+end_src
#+END_SRC
** extract the mount point
#+begin_src sh
#+BEGIN_SRC sh
|awk '@{print $2@}'
#+end_src
#+END_SRC
@end example
@node cache, sep, noweb-ref, Specific header arguments
@ -12842,18 +12911,18 @@ invalidated and the code block is re-run. In the following example,
changed since it was last run.
@example
#+srcname: random
#+begin_src R :cache yes
#+NAME: random
#+BEGIN_SRC R :cache yes
runif(1)
#+end_src
#+END_SRC
#+results[a2a72cd647ad44515fab62e144796432793d68e1]: random
0.4659510825295
#+srcname: caller
#+begin_src emacs-lisp :var x=random :cache yes
#+NAME: caller
#+BEGIN_SRC emacs-lisp :var x=random :cache yes
x
#+end_src
#+END_SRC
#+results[bec9c8724e397d5df3b696502df3ed7892fc4f5f]: caller
0.254227238707244
@ -12887,17 +12956,17 @@ variable and raises an error. Setting @code{:hlines no} or relying on the
default value yields the following results.
@example
#+tblname: many-cols
#+TBLNAME: many-cols
| a | b | c |
|---+---+---|
| d | e | f |
|---+---+---|
| g | h | i |
#+source: echo-table
#+begin_src python :var tab=many-cols
#+NAME: echo-table
#+BEGIN_SRC python :var tab=many-cols
return tab
#+end_src
#+END_SRC
#+results: echo-table
| a | b | c |
@ -12909,17 +12978,17 @@ default value yields the following results.
Leaves hlines in the table. Setting @code{:hlines yes} has this effect.
@example
#+tblname: many-cols
#+TBLNAME: many-cols
| a | b | c |
|---+---+---|
| d | e | f |
|---+---+---|
| g | h | i |
#+source: echo-table
#+begin_src python :var tab=many-cols :hlines yes
#+NAME: echo-table
#+BEGIN_SRC python :var tab=many-cols :hlines yes
return tab
#+end_src
#+END_SRC
#+results: echo-table
| a | b | c |
@ -12944,16 +13013,16 @@ names will be removed from the table before
processing, then reapplied to the results.
@example
#+tblname: less-cols
#+TBLNAME: less-cols
| a |
|---|
| b |
| c |
#+srcname: echo-table-again
#+begin_src python :var tab=less-cols
#+NAME: echo-table-again
#+BEGIN_SRC python :var tab=less-cols
return [[val + '*' for val in row] for row in tab]
#+end_src
#+END_SRC
#+results: echo-table-again
| a |
@ -12989,14 +13058,14 @@ The first column of the table is removed from the table before processing,
and is then reapplied to the results.
@example
#+tblname: with-rownames
#+TBLNAME: with-rownames
| one | 1 | 2 | 3 | 4 | 5 |
| two | 6 | 7 | 8 | 9 | 10 |
#+srcname: echo-table-once-again
#+begin_src python :var tab=with-rownames :rownames yes
#+NAME: echo-table-once-again
#+BEGIN_SRC python :var tab=with-rownames :rownames yes
return [[val + 10 for val in row] for row in tab]
#+end_src
#+END_SRC
#+results: echo-table-once-again
| one | 11 | 12 | 13 | 14 | 15 |
@ -13093,26 +13162,26 @@ were passed to a non-interactive interpreter running as an external
process. For example, compare the following two blocks:
@example
#+begin_src python :results output
#+BEGIN_SRC python :results output
print "hello"
2
print "bye"
#+end_src
#+END_SRC
#+resname:
#+results:
: hello
: bye
@end example
In non-session mode, the `2' is not printed and does not appear.
@example
#+begin_src python :results output :session
#+BEGIN_SRC python :results output :session
print "hello"
2
print "bye"
#+end_src
#+END_SRC
#+resname:
#+results:
: hello
: 2
: bye

View File

@ -147,7 +147,7 @@ options and are taken from `org-babel-default-inline-header-args'."
(forward-char 2)))))))))
(defun org-exp-res/src-name-cleanup ()
"Clean up #+results and #+srcname lines for export.
"Clean up #+results and #+name lines for export.
This function should only be called after all block processing
has taken place."
(interactive)
@ -166,8 +166,7 @@ has taken place."
Example and verbatim code include escaped portions of
an org-mode buffer code that should be treated as normal
org-mode text."
(or (org-in-indented-comment-line)
(save-match-data
(or (save-match-data
(save-excursion
(goto-char (point-at-bol))
(looking-at "[ \t]*:[ \t]")))

View File

@ -78,7 +78,7 @@ current directory string."
(if (member "output" (cdr (assoc :result-params params)))
(car result)
(condition-case nil
(read (org-bable-lisp-vector-to-list (cadr result)))
(read (org-babel-lisp-vector-to-list (cadr result)))
(error (cadr result)))))
(with-temp-buffer
(insert (org-babel-expand-body:lisp body params))
@ -96,7 +96,7 @@ current directory string."
(org-babel-pick-name (cdr (assoc :rowname-names params))
(cdr (assoc :rownames params)))))
(defun org-bable-lisp-vector-to-list (results)
(defun org-babel-lisp-vector-to-list (results)
;; TODO: better would be to replace #(...) with [...]
(replace-regexp-in-string "#(" "(" results))

View File

@ -28,6 +28,8 @@
(require 'ob)
(require 'ob-table)
(declare-function org-babel-in-example-or-verbatim "ob-exp" nil)
(defvar org-babel-library-of-babel nil
"Library of source-code blocks.
This is an association list. Populate the library by adding
@ -61,24 +63,15 @@ To add files to this list use the `org-babel-lob-ingest' command."
lob-ingest-count (if (> lob-ingest-count 1) "s" ""))
lob-ingest-count))
(defconst org-babel-lob-call-aliases '("lob" "call")
"Aliases to call a source block function.
If you change the value of this variable then your files may
become unusable by other org-babel users, and vice versa.")
(defconst org-babel-block-lob-one-liner-regexp
(concat
"^\\([ \t]*\\)#\\+\\(?:"
(mapconcat #'regexp-quote org-babel-lob-call-aliases "\\|")
"\\):[ \t]+\\([^\(\)\n]+?\\)\\(\\[\\(.*\\)\\]\\|\\(\\)\\)"
"^\\([ \t]*\\)#\\+call:[ \t]+\\([^\(\)\n]+?\\)\\(\\[\\(.*\\)\\]\\|\\(\\)\\)"
"\(\\([^\n]*\\)\)\\(\\[.+\\]\\|\\)[ \t]*\\(\\([^\n]*\\)\\)?")
"Regexp to match non-inline calls to predefined source block functions.")
(defconst org-babel-inline-lob-one-liner-regexp
(concat
"\\([^\n]*\\)\\(?:"
(mapconcat #'regexp-quote org-babel-lob-call-aliases "\\|")
"\\)_\\([^\(\)\n]+?\\)\\(\\[\\(.*\\)\\]\\|\\(\\)\\)"
"\\([^\n]*\\)call_\\([^\(\)\n]+?\\)\\(\\[\\(.*\\)\\]\\|\\(\\)\\)"
"\(\\([^\n]*\\)\)\\(\\[\\(.*?\\)\\]\\)?")
"Regexp to match inline calls to predefined source block functions.")

View File

@ -148,21 +148,19 @@ the variable."
(save-restriction
(widen)
(goto-char (point-min))
(if (let* ((rx (regexp-quote ref))
(res-rx (concat org-babel-result-regexp rx "[ \t]*.*$"))
(src-rx (concat org-babel-src-name-regexp
rx "\\(\(.*\)\\)?" "[ \t]*$")))
(if (let ((src-rx (org-babel-named-src-block-regexp-for-name ref))
(res-rx (org-babel-named-data-regexp-for-name ref)))
;; goto ref in the current buffer
(or (and (not args)
(or (re-search-forward res-rx nil t)
(re-search-backward res-rx nil t)))
(re-search-forward src-rx nil t)
(re-search-backward src-rx nil t)
;; check for local or global headlines by id
(setq id (org-babel-ref-goto-headline-id ref))
;; check the Library of Babel
(setq lob-info (cdr (assoc (intern ref)
org-babel-library-of-babel)))))
(or
;; check for code blocks
(re-search-forward src-rx nil t)
;; check for named data
(re-search-forward res-rx nil t)
;; check for local or global headlines by id
(setq id (org-babel-ref-goto-headline-id ref))
;; check the Library of Babel
(setq lob-info (cdr (assoc (intern ref)
org-babel-library-of-babel)))))
(unless (or lob-info id) (goto-char (match-beginning 0)))
;; ;; TODO: allow searching for names in other buffers
;; (setq id-loc (org-id-find ref 'marker)
@ -173,6 +171,12 @@ the variable."
(cond
(lob-info (setq type 'lob))
(id (setq type 'id))
((and (looking-at org-babel-src-name-regexp)
(save-excursion
(forward-line 1)
(or (looking-at org-babel-src-block-regexp)
(looking-at org-babel-multi-line-header-regexp))))
(setq type 'source-block))
(t (while (not (setq type (org-babel-ref-at-ref-p)))
(forward-line 1)
(beginning-of-line)

View File

@ -30,7 +30,7 @@
;; (defun fibbd (n) (if (< n 2) 1 (+ (fibbd (- n 1)) (fibbd (- n 2)))))
;; #+end_src
;; #+srcname: fibbd
;; #+name: fibbd
;; #+begin_src emacs-lisp :var n=2 :results silent
;; (fibbd n)
;; #+end_src

View File

@ -114,7 +114,7 @@ remove code block execution from the C-c C-c keybinding."
:type 'boolean)
(defvar org-babel-src-name-regexp
"^[ \t]*#\\+\\(srcname\\|source\\|function\\):[ \t]*"
"^[ \t]*#\\+name:[ \t]*"
"Regular expression used to match a source name line.")
(defvar org-babel-multi-line-header-regexp
@ -217,8 +217,8 @@ Returns a list
(nth 2 info)
(org-babel-parse-header-arguments (match-string 1)))))
(when (looking-at org-babel-src-name-w-name-regexp)
(setq name (org-babel-clean-text-properties (match-string 4)))
(when (match-string 6)
(setq name (org-babel-clean-text-properties (match-string 3)))
(when (and (match-string 5) (> (length (match-string 5)) 0))
(setf (nth 2 info) ;; merge functional-syntax vars and header-args
(org-babel-merge-params
(mapcar
@ -230,7 +230,7 @@ Returns a list
(error
"variable \"%s\"%s must be assigned a default value"
var (if name (format " in block \"%s\"" name) ""))))
(org-babel-ref-split-args (match-string 6))))
(org-babel-ref-split-args (match-string 5))))
(nth 2 info))))))
;; inline source block
(when (org-babel-get-inline-src-block-matches)
@ -397,7 +397,7 @@ specific header arguments as well.")
'((:session . "none") (:results . "replace") (:exports . "results"))
"Default arguments to use when evaluating an inline source block.")
(defvar org-babel-data-names '("TBLNAME" "RESNAME" "RESULTS" "DATA"))
(defvar org-babel-data-names '("TBLNAME" "RESULTS" "NAME"))
(defvar org-babel-result-regexp
(concat "^[ \t]*#\\+"
@ -430,11 +430,17 @@ can not be resolved.")
(defvar org-babel-after-execute-hook nil
"Hook for functions to be called after `org-babel-execute-src-block'")
(defun org-babel-named-src-block-regexp-for-name (name)
"This generates a regexp used to match a src block named NAME."
(concat org-babel-src-name-regexp (regexp-quote name) "[ \t\n]*"
(concat org-babel-src-name-regexp (regexp-quote name)
"\\([ \t]\\|$\\|(\\)" ".*[\r\n]"
(substring org-babel-src-block-regexp 1)))
(defun org-babel-named-data-regexp-for-name (name)
"This generates a regexp used to match data named NAME."
(concat org-babel-result-regexp (regexp-quote name) "\\([ \t]\\|$\\)"))
;;; functions
(defvar call-process-region)
;;;###autoload
@ -1121,17 +1127,24 @@ instances of \"[ \t]:\" set ALTS to '((32 9) . 58)."
(flet ((matches (ch spec) (or (and (numberp spec) (= spec ch))
(member ch spec)))
(matched (ch last)
(and (matches ch (cdr alts))
(matches last (car alts)))))
(let ((balance 0) (partial nil) (lst nil) (last 0))
(mapc (lambda (ch) ; split on [] or () balanced instances of [ \t]:
(if (consp alts)
(and (matches ch (cdr alts))
(matches last (car alts)))
(matches ch alts))))
(let ((balance 0) (quote nil) (partial nil) (lst nil) (last 0))
(mapc (lambda (ch) ; split on [], (), "" balanced instances of [ \t]:
(setq balance (+ balance
(cond ((or (equal 91 ch) (equal 40 ch)) 1)
((or (equal 93 ch) (equal 41 ch)) -1)
(t 0))))
(when (and (equal 34 ch) (not (equal 92 last)))
(setq quote (not quote)))
(setq partial (cons ch partial))
(when (and (= balance 0) (matched ch last))
(setq lst (cons (apply #'string (nreverse (cddr partial)))
(when (and (= balance 0) (not quote) (matched ch last))
(setq lst (cons (apply #'string (nreverse
(if (consp alts)
(cddr partial)
(cdr partial))))
lst))
(setq partial nil))
(setq last ch))
@ -1166,23 +1179,23 @@ shown below.
(mapc (lambda (pair)
(if (eq (car pair) :var)
(mapcar (lambda (v) (push (cons :var (org-babel-trim v)) results))
(org-babel-balanced-split (cdr pair) '(44 . (32 9))))
(org-babel-balanced-split (cdr pair) 32))
(push pair results)))
header-arguments)
(nreverse results)))
(defun org-babel-process-params (params)
"Expand variables in PARAMS and add summary parameters."
(let* ((vars-and-names (if (and (assoc :colname-names params)
(let* ((processed-vars (mapcar (lambda (el)
(if (consp (cdr el))
(cdr el)
(org-babel-ref-parse (cdr el))))
(org-babel-get-header params :var)))
(vars-and-names (if (and (assoc :colname-names params)
(assoc :rowname-names params))
(list (mapcar #'cdr
(org-babel-get-header params :var)))
(list processed-vars)
(org-babel-disassemble-tables
(mapcar (lambda (el)
(if (consp (cdr el))
(cdr el)
(org-babel-ref-parse (cdr el))))
(org-babel-get-header params :var))
processed-vars
(cdr (assoc :hlines params))
(cdr (assoc :colnames params))
(cdr (assoc :rownames params)))))
@ -1367,7 +1380,7 @@ org-babel-named-src-block-regexp."
(regexp (org-babel-named-src-block-regexp-for-name name)) msg)
(goto-char (point-min))
(when (or (re-search-forward regexp nil t)
(re-search-backward regexp nil t))
(re-search-backward regexp nil t))
(match-beginning 0)))))
(defun org-babel-src-block-names (&optional file)
@ -1376,7 +1389,7 @@ org-babel-named-src-block-regexp."
(when file (find-file file)) (goto-char (point-min))
(let (names)
(while (re-search-forward org-babel-src-name-w-name-regexp nil t)
(setq names (cons (match-string 4) names)))
(setq names (cons (match-string 3) names)))
names)))
;;;###autoload
@ -1392,16 +1405,21 @@ org-babel-named-src-block-regexp."
(progn (goto-char point) (org-show-context))
(message "result '%s' not found in this buffer" name))))
(defun org-babel-find-named-result (name)
(defun org-babel-find-named-result (name &optional point)
"Find a named result.
Return the location of the result named NAME in the current
buffer or nil if no such result exists."
(save-excursion
(goto-char (point-min))
(when (re-search-forward
(concat org-babel-result-regexp
"[ \t]" (regexp-quote name) "[ \t\n\f\v\r]") nil t)
(beginning-of-line 0) (point))))
(goto-char (or point (point-min)))
(catch 'is-a-code-block
(when (re-search-forward
(concat org-babel-result-regexp
"[ \t]" (regexp-quote name) "[ \t\n\f\v\r]") nil t)
(when (and (string= "name" (downcase (match-string 1)))
(or (looking-at org-babel-src-block-regexp)
(looking-at org-babel-multi-line-header-regexp)))
(throw 'is-a-code-block (org-babel-find-named-result name (point))))
(beginning-of-line 0) (point)))))
(defun org-babel-result-names (&optional file)
"Returns the names of results in FILE or the current buffer."
@ -1730,42 +1748,45 @@ code ---- the results are extracted in the syntax of the source
((member "prepend" result-params)))) ; already there
(setq results-switches
(if results-switches (concat " " results-switches) ""))
;; insert results based on type
(cond
;; do nothing for an empty result
((= (length result) 0))
;; insert a list if preferred
((member "list" result-params)
(insert
(org-babel-trim
(org-list-to-generic
(cons 'unordered
(mapcar
(lambda (el) (list nil (if (stringp el) el (format "%S" el))))
(if (listp result) result (list result))))
'(:splicep nil :istart "- " :iend "\n")))
"\n"))
;; assume the result is a table if it's not a string
((not (stringp result))
(goto-char beg)
(insert (concat (orgtbl-to-orgtbl
(if (or (eq 'hline (car result))
(and (listp (car result))
(listp (cdr (car result)))))
result (list result))
'(:fmt (lambda (cell) (format "%s" cell)))) "\n"))
(goto-char beg) (when (org-at-table-p) (org-table-align)))
((member "file" result-params)
(when inlinep (goto-char inlinep))
(insert result))
(t (goto-char beg) (insert result)))
(when (listp result) (goto-char (org-table-end)))
(setq end (point-marker))
;; possibly wrap result
(flet ((wrap (start finish)
(goto-char beg) (insert (concat start "\n"))
(goto-char end) (insert (concat finish "\n"))
(setq end (point-marker))))
(setq end (point-marker)))
(proper-list-p (it) (and (listp it) (null (cdr (last it))))))
;; insert results based on type
(cond
;; do nothing for an empty result
((null result))
;; insert a list if preferred
((member "list" result-params)
(insert
(org-babel-trim
(org-list-to-generic
(cons 'unordered
(mapcar
(lambda (el) (list nil (if (stringp el) el (format "%S" el))))
(if (listp result) result (list result))))
'(:splicep nil :istart "- " :iend "\n")))
"\n"))
;; assume the result is a table if it's not a string
((proper-list-p result)
(goto-char beg)
(insert (concat (orgtbl-to-orgtbl
(if (or (eq 'hline (car result))
(and (listp (car result))
(listp (cdr (car result)))))
result (list result))
'(:fmt (lambda (cell) (format "%s" cell)))) "\n"))
(goto-char beg) (when (org-at-table-p) (org-table-align)))
((and (listp result) (not (proper-list-p result)))
(insert (format "%s\n" result)))
((member "file" result-params)
(when inlinep (goto-char inlinep))
(insert result))
(t (goto-char beg) (insert result)))
(when (proper-list-p result) (goto-char (org-table-end)))
(setq end (point-marker))
;; possibly wrap result
(cond
((member "html" result-params)
(wrap "#+BEGIN_HTML" "#+END_HTML"))
@ -1782,7 +1803,8 @@ code ---- the results are extracted in the syntax of the source
(when (and (stringp result) (not (member "file" result-params)))
(org-babel-examplize-region beg end results-switches))
(wrap "#+BEGIN_RESULT" "#+END_RESULT"))
((and (stringp result) (not (member "file" result-params)))
((and (not (proper-list-p result))
(not (member "file" result-params)))
(org-babel-examplize-region beg end results-switches)
(setq end (point)))))
;; possibly indent the results to match the #+results line
@ -1791,7 +1813,7 @@ code ---- the results are extracted in the syntax of the source
(not (and (listp result)
(member "append" result-params))))
(indent-rigidly beg end indent))))
(if (= (length result) 0)
(if (null result)
(if (member "value" result-params)
(message "Code block returned no value.")
(message "Code block produced no output."))

View File

@ -4438,6 +4438,15 @@ in the #+STARTUP line, the corresponding variable, and the value to
set this variable to if the option is found. An optional forth element PUSH
means to push this value onto the list in the variable.")
(defun org-update-property-plist (key val props)
"Update PROPS with KEY and VAL."
(if (string= "+" (substring key (- (length key) 1)))
(let* ((key (substring key 0 (- (length key) 1)))
(previous (cdr (assoc key props))))
(cons (cons key (concat previous " " val))
(org-remove-if (lambda (p) (string= (car p) key)) props)))
(cons (cons key val) props)))
(defun org-set-regexps-and-options ()
"Precompute regular expressions for current buffer."
(when (eq major-mode 'org-mode)
@ -4499,8 +4508,9 @@ means to push this value onto the list in the variable.")
(setq prio (org-split-string value " +")))
((equal key "PROPERTY")
(when (string-match "\\(\\S-+\\)\\s-+\\(.*\\)" value)
(push (cons (match-string 1 value) (match-string 2 value))
props)))
(setq props (org-update-property-plist (match-string 1 value)
(match-string 2 value)
props))))
((equal key "FILETAGS")
(when (string-match "\\S-" value)
(setq ftags
@ -4552,8 +4562,9 @@ means to push this value onto the list in the variable.")
(setq value (replace-regexp-in-string
"[\n\r]" " " (match-string 4)))
(when (string-match "\\(\\S-+\\)\\s-+\\(.*\\)" value)
(push (cons (match-string 1 value) (match-string 2 value))
props))))))
(setq props (org-update-property-plist (match-string 1 value)
(match-string 2 value)
props)))))))
(org-set-local 'org-use-sub-superscripts scripts)
(when cat
(org-set-local 'org-category (intern cat))
@ -5425,9 +5436,8 @@ will be prompted for."
'(font-lock-fontified t face org-meta-line))
t)
((or (member dc1 '("begin:" "end:" "caption:" "label:"
"orgtbl:" "tblfm:" "tblname:" "result:"
"results:" "source:" "srcname:" "call:"
"data:" "header:" "headers:"))
"orgtbl:" "tblfm:" "tblname:" "results:"
"call:" "header:" "headers:"))
(and (match-end 4) (equal dc3 "attr")))
(add-text-properties
beg (match-end 0)
@ -6616,8 +6626,7 @@ DATA should have been made by `org-outline-overlay-data'."
(widen)
(show-all)
(mapc (lambda (c)
(setq o (make-overlay (car c) (cdr c)))
(overlay-put o 'invisible 'outline))
(outline-flag-region (car c) (cdr c) t))
data)))))
;;; Folding of blocks
@ -10998,10 +11007,8 @@ This function can be used in a hook."
"BEGIN_CENTER" "END_CENTER"
"BEGIN_SRC" "END_SRC"
"BEGIN_RESULT" "END_RESULT"
"SOURCE:" "SRCNAME:" "FUNCTION:"
"RESULTS:" "DATA:"
"NAME:" "RESULTS:"
"HEADER:" "HEADERS:"
"BABEL:"
"CATEGORY:" "COLUMNS:" "PROPERTY:"
"CAPTION:" "LABEL:"
"SETUPFILE:"
@ -14087,17 +14094,23 @@ when a \"nil\" value can supersede a non-nil value higher up the hierarchy."
(cdr (assoc property (org-entry-properties nil 'special property)))
(let ((range (unless (org-before-first-heading-p)
(org-get-property-block))))
(if (and range
(goto-char (car range))
(re-search-forward
(org-re-property property)
(cdr range) t))
;; Found the property, return it.
(if (match-end 1)
(if literal-nil
(org-match-string-no-properties 1)
(org-not-nil (org-match-string-no-properties 1)))
"")))))))
(when (and range (goto-char (car range)))
((lambda (val) (when val (if literal-nil val (org-not-nil val))))
(cond
((re-search-forward
(org-re-property property) (cdr range) t)
(if (match-end 1) (org-match-string-no-properties 1) ""))
((re-search-forward
(org-re-property (concat property "+")) (cdr range) t)
(cdr (assoc
property
(org-update-property-plist
(concat property "+")
(if (match-end 1) (org-match-string-no-properties 1) "")
(list (or (assoc property org-file-properties)
(assoc property org-global-properties)
(assoc property org-global-properties-fixed)
))))))))))))))
(defun org-property-or-variable-value (var &optional inherit)
"Check if there is a property fixing the value of VAR.

2
testing/.gitignore vendored
View File

@ -1,3 +1,5 @@
# in case anyone wants to keep ert in the testing directory, e.g., for
# old versions of Emacs
ert
.org-test-id-locations
.test-org-id-locations

View File

@ -9,7 +9,9 @@
There is no default value assigned to =x= variable. This is not permitted
anymore.
#+source: carre(x)
#+name: carre(x)
#+begin_src python
return x*x
#+end_src
#+name: carre

View File

@ -6,7 +6,7 @@
:ID: eb1f6498-5bd9-45e0-9c56-50717053e7b7
:END:
#+source: noweb-example
#+name: noweb-example
#+begin_src emacs-lisp
(message "expanded")
#+end_src
@ -39,7 +39,7 @@
prop
#+end_src
#+results:
#+name:
: 4
* excessive id links on tangling
@ -64,7 +64,7 @@
:ID: f68821bc-7f49-4389-85b5-914791ee3718
:END:
#+source: four
#+name: four
#+begin_src emacs-lisp
(list 1 2 3 4)
#+end_src
@ -73,7 +73,7 @@
(length four)
#+end_src
#+results:
#+name:
: 4
* multi-line header arguments
@ -86,7 +86,7 @@
(map 'list #'list numbers letters)
#+end_src
#+results:
#+name:
| 1 | a |
| 2 | b |
| 3 | c |
@ -100,15 +100,15 @@
:ID: 0d82b52d-1bb9-4916-816b-2c67c8108dbb
:END:
#+source: i-have-a-name
#+name: i-have-a-name
#+begin_src emacs-lisp
42
#+end_src
#+results:
#+name:
: 42
#+results: i-have-a-name
#+name: i-have-a-name
: 42
* Pascal's Triangle -- export test
@ -116,7 +116,7 @@
:ID: 92518f2a-a46a-4205-a3ab-bcce1008a4bb
:END:
#+source: pascals-triangle
#+name: pascals-triangle
#+begin_src emacs-lisp :var n=5 :exports both
(defun pascals-triangle (n)
(if (= n 0)
@ -136,7 +136,7 @@
:ID: 6d2ff4ce-4489-4e2a-9c65-e3f71f77d975
:END:
#+source: take-sqrt
#+name: take-sqrt
#+begin_src emacs-lisp :var n=9
(sqrt n)
#+end_src
@ -159,7 +159,7 @@ This is an inline call call_echo(input="testing")[:results vector] embedded in p
call_echo("testing")
call_concat(1,2,3)
#+source: concat
#+name: concat
#+begin_src emacs-lisp :var a=0 :var b=0 :var c=0
(format "%S%S%S" a b c)
#+end_src
@ -169,7 +169,7 @@ call_concat(1,2,3)
:ID: 72ddeed3-2d17-4c7f-8192-a575d535d3fc
:END:
#+source: double
#+name: double
#+begin_src emacs-lisp :var it=0
(* 2 it)
#+end_src
@ -214,7 +214,7 @@ src_sh{echo 3} Here is one at the beginning of a line.
:PROPERTIES:
:ID: 5daa4d03-e3ea-46b7-b093-62c1b7632df3
:END:
#+results: a-list
#+name: a-list
- a
- b
- c
@ -298,13 +298,13 @@ src_sh{echo 2} blocks on the src_emacs-lisp{"same"} line
echo "[[file:./cv.cls]]"
#+end_src
#+results:
#+name:
: [[file:./cv.cls]]
#+begin_src sh :results raw scalar
echo "[[file:./cv.cls]]"
#+end_src
#+results:
#+name:
[[file:./cv.cls]]

View File

@ -20,7 +20,7 @@ Use a code block ouput as an input
#+end_src
Use input file
#+srcname: genfile
#+name: genfile
#+begin_src awk :in-file ob-awk-test.in :results silent
$0~/[\t]*#/{
# skip comments
@ -33,7 +33,7 @@ Use input file
* Input data generators
A code block to generate input stream
#+srcname: genseq
#+name: genseq
#+begin_src emacs-lisp :results silent
(print "1")
#+end_src

View File

@ -5,12 +5,12 @@
:PROPERTIES:
:ID: 459384e8-1797-4f11-867e-dde0473ea7cc
:END:
#+source: hello
#+name: hello
#+begin_src fortran :results silent
print *, 'Hello world'
#+end_src
#+source: fortran_parameter
#+name: fortran_parameter
#+begin_src fortran :results silent
integer, parameter :: i = 10
write (*, '(i2)') i

View File

@ -0,0 +1,36 @@
#+property: var foo=1
#+property: var+ bar=2
#+begin_src emacs-lisp
(+ foo bar)
#+end_src
#+begin_src emacs-lisp
(org-entry-get (point) "var" t)
#+end_src
* overwriting a file-wide property
:PROPERTIES:
:var: foo=7
:END:
#+begin_src emacs-lisp
foo
#+end_src
#+begin_src emacs-lisp
(org-entry-get (point) "var" t)
#+end_src
* appending to a file-wide property
:PROPERTIES:
:var+: baz=3
:END:
#+begin_src emacs-lisp
(+ foo bar baz)
#+end_src
#+begin_src emacs-lisp
(org-entry-get (point) "var" t)
#+end_src

View File

@ -35,6 +35,7 @@
(ert-deftest ob-C/table ()
"Test of a table output"
:expected-result :failed
(org-test-at-id "2df1ab83-3fa3-462a-a1f3-3aef6044a874"
(org-babel-next-src-block)
(should (equal '((1) (2)) (org-babel-execute-src-block)))))

View File

@ -8,7 +8,7 @@
(org-test-for-executable "R")
(unless (featurep 'ess)
(throw 'missing-test-dependency "ESS"))
(signal 'missing-test-dependency "ESS"))
(let ((load-path (cons (expand-file-name
".." (file-name-directory

View File

@ -50,6 +50,7 @@
(ert-deftest ob-fortran/input-var ()
"Test :var"
:expected-result :failed
(org-test-at-id "d8d1dfd3-5f0c-48fe-b55d-777997e02242"
(org-babel-next-src-block)
(should (= 15 (org-babel-execute-src-block)))))

View File

@ -13,36 +13,6 @@
(require 'org-test)
(require 'org-test-ob-consts))
(ert-deftest test-org-babel/src-name-regexp ()
(should(equal "^[ \t]*#\\+\\(srcname\\|source\\|function\\):[ \t]*"
org-babel-src-name-regexp))
(mapcar (lambda (name)
(should (org-test-string-exact-match
org-babel-src-name-regexp
(concat
" \t #+"
name
": \t src-name \t blah blah blah ")))
(should (string-match
org-babel-src-name-regexp
(concat
"#+" (upcase name)
": src-name")))
;;TODO This should fail no?
(should (org-test-string-exact-match
org-babel-src-name-regexp
(concat
"#+" name ":")))
;;TODO Check - should this pass?
(should (not (org-test-string-exact-match
org-babel-src-name-regexp
(concat
"#+" name " : src-name")))))
'("srcname" "source" "function"))
(should (not (org-test-string-exact-match
org-babel-src-name-regexp
"#+invalid-name: src-name"))))
(ert-deftest test-org-babel/multi-line-header-regexp ()
(should(equal "^[ \t]*#\\+headers?:[ \t]*\\([^\n]*\\)$"
org-babel-multi-line-header-regexp))
@ -63,18 +33,6 @@
org-babel-multi-line-header-regexp
" \t #+headers : blah1 blah2 blah3 \t\n\t\n blah4 blah5 blah6 \n"))))
(ert-deftest test-org-babel/src-name-w-name-regexp ()
(should(equal
(concat org-babel-src-name-regexp "\\("
org-babel-multi-line-header-regexp "\\)*"
"\\([^ ()\f\t\n\r\v]+\\)\\(\(\\(.*\\)\)\\|\\)")
org-babel-src-name-w-name-regexp))
(should (org-test-string-exact-match
org-babel-src-name-w-name-regexp
(concat
"#+srcname: src-name "
"#+headers: blah1 blah2 blah3 \t\n\t\n blah4 blah5 blah6 \n"))))
(ert-deftest test-org-babel/src-block-regexp ()
(let ((test-block
(concat
@ -445,6 +403,100 @@ duplicate results block."
(should (search-forward "Hello")) ; the same string in the results block
(should-error (search-forward "Hello"))))
(ert-deftest test-org-babel/nested-code-block ()
"Test nested code blocks inside code blocks don't cause problems."
(org-test-with-temp-text "#+begin_src org :results silent
,#+begin_src emacs-lisp
, 'foo
,#+end_src
#+end_src"
(should (string= (org-babel-execute-src-block)
"#+begin_src emacs-lisp\n 'foo\n#+end_src"))))
(ert-deftest test-org-babel/partial-nested-code-block ()
"Test nested code blocks inside code blocks don't cause problems."
(org-test-with-temp-text "#+begin_src org :results silent
,#+begin_src emacs-lisp
#+end_src"
(should (string= "#+begin_src emacs-lisp" (org-babel-execute-src-block)))))
(ert-deftest test-ob/does-not-replace-a-block-with-the-results ()
(org-test-with-temp-text "#+NAME: foo
#+BEGIN_SRC emacs-lisp
'foo
#+END_SRC\n"
(org-babel-next-src-block 1)
(should (eq 'foo (org-babel-execute-src-block)))
(goto-char (point-min))
(org-babel-next-src-block 1)
(should (looking-at org-babel-src-block-regexp))))
(ert-deftest test-ob/catches-all-references ()
(org-test-with-temp-text "
#+NAME: literal-example
#+BEGIN_EXAMPLE
A literal example
on two lines
#+END_EXAMPLE
#+NAME: read-literal-example
#+BEGIN_SRC emacs-lisp :var x=literal-example
(concatenate 'string x \" for me.\")
#+END_SRC"
(org-babel-next-src-block 1)
(should (string= (org-babel-execute-src-block)
"A literal example\non two lines for me."))))
(ert-deftest test-ob/resolve-code-blocks-before-data-blocks ()
(org-test-with-temp-text "
#+name: foo
: bar
#+name: foo
#+begin_src emacs-lisp
\"baz\"
#+end_src
#+begin_src emacs-lisp :var foo=foo
foo
#+end_src"
(org-babel-next-src-block 2)
(should (string= (org-babel-execute-src-block) "baz"))))
(ert-deftest test-ob/do-not-resolve-to-partial-names-data ()
(org-test-with-temp-text "
#+tblname: base_plus
| 1 |
| 2 |
#+tblname: base
| 3 |
| 4 |
#+begin_src emacs-lisp :var x=base
x
#+end_src"
(org-babel-next-src-block 1)
(should (equal (org-babel-execute-src-block) '((3) (4))))))
(ert-deftest test-ob/do-not-resolve-to-partial-names-code ()
(org-test-with-temp-text "
#+name: base_plus
#+begin_src emacs-lisp
'bar
#+end_src
#+name: base
#+begin_src emacs-lisp
'foo
#+end_src
#+begin_src emacs-lisp :var x=base
x
#+end_src"
(org-babel-next-src-block 3)
(should (equal (org-babel-execute-src-block) "foo"))))
(provide 'test-ob)
;;; test-ob ends here

View File

@ -0,0 +1,61 @@
;;; test-ob-R.el --- tests for ob-R.el
;; Copyright (c) 2011 Eric Schulte
;; Authors: Eric Schulte
;; Released under the GNU General Public License version 3
;; see: http://www.gnu.org/licenses/gpl-3.0.html
(let ((load-path (cons (expand-file-name
".." (file-name-directory
(or load-file-name buffer-file-name)))
load-path)))
(require 'org-test)
(require 'org-test-ob-consts))
(defmacro test-org-in-property-buffer (&rest body)
`(with-temp-buffer
(insert-file-contents (expand-file-name "property-inheritance.org"
org-test-example-dir))
(org-mode)
,@body))
(ert-deftest test-org-property-accumulation-top-use ()
(test-org-in-property-buffer
(goto-char (point-min))
(org-babel-next-src-block 1)
(should (equal 3 (org-babel-execute-src-block)))))
(ert-deftest test-org-property-accumulation-top-val ()
(test-org-in-property-buffer
(goto-char (point-min))
(org-babel-next-src-block 2)
(should (string= "foo=1 bar=2" (org-babel-execute-src-block)))))
(ert-deftest test-org-property-accumulation-overwrite-use ()
(test-org-in-property-buffer
(goto-char (point-min))
(org-babel-next-src-block 3)
(should (= 7 (org-babel-execute-src-block)))))
(ert-deftest test-org-property-accumulation-overwrite-val ()
(test-org-in-property-buffer
(goto-char (point-min))
(org-babel-next-src-block 4)
(should (string= "foo=7" (org-babel-execute-src-block)))))
(ert-deftest test-org-property-accumulation-append-use ()
(test-org-in-property-buffer
(goto-char (point-min))
(org-babel-next-src-block 5)
(should (= 6 (org-babel-execute-src-block)))))
(ert-deftest test-org-property-accumulation-append-val ()
(test-org-in-property-buffer
(goto-char (point-min))
(org-babel-next-src-block 6)
(should (string= "foo=1 bar=2 baz=3" (org-babel-execute-src-block)))))
(provide 'test-ob-R)
;;; test-ob-R.el ends here

View File

@ -39,8 +39,9 @@
(unless (featurep 'org)
(setq load-path (cons org-lisp-dir load-path))
(require 'org)
(org-babel-do-load-languages
'org-babel-load-languages '((sh . t))))
(require 'org-id)
(org-babel-do-load-languages
'org-babel-load-languages '((sh . t) (org . t))))
(let* ((load-path (cons
org-test-dir
@ -102,6 +103,10 @@ org-test searches this directory up the directory tree.")
;;; Functions for writing tests
(put 'missing-test-dependency
'error-conditions
'(error missing-test-dependency))
(defun org-test-for-executable (exe)
"Throw an error if EXE is not available.
This can be used at the top of code-block-language specific test
@ -111,7 +116,7 @@ executable."
(lambda (acc dir)
(or acc (file-exists-p (expand-file-name exe dir))))
exec-path :initial-value nil)
(throw 'missing-test-dependency exe)))
(signal 'missing-test-dependency (list exe))))
(defun org-test-buffer (&optional file)
"TODO: Setup and return a buffer to work with.
@ -274,9 +279,18 @@ otherwise place the point at the beginning of the inserted text."
(mapc
(lambda (path)
(if (file-directory-p path)
(rld path)
(catch 'missing-test-dependency
(load-file path))))
(rld path)
(condition-case err
(when (string-match "^[A-Za-z].*\\.el$"
(file-name-nondirectory path))
(load-file path))
(missing-test-dependency
(let ((name (intern
(concat "org-missing-dependency/"
(file-name-nondirectory
(file-name-sans-extension path))))))
(eval `(ert-deftest ,name ()
:expected-result :failed (should nil))))))))
(directory-files base 'full
"^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*\\.el$"))))
(rld (expand-file-name "lisp" org-test-dir))
@ -301,13 +315,26 @@ otherwise place the point at the beginning of the inserted text."
"^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*\\.org$"))
(find-file file)))
(defun org-test-update-id-locations ()
(org-id-update-id-locations
(directory-files
org-test-example-dir 'full
"^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*\\.org$")))
(defun org-test-run-batch-tests ()
"Run all defined tests matching \"\\(org\\|ob\\)\".
Load all test files first."
(interactive)
(org-test-touch-all-examples)
(org-test-load)
(ert-run-tests-batch-and-exit "\\(org\\|ob\\)"))
(let ((org-id-track-globally t)
(org-id-locations-file
(convert-standard-filename
(expand-file-name
"testing/.test-org-id-locations"
org-base-dir))))
(org-test-touch-all-examples)
(org-test-update-id-locations)
(org-test-load)
(ert-run-tests-batch-and-exit "\\(org\\|ob\\)")))
(defun org-test-run-all-tests ()
"Run all defined tests matching \"\\(org\\|ob\\)\".