home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
gnu
/
info
/
calc.info-25
(
.txt
)
< prev
next >
Wrap
GNU Info File
|
1994-12-22
|
49KB
|
843 lines
This is Info file calc.info, produced by Makeinfo-1.55 from the input
file calc.texinfo.
This file documents Calc, the GNU Emacs calculator.
Copyright (C) 1990, 1991 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.
Permission is granted to copy and distribute modified versions of
this manual under the conditions for verbatim copying, provided also
that the section entitled "GNU General Public License" is included
exactly as in the original, and provided that the entire resulting
derived work is distributed under the terms of a permission notice
identical to this one.
Permission is granted to copy and distribute translations of this
manual into another language, under the above conditions for modified
versions, except that the section entitled "GNU General Public License"
may be included in a translation approved by the author instead of in
the original English.
File: calc.info, Node: Programming, Next: Installation, Prev: Embedded Mode, Up: Top
Programming
***********
There are several ways to "program" the Emacs Calculator, depending on
the nature of the problem you need to solve.
1. "Keyboard macros" allow you to record a sequence of keystrokes and
play them back at a later time. This is just the standard Emacs
keyboard macro mechanism, dressed up with a few more features such
as loops and conditionals.
2. "Algebraic definitions" allow you to use any formula to define a
new function. This function can then be used in algebraic
formulas or as an interactive command.
3. "Rewrite rules" are discussed in the section on algebra commands.
*Note Rewrite Rules::. If you put your rewrite rules in the
variable `EvalRules', they will be applied automatically to all
Calc results in just the same way as an internal "rule" is applied
to evaluate `sqrt(9)' to 3 and so on. *Note Automatic Rewrites::.
4. "Lisp" is the programming language that Calc (and most of Emacs)
is written in. If the above techniques aren't powerful enough, you
can write Lisp functions to do anything that built-in Calc commands
can do. Lisp code is also somewhat faster than keyboard macros or
rewrite rules.
Programming features are available through the `z' and `Z' prefix
keys. New commands that you define are two-key sequences beginning
with `z'. Commands for managing these definitions use the shift-`Z'
prefix. (The `Z T' (`calc-timing') command is described elsewhere;
*note Troubleshooting Commands::.. The `Z C'
(`calc-user-define-composition') command is also described elsewhere;
*note User-Defined Compositions::..)
* Menu:
* Creating User Keys::
* Keyboard Macros::
* Invocation Macros::
* Algebraic Definitions::
* Lisp Definitions::
File: calc.info, Node: Creating User Keys, Next: Keyboard Macros, Prev: Programming, Up: Programming
Creating User Keys
==================
Any Calculator command may be bound to a key using the `Z D'
(`calc-user-define') command. Actually, it is bound to a two-key
sequence beginning with the lower-case `z' prefix.
The `Z D' command first prompts for the key to define. For example,
press `Z D a' to define the new key sequence `z a'. You are then
prompted for the name of the Calculator command that this key should
run. For example, the `calc-sincos' command is not normally available
on a key. Typing `Z D s sincos RET' programs the `z s' key sequence to
run `calc-sincos'. This definition will remain in effect for the rest
of this Emacs session, or until you redefine `z s' to be something else.
You can actually bind any Emacs command to a `z' key sequence by
backspacing over the `calc-' when you are prompted for the command name.
As with any other prefix key, you can type `z ?' to see a list of
all the two-key sequences you have defined that start with `z'.
Initially, no `z' sequences (except `z ?' itself) are defined.
User keys are typically letters, but may in fact be any key.
(META-keys are not permitted, nor are a terminal's special function
keys which generate multi-character sequences when pressed.) You can
define different commands on the shifted and unshifted versions of a
letter if you wish.
The `Z U' (`calc-user-undefine') command unbinds a user key. For
example, the key sequence `Z U s' will undefine the `sincos' key we
defined above.
The `Z P' (`calc-user-define-permanent') command makes a key binding
permanent so that it will remain in effect even in future Emacs
sessions. (It does this by adding a suitable bit of Lisp code into
your `.emacs' file.) For example, `Z P s' would register our `sincos'
command permanently. If you later wish to unregister this command you
must edit your `.emacs' file by hand. (*Note General Mode Commands::,
for a way to tell Calc to use a different file instead of `.emacs'.)
The `Z P' command also saves the user definition, if any, for the
command bound to the key. After `Z F' and `Z C', a given user key
could invoke a command, which in turn calls an algebraic function,
which might have one or more special display formats. A single `Z P'
command will save all of these definitions.
To save a command or function without its key binding (or if there is
no key binding for the command or function), type `'' (the apostrophe)
when prompted for a key. Then, type the function name, or backspace to
change the `calcFunc-' prefix to `calc-' and enter a command name. (If
the command you give implies a function, the function will be saved,
and if the function has any display formats, those will be saved, but
not the other way around: Saving a function will not save any commands
or key bindings associated with the function.)
The `Z E' (`calc-user-define-edit') command edits the definition of
a user key. This works for keys that have been defined by either
keyboard macros or formulas; further details are contained in the
relevant following sections.
File: calc.info, Node: Keyboard Macros, Next: Invocation Macros, Prev: Creating User Keys, Up: Programming
Programming with Keyboard Macros
================================
The easiest way to "program" the Emacs Calculator is to use standard
keyboard macros. Press `C-x (' to begin recording a macro. From this
point on, keystrokes you type will be saved away as well as performing
their usual functions. Press `C-x )' to end recording. Press
shift-`X' (or the standard Emacs key sequence `C-x e') to execute your
keyboard macro by replaying the recorded keystrokes. *Note Keyboard
Macros: (emacs)Keyboard Macros, for further information.
When you use `X' to invoke a keyboard macro, the entire macro is
treated as a single command by the undo and trail features. The stack
display buffer is not updated during macro execution, but is instead
fixed up once the macro completes. Thus, commands defined with keyboard
macros are convenient and efficient. The `C-x e' command, on the other
hand, invokes the keyboard macro with no special treatment: Each
command in the macro will record its own undo information and trail
entry, and update the stack buffer accordingly. If your macro uses
features outside of Calc's control to operate on the contents of the
Calc stack buffer, or if it includes Undo, Redo, or last-arguments
commands, you must use `C-x e' to make sure the buffer and undo list
are up-to-date at all times. You could also consider using `K'
(`calc-keep-args') instead of `M-RET' (`calc-last-args').
Calc extends the standard Emacs keyboard macros in several ways.
Keyboard macros can be used to create user-defined commands. Keyboard
macros can include conditional and iteration structures, somewhat
analogous to those provided by a traditional programmable calculator.
* Menu:
* Naming Keyboard Macros::
* Conditionals in Macros::
* Loops in Macros::
* Local Values in Macros::
* Queries in Macros::
File: calc.info, Node: Naming Keyboard Macros, Next: Conditionals in Macros, Prev: Keyboard Macros, Up: Keyboard Macros
Naming Keyboard Macros
----------------------
Once you have defined