@node Programs, Keymaps, Macros, Top
@chapter Programs



@menu
* One Line Programs::           Writing One Line Programs
* Long One Liners::             Multiple Commands in One Line
* Writing programs::            Writing Programs
* Commands in Programs::        Commands available in programs
@end menu

@node One Line Programs, Long One Liners, Programs, Programs
@section Writing One Line Programs
        Any @kbd{M-x} command can be written into a cell.  Typing 
@code{M-x cell-number} will execute the commands in the cell.
For example, assume the cell cursor is located on cell @code{A1}.
Enter the keystrokes (including the quotes and braces).

@example 
"@{right-cell 4@}"
@end example

If you now type @code{M-x A1} the cell cursor will be positioned in
@code{E1}. Typing @code{M-x A1} again, the cell cursor is positioned at
@code{I1}.  Some examples:



@table @code
@item "@{set-option status -1@}"
        Set the status line to the bottom row of the screen

@item "@{print-region A1.F35 /tmp/out@}"
        Write the values of the cells in the region @samp{A1.F35} to the
file @code{/tmp/out}.  The contents of the cells are truncated to fit in
their column's width.  The result is a rectangular array.  Notice that
there are no quotes around the file name.

@end table

@node Long One Liners, Writing programs, One Line Programs, Programs
@section Multiple Commands in One Line

To execute several commands at once, concatenate them in a cell.
If @samp{A1} contains
@example
"@{right-cell 1@}@{up-cell 1@}"
@end example

then typing @code{M-x A1} moves the cell cursor one right and one up.


@node Writing programs, Commands in Programs, Long One Liners, Programs
@section Writing Programs

If commands are entered into a region named by a variable @var{var},
then we can use @code{M-x var} to execute the code.

Suppose that the contents of @code{A1.A3} are given below , and that
region @code{A1.A3} is named @code{test1}.  Typing
@code{M-x test1} has the same effect as @code{@{up-cell 1@}}.

@example
        "@{right-cell 1@}"
        "@{up-cell    1@}"
        "@{left-cell  1@}"
@end example

@footnote{yes it's trivial - how about something complex!}

If @file{filename} contains a list of @code{Oleo} commands (like the
@file{.oleorc} file), the commands in this file can be executed:

@table @kbd
@item M-x	read-commands	
This command opens the file you specify, reads in each
line, and executes them as if you'd typed them in to
execute-command.  If any command needs more arguments than are
included on the line, it will prompt you (interactively) for
the missing information.

The syntax for a command is a command name followed by a whitespace 
separated list arguments.  For example: 
@example

	bind-key main next-row @kbd{^n},
@end example

Blank lines and lines that begin with `#' are ignored.
Lines may be continued by preceeding the final newline with an
odd number of `\\' characters.  One backslash and the newline will,
be discarded.

The commands in the next file perform some arithmetic operations on an
already loaded spreadsheet.  Note that the division is protected against
division by zero.
@example
goto-cell r3c84
edit-cell  ((rc82-rc3)/if(rc4=0,0.5,rc4) )^2 + \
           ((rc82-rc5)/if(rc6=0,0.5,rc6) )^2 
goto-cell r3c85
edit-cell rc[-1]/36.0
@end example

@end table




@node Commands in Programs,  , Writing programs, Programs
@section Commands available in programs

The commands available in programs are listed in the command index
(@pxref{Command Index}).
For more information, look at the online help for the individual entries.


