home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / gnu / info / calc.info-25 (.txt) < prev    next >
GNU Info File  |  1994-12-22  |  49KB  |  843 lines

  1. This is Info file calc.info, produced by Makeinfo-1.55 from the input
  2. file calc.texinfo.
  3.    This file documents Calc, the GNU Emacs calculator.
  4.    Copyright (C) 1990, 1991 Free Software Foundation, Inc.
  5.    Permission is granted to make and distribute verbatim copies of this
  6. manual provided the copyright notice and this permission notice are
  7. preserved on all copies.
  8.    Permission is granted to copy and distribute modified versions of
  9. this manual under the conditions for verbatim copying, provided also
  10. that the section entitled "GNU General Public License" is included
  11. exactly as in the original, and provided that the entire resulting
  12. derived work is distributed under the terms of a permission notice
  13. identical to this one.
  14.    Permission is granted to copy and distribute translations of this
  15. manual into another language, under the above conditions for modified
  16. versions, except that the section entitled "GNU General Public License"
  17. may be included in a translation approved by the author instead of in
  18. the original English.
  19. File: calc.info,  Node: Programming,  Next: Installation,  Prev: Embedded Mode,  Up: Top
  20. Programming
  21. ***********
  22. There are several ways to "program" the Emacs Calculator, depending on
  23. the nature of the problem you need to solve.
  24.   1. "Keyboard macros" allow you to record a sequence of keystrokes and
  25.      play them back at a later time.  This is just the standard Emacs
  26.      keyboard macro mechanism, dressed up with a few more features such
  27.      as loops and conditionals.
  28.   2. "Algebraic definitions" allow you to use any formula to define a
  29.      new function.  This function can then be used in algebraic
  30.      formulas or as an interactive command.
  31.   3. "Rewrite rules" are discussed in the section on algebra commands.
  32.      *Note Rewrite Rules::.  If you put your rewrite rules in the
  33.      variable `EvalRules', they will be applied automatically to all
  34.      Calc results in just the same way as an internal "rule" is applied
  35.      to evaluate `sqrt(9)' to 3 and so on.  *Note Automatic Rewrites::.
  36.   4. "Lisp" is the programming language that Calc (and most of Emacs)
  37.      is written in.  If the above techniques aren't powerful enough, you
  38.      can write Lisp functions to do anything that built-in Calc commands
  39.      can do.  Lisp code is also somewhat faster than keyboard macros or
  40.      rewrite rules.
  41.    Programming features are available through the `z' and `Z' prefix
  42. keys.  New commands that you define are two-key sequences beginning
  43. with `z'.  Commands for managing these definitions use the shift-`Z'
  44. prefix.  (The `Z T' (`calc-timing') command is described elsewhere;
  45. *note Troubleshooting Commands::..  The `Z C'
  46. (`calc-user-define-composition') command is also described elsewhere;
  47. *note User-Defined Compositions::..)
  48. * Menu:
  49. * Creating User Keys::
  50. * Keyboard Macros::
  51. * Invocation Macros::
  52. * Algebraic Definitions::
  53. * Lisp Definitions::
  54. File: calc.info,  Node: Creating User Keys,  Next: Keyboard Macros,  Prev: Programming,  Up: Programming
  55. Creating User Keys
  56. ==================
  57. Any Calculator command may be bound to a key using the `Z D'
  58. (`calc-user-define') command.  Actually, it is bound to a two-key
  59. sequence beginning with the lower-case `z' prefix.
  60.    The `Z D' command first prompts for the key to define.  For example,
  61. press `Z D a' to define the new key sequence `z a'.  You are then
  62. prompted for the name of the Calculator command that this key should
  63. run.  For example, the `calc-sincos' command is not normally available
  64. on a key.  Typing `Z D s sincos RET' programs the `z s' key sequence to
  65. run `calc-sincos'.  This definition will remain in effect for the rest
  66. of this Emacs session, or until you redefine `z s' to be something else.
  67.    You can actually bind any Emacs command to a `z' key sequence by
  68. backspacing over the `calc-' when you are prompted for the command name.
  69.    As with any other prefix key, you can type `z ?' to see a list of
  70. all the two-key sequences you have defined that start with `z'.
  71. Initially, no `z' sequences (except `z ?' itself) are defined.
  72.    User keys are typically letters, but may in fact be any key.
  73. (META-keys are not permitted, nor are a terminal's special function
  74. keys which generate multi-character sequences when pressed.) You can
  75. define different commands on the shifted and unshifted versions of a
  76. letter if you wish.
  77.    The `Z U' (`calc-user-undefine') command unbinds a user key.  For
  78. example, the key sequence `Z U s' will undefine the `sincos' key we
  79. defined above.
  80.    The `Z P' (`calc-user-define-permanent') command makes a key binding
  81. permanent so that it will remain in effect even in future Emacs
  82. sessions.  (It does this by adding a suitable bit of Lisp code into
  83. your `.emacs' file.)  For example, `Z P s' would register our `sincos'
  84. command permanently.  If you later wish to unregister this command you
  85. must edit your `.emacs' file by hand.  (*Note General Mode Commands::,
  86. for a way to tell Calc to use a different file instead of `.emacs'.)
  87.    The `Z P' command also saves the user definition, if any, for the
  88. command bound to the key.  After `Z F' and `Z C', a given user key
  89. could invoke a command, which in turn calls an algebraic function,
  90. which might have one or more special display formats.  A single `Z P'
  91. command will save all of these definitions.
  92.    To save a command or function without its key binding (or if there is
  93. no key binding for the command or function), type `'' (the apostrophe)
  94. when prompted for a key.  Then, type the function name, or backspace to
  95. change the `calcFunc-' prefix to `calc-' and enter a command name.  (If
  96. the command you give implies a function, the function will be saved,
  97. and if the function has any display formats, those will be saved, but
  98. not the other way around:  Saving a function will not save any commands
  99. or key bindings associated with the function.)
  100.    The `Z E' (`calc-user-define-edit') command edits the definition of
  101. a user key.  This works for keys that have been defined by either
  102. keyboard macros or formulas; further details are contained in the
  103. relevant following sections.
  104. File: calc.info,  Node: Keyboard Macros,  Next: Invocation Macros,  Prev: Creating User Keys,  Up: Programming
  105. Programming with Keyboard Macros
  106. ================================
  107. The easiest way to "program" the Emacs Calculator is to use standard
  108. keyboard macros.  Press `C-x (' to begin recording a macro.  From this
  109. point on, keystrokes you type will be saved away as well as performing
  110. their usual functions.  Press `C-x )' to end recording.  Press
  111. shift-`X' (or the standard Emacs key sequence `C-x e') to execute your
  112. keyboard macro by replaying the recorded keystrokes.  *Note Keyboard
  113. Macros: (emacs)Keyboard Macros, for further information.
  114.    When you use `X' to invoke a keyboard macro, the entire macro is
  115. treated as a single command by the undo and trail features.  The stack
  116. display buffer is not updated during macro execution, but is instead
  117. fixed up once the macro completes.  Thus, commands defined with keyboard
  118. macros are convenient and efficient.  The `C-x e' command, on the other
  119. hand, invokes the keyboard macro with no special treatment: Each
  120. command in the macro will record its own undo information and trail
  121. entry, and update the stack buffer accordingly.  If your macro uses
  122. features outside of Calc's control to operate on the contents of the
  123. Calc stack buffer, or if it includes Undo, Redo, or last-arguments
  124. commands, you must use `C-x e' to make sure the buffer and undo list
  125. are up-to-date at all times.  You could also consider using `K'
  126. (`calc-keep-args') instead of `M-RET' (`calc-last-args').
  127.    Calc extends the standard Emacs keyboard macros in several ways.
  128. Keyboard macros can be used to create user-defined commands.  Keyboard
  129. macros can include conditional and iteration structures, somewhat
  130. analogous to those provided by a traditional programmable calculator.
  131. * Menu:
  132. * Naming Keyboard Macros::
  133. * Conditionals in Macros::
  134. * Loops in Macros::
  135. * Local Values in Macros::
  136. * Queries in Macros::
  137. File: calc.info,  Node: Naming Keyboard Macros,  Next: Conditionals in Macros,  Prev: Keyboard Macros,  Up: Keyboard Macros
  138. Naming Keyboard Macros
  139. ----------------------
  140. Once you have defined