Programs
********

Writing One Line Programs
=========================

Any M-x command can be written into a cell.  Typing M-x cell-number will execute the commands in the cell. For example, assume the cell cursor is located on cell A1. Enter the keystrokes (including the quotes and braces).

     "{right-cell 4}"

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

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

"{print-region A1.F35 /tmp/out}"
     Write the values of the cells in the region A1.F35 to the file /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.

Multiple Commands in One Line
=============================

To execute several commands at once, concatenate them in a cell. If A1 contains

     "{right-cell 1}{up-cell 1}"

then typing M-x A1 moves the cell cursor one right and one up.

Writing Programs
================

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

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

             "{right-cell 1}"
             "{up-cell    1}"
             "{left-cell  1}"

 (yes it's trivial - how about something complex!)

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

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:

          	bind-key main next-row ^n,

     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.

          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

Commands available in programs
==============================

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