(calc-user-define-formula, calc-do-defmath): Replace calc-need-macros by
[bpt/emacs.git] / lisp / calc / calc.el
index f119266..d2b75a2 100644 (file)
@@ -1,9 +1,9 @@
 ;;; calc.el --- the GNU Emacs calculator
 
-;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002 Free Software Foundation, Inc.
+;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
 
 ;; Author: David Gillespie <daveg@synaptics.com>
-;; Maintainer: Colin Walters <walters@debian.org>
+;; Maintainer: Jay Belanger <belanger@truman.edu>
 ;; Keywords: convenience, extensions
 ;; Version: 2.02g
 
 ;; Subject: Re: fix for `Cannot open load file: calc-alg-3'
 ;; To: walters@debian.org
 ;; Date: Sat, 24 Nov 2001 21:44:21 +0000 (UTC)
-;; 
+;;
 ;; Could you add logistic curve fitting to the current list?
-;; 
+;;
 ;; (I guess the key binding for a logistic curve would have to be `s'
 ;; since a logistic curve is an `s' curve; both `l' and `L' are already
 ;; taken for logarithms.)
-;; 
+;;
 ;; Here is the current list for curve fitting;
-;; 
+;;
 ;;     `1'
 ;;          Linear or multilinear.  a + b x + c y + d z.
-;; 
+;;
 ;;     `2-9'
 ;;          Polynomials.  a + b x + c x^2 + d x^3.
-;; 
+;;
 ;;     `e'
 ;;          Exponential.  a exp(b x) exp(c y).
-;; 
+;;
 ;;     `E'
 ;;          Base-10 exponential.  a 10^(b x) 10^(c y).
-;; 
+;;
 ;;     `x'
 ;;          Exponential (alternate notation).  exp(a + b x + c y).
-;; 
+;;
 ;;     `X'
 ;;          Base-10 exponential (alternate).  10^(a + b x + c y).
-;; 
+;;
 ;;     `l'
 ;;          Logarithmic.  a + b ln(x) + c ln(y).
-;; 
+;;
 ;;     `L'
 ;;          Base-10 logarithmic.  a + b log10(x) + c log10(y).
-;; 
+;;
 ;;     `^'
 ;;          General exponential.  a b^x c^y.
-;; 
+;;
 ;;     `p'
 ;;          Power law.  a x^b y^c.
-;; 
+;;
 ;;     `q'
 ;;          Quadratic.  a + b (x-c)^2 + d (x-e)^2.
-;; 
+;;
 ;;     `g'
 ;;          Gaussian.  (a / b sqrt(2 pi)) exp(-0.5*((x-c)/b)^2).
-;; 
-;; 
+;;
+;;
 ;; Logistic curves are used a great deal in ecology, and in predicting
 ;; human actions, such as use of different kinds of energy in a country
 ;; (wood, coal, oil, natural gas, etc.) or the number of scientific
 ;; papers a person publishes, or the number of movies made.
-;; 
+;;
 ;; (The less information on which to base the curve, the higher the error
 ;; rate.  Theodore Modis ran some Monte Carlo simulations and produced
 ;; what may be useful set of confidence levels for different amounts of
@@ -236,356 +236,366 @@ This can safely be nil as long as the Calc files are on the load-path.")
 (defvar calc-gnuplot-print-command "lp %s"
   "*Name of command for printing GNUPLOT output; %s = file name to print.")
 
-;; Address of the author of Calc, for use by report-calc-bug.
-(defvar calc-bug-address "walters@debian.org")
+(defvar calc-bug-address "belanger@truman.edu"
+  "Address of the author of Calc, for use by `report-calc-bug'.")
 
-;; If t, scan keymaps to find all DEL-like keys.
-;; if nil, only DEL itself is mapped to calc-pop.
-(defvar calc-scan-for-dels t)
+(defvar calc-scan-for-dels t
+  "If t, scan keymaps to find all DEL-like keys.
+if nil, only DEL itself is mapped to calc-pop.")
 
 (defvar calc-extensions-loaded nil)
 
-;; Calculator stack.
-;; Entries are 3-lists:  Formula, Height (in lines), Selection (or nil).
-(defvar calc-stack '((top-of-stack 1 nil)))
-
-(defvar calc-show-banner t
-  "*If non-nil, show a friendly greeting above the stack.")
-
-;; Index into calc-stack of "top" of stack.
-;; This is 1 unless calc-truncate-stack has been used.
-;;(defvar calc-stack-top 1)
-
-;; If non-nil, load the calc-ext module automatically when calc is loaded.
-;;(defvar calc-always-load-extensions nil)
-
-;; If non-nil, display line numbers in Calculator stack.
-;;(defvar calc-line-numbering t)
-
-;; If non-nil, break long values across multiple lines in Calculator stack.
-;;(defvar calc-line-breaking t)
-
-;; If nil, stack display is left-justified.
-;; If 'right, stack display is right-justified.
-;; If 'center, stack display is centered."
-;;(defvar calc-display-just nil)
-
-;; Horizontal origin of displayed stack entries.
-;; In left-justified mode, this is effectively indentation.  (Default 0).
-;; In right-justified mode, this is effectively window width.
-;; In centered mode, center of stack entry is placed here.
-;;(defvar calc-display-origin nil)
-
-;; Radix for entry and display of numbers in calc-mode, 2-36.
-;;(defvar calc-number-radix 10)
-
-;; If non-nil, leading zeros are provided to pad integers to calc-word-size.
-;;(defvar calc-leading-zeros nil)
-
-;; If non-nil, group digits in large displayed integers by inserting spaces.
-;; If an integer, group that many digits at a time.
-;; If 't', use 4 for binary and hex, 3 otherwise.
-;;(defvar calc-group-digits nil)
-
-;; The character (in the form of a string) to be used for grouping digits.
-;; This is used only when calc-group-digits mode is on.
-;;(defvar calc-group-char ",")
-
-;; The character (in the form of a string) to be used as a decimal point.
-;;(defvar calc-point-char ".")
-
-;; Format of displayed fractions; a string of one or two of ":" or "/".
-;;(defvar calc-frac-format '(":" nil))
-
-;; If non-nil, prefer fractional over floating-point results.
-;;(defvar calc-prefer-frac nil)
-
-;; Format of displayed hours-minutes-seconds angles, a format string.
-;; String must contain three %s marks for hours, minutes, seconds respectively.
-;;(defvar calc-hms-format "%s@ %s' %s\"")
-
-;; Format of displayed date forms.
-;;(defvar calc-date-format '((H ":" mm ":" SS pp " ") Www " " Mmm " " D ", " YYYY))
-
-;; Format to use for display of floating-point numbers in calc-mode.
-;; Must be a list of one of the following forms:
-;;  (float 0)      Floating point format, display full precision.
-;;  (float N)      N > 0: Floating point format, at most N significant figures.
-;;  (float -N)     -N < 0: Floating point format, calc-internal-prec - N figs.
-;;  (fix N)        N >= 0: Fixed point format, N places after decimal point.
-;;  (sci 0)        Scientific notation, full precision.
-;;  (sci N)        N > 0: Scientific notation, N significant figures.
-;;  (sci -N)       -N < 0: Scientific notation, calc-internal-prec - N figs.
-;;  (eng 0)        Engineering notation, full precision.
-;;  (eng N)        N > 0: Engineering notation, N significant figures.
-;;  (eng -N)       -N < 0: Engineering notation, calc-internal-prec - N figs.
-;;(defvar calc-float-format '(float 0))
-
-;; Format to use when full precision must be displayed.
-;;(defvar calc-full-float-format '(float 0))
-
-;; Format to use for display of complex numbers in calc-mode.  Must be one of:
-;;   nil            Use (x, y) form.
-;;   i              Use x + yi form.
-;;   j              Use x + yj form.
-;;(defvar calc-complex-format nil)
-
-;; Preferred form, either 'cplx or 'polar, for complex numbers.
-;;(defvar calc-complex-mode 'cplx)
-
-;; If nil, 1 / 0 is left unsimplified.
-;; If 0, 1 / 0 is changed to inf (zeros are considered positive).
-;; Otherwise, 1 / 0 is changed to uinf (undirected infinity).
-;;(defvar calc-infinite-mode nil)
-
-;; If non-nil, display vectors of byte-sized integers as strings.
-;;(defvar calc-display-strings nil)
-
-;; If nil, vector elements are left-justified.
-;; If 'right, vector elements are right-justified.
-;; If 'center, vector elements are centered."
-;;(defvar calc-matrix-just 'center)
-
-;; If non-nil, display vectors one element per line.
-;;(defvar calc-break-vectors nil)
-
-;; If non-nil, display long vectors in full.  If nil, use abbreviated form.
-;;(defvar calc-full-vectors t)
-
-;; If non-nil, display long vectors in full in the trail.
-;;(defvar calc-full-trail-vectors t)
-
-;; If non-nil, separate elements of displayed vectors with this string.
-;;(defvar calc-vector-commas ",")
-
-;; If non-nil, surround displayed vectors with these characters.
-;;(defvar calc-vector-brackets "[]")
-
-;; A list of code-letter symbols that control "big" matrix display.
-;; If 'R is present, display inner brackets for matrices.
-;; If 'O is present, display outer brackets for matrices (above/below).
-;; If 'C is present, display outer brackets for matrices (centered).
-;;(defvar calc-matrix-brackets '(R O))
-
-;; Language or format for entry and display of stack values.  Must be one of:
-;;   nil            Use standard Calc notation.
-;;   flat           Use standard Calc notation, one-line format.
-;;   big           Display formulas in 2-d notation (enter w/std notation).
-;;   unform        Use unformatted display: add(a, mul(b,c)).
-;;   c              Use C language notation.
-;;   pascal         Use Pascal language notation.
-;;   fortran        Use Fortran language notation.
-;;   tex            Use TeX notation.
-;;   eqn           Use eqn notation.
-;;   math           Use Mathematica(tm) notation.
-;;   maple         Use Maple notation.
-;;(defvar calc-language nil)
-
-;; Numeric prefix argument for the command that set calc-language.
-;;(defvar calc-language-option nil)
-
-;; Open-parenthesis string for function call notation.
-;;(defvar calc-function-open "(")
-
-;; Close-parenthesis string for function call notation.
-;;(defvar calc-function-close ")")
-
-;; Function through which to pass strings after formatting.
-;;(defvar calc-language-output-filter nil)
-
-;; Function through which to pass strings before parsing.
-;;(defvar calc-language-input-filter nil)
+(defvar calc-stack '((top-of-stack 1 nil))
+  "Calculator stack.
+Entries are 3-lists:  Formula, Height (in lines), Selection (or nil).")
+
+(defvar calc-stack-top 1
+  "Index into `calc-stack' of \"top\" of stack.
+This is 1 unless `calc-truncate-stack' has been used.")
+
+(defvar calc-display-sci-high 0
+  "Floating-point numbers with this positive exponent or higher above the
+current precision are displayed in scientific notation in calc-mode.")
+
+(defvar calc-display-sci-low -3
+  "Floating-point numbers with this negative exponent or lower are displayed
+scientific notation in calc-mode.")
+
+(defvar calc-other-modes nil
+  "List of used-defined strings to append to Calculator mode line.")
+
+(defvar calc-Y-help-msgs nil
+  "List of strings for Y prefix help.")
+
+(defvar calc-loaded-settings-file nil
+  "t if `calc-settings-file' has been loaded yet.")
+
+(defvar calc-always-load-extensions)
+(defvar calc-line-numbering)
+(defvar calc-line-breaking)
+(defvar calc-display-just)
+(defvar calc-display-origin)
+(defvar calc-number-radix)
+(defvar calc-leading-zeros)
+(defvar calc-group-digits)
+(defvar calc-group-char)
+(defvar calc-point-char)
+(defvar calc-frac-format)
+(defvar calc-prefer-frac)
+(defvar calc-hms-format)
+(defvar calc-date-format)
+(defvar calc-float-format)
+(defvar calc-full-float-format)
+(defvar calc-complex-format)
+(defvar calc-complex-mode)
+(defvar calc-infinite-mode)
+(defvar calc-display-strings)
+(defvar calc-matrix-just)
+(defvar calc-break-vectors)
+(defvar calc-full-vectors)
+(defvar calc-full-trail-vectors)
+(defvar calc-vector-commas)
+(defvar calc-vector-brackets)
+(defvar calc-matrix-brackets)
+(defvar calc-language)
+(defvar calc-language-option)
+(defvar calc-left-label)
+(defvar calc-right-label)
+(defvar calc-word-size)
+(defvar calc-previous-modulo)
+(defvar calc-simplify-mode)
+(defvar calc-auto-recompute)
+(defvar calc-display-raw)
+(defvar calc-internal-prec)
+(defvar calc-angle-mode)
+(defvar calc-algebraic-mode)
+(defvar calc-incomplete-algebraic-mode)
+(defvar calc-symbolic-mode)
+(defvar calc-matrix-mode)
+(defvar calc-shift-prefix)
+(defvar calc-window-height)
+(defvar calc-display-trail)
+(defvar calc-show-selections)
+(defvar calc-use-selections)
+(defvar calc-assoc-selections)
+(defvar calc-display-working-message)
+(defvar calc-auto-why)
+(defvar calc-timing)
+(defvar calc-mode-save-mode)
+(defvar calc-standard-date-formats)
+(defvar calc-autorange-units)
+(defvar calc-was-keypad-mode)
+(defvar calc-full-mode)
+(defvar calc-user-parse-tables)
+(defvar calc-gnuplot-default-device)
+(defvar calc-gnuplot-default-output)
+(defvar calc-gnuplot-print-device)
+(defvar calc-gnuplot-print-output)
+(defvar calc-gnuplot-geometry)
+(defvar calc-graph-default-resolution)
+(defvar calc-graph-default-resolution-3d)
+(defvar calc-invocation-macro)
+(defvar calc-show-banner)
+
+(defconst calc-mode-var-list '(
+  (calc-always-load-extensions nil
+   "If non-nil, load the calc-ext module automatically when calc is loaded.")
+
+  (calc-line-numbering t
+   "If non-nil, display line numbers in Calculator stack.")
+
+  (calc-line-breaking t
+   "If non-nil, break long values across multiple lines in Calculator stack.")
+
+  (calc-display-just nil
+   "If nil, stack display is left-justified.
+If `right', stack display is right-justified.
+If `center', stack display is centered.")
+
+  (calc-display-origin nil
+   "Horizontal origin of displayed stack entries.
+In left-justified mode, this is effectively indentation.  (Default 0).
+In right-justified mode, this is effectively window width.
+In centered mode, center of stack entry is placed here.")
+
+  (calc-number-radix 10
+   "Radix for entry and display of numbers in calc-mode, 2-36.")
+
+  (calc-leading-zeros nil
+   "If non-nil, leading zeros are provided to pad integers to calc-word-size.")
+
+  (calc-group-digits nil
+   "If non-nil, group digits in large displayed integers by inserting spaces.
+If an integer, group that many digits at a time.
+If t, use 4 for binary and hex, 3 otherwise.")
+
+  (calc-group-char ","
+   "The character (in the form of a string) to be used for grouping digits.
+This is used only when calc-group-digits mode is on.")
+
+  (calc-point-char "."
+   "The character (in the form of a string) to be used as a decimal point.")
+  
+  (calc-frac-format (":" nil)
+   "Format of displayed fractions; a string of one or two of \":\" or \"/\".")
+
+  (calc-prefer-frac nil
+   "If non-nil, prefer fractional over floating-point results.")
+
+  (calc-hms-format "%s@ %s' %s\""
+   "Format of displayed hours-minutes-seconds angles, a format string.
+String must contain three %s marks for hours, minutes, seconds respectively.")
+
+  (calc-date-format ((H ":" mm C SS pp " ")
+                     Www " " Mmm " " D ", " YYYY)
+   "Format of displayed date forms.")
+
+  (calc-float-format (float 0)
+   "Format to use for display of floating-point numbers in calc-mode.
+Must be a list of one of the following forms:
+ (float 0)      Floating point format, display full precision.
+ (float N)      N > 0: Floating point format, at most N significant figures.
+ (float -N)     -N < 0: Floating point format, calc-internal-prec - N figs.
+ (fix N)        N >= 0: Fixed point format, N places after decimal point.
+ (sci 0)        Scientific notation, full precision.
+ (sci N)        N > 0: Scientific notation, N significant figures.
+ (sci -N)       -N < 0: Scientific notation, calc-internal-prec - N figs.
+ (eng 0)        Engineering notation, full precision.
+ (eng N)        N > 0: Engineering notation, N significant figures.
+ (eng -N)       -N < 0: Engineering notation, calc-internal-prec - N figs.")
+
+  (calc-full-float-format (float 0)
+   "Format to use when full precision must be displayed.")
+
+  (calc-complex-format nil
+   "Format to use for display of complex numbers in calc-mode.  Must be one of:
+  nil            Use (x, y) form.
+  i              Use x + yi form.
+  j              Use x + yj form.")
+
+  (calc-complex-mode cplx
+   "Preferred form, either `cplx' or `polar', for complex numbers.")
+
+  (calc-infinite-mode nil
+   "If nil, 1 / 0 is left unsimplified.
+If 0, 1 / 0 is changed to inf (zeros are considered positive).
+Otherwise, 1 / 0 is changed to uinf (undirected infinity).")
+
+  (calc-display-strings nil
+   "If non-nil, display vectors of byte-sized integers as strings.")
+
+  (calc-matrix-just center
+   "If nil, vector elements are left-justified.
+If `right', vector elements are right-justified.
+If `center', vector elements are centered.")
+
+  (calc-break-vectors nil
+   "If non-nil, display vectors one element per line.")
+
+  (calc-full-vectors t
+   "If non-nil, display long vectors in full.  If nil, use abbreviated form.")
+
+  (calc-full-trail-vectors t
+   "If non-nil, display long vectors in full in the trail.")
+
+  (calc-vector-commas ","
+   "If non-nil, separate elements of displayed vectors with this string.")
+
+  (calc-vector-brackets "[]"
+   "If non-nil, surround displayed vectors with these characters.")
+
+  (calc-matrix-brackets (R O)
+   "A list of code-letter symbols that control \"big\" matrix display.
+If `R' is present, display inner brackets for matrices.
+If `O' is present, display outer brackets for matrices (above/below).
+If `C' is present, display outer brackets for matrices (centered).")
+
+  (calc-language nil
+   "Language or format for entry and display of stack values.  Must be one of:
+  nil          Use standard Calc notation.
+  flat         Use standard Calc notation, one-line format.
+  big          Display formulas in 2-d notation (enter w/std notation).
+  unform       Use unformatted display: add(a, mul(b,c)).
+  c            Use C language notation.
+  pascal       Use Pascal language notation.
+  fortran      Use Fortran language notation.
+  tex          Use TeX notation.
+  eqn          Use eqn notation.
+  math         Use Mathematica(tm) notation.
+  maple                Use Maple notation.")
+
+  (calc-language-option nil
+   "Numeric prefix argument for the command that set `calc-language'.")
+
+  (calc-left-label ""
+   "Label to display at left of formula.")
+
+  (calc-right-label ""
+   "Label to display at right of formula.")
+
+  (calc-word-size 32
+   "Minimum number of bits per word, if any, for binary operations in calc-mode.")
+
+  (calc-previous-modulo nil
+   "Most recently used value of M in a modulo form.")
+
+  (calc-simplify-mode nil
+   "Type of simplification applied to results.
+If `none', results are not simplified when pushed on the stack.
+If `num', functions are simplified only when args are constant.
+If nil, only fast simplifications are applied.
+If `binary', `math-clip' is applied if appropriate.
+If `alg', `math-simplify' is applied.
+If `ext', `math-simplify-extended' is applied.
+If `units', `math-simplify-units' is applied.")
+
+  (calc-auto-recompute t
+   "If non-nil, recompute evalto's automatically when necessary.")
+
+  (calc-display-raw nil
+   "If non-nil, display shows unformatted Lisp exprs.  (For debugging)")
+
+  (calc-internal-prec 12
+   "Number of digits of internal precision for calc-mode calculations.")
+
+  (calc-angle-mode deg
+   "If deg, angles are in degrees; if rad, angles are in radians.
+If hms, angles are in degrees-minutes-seconds.")
+
+  (calc-algebraic-mode nil
+   "If non-nil, numeric entry accepts whole algebraic expressions.
+If nil, algebraic expressions must be preceded by \"'\".")
+
+  (calc-incomplete-algebraic-mode nil
+   "Like calc-algebraic-mode except only affects ( and [ keys.")
+
+  (calc-symbolic-mode nil
+   "If non-nil, inexact numeric computations like sqrt(2) are postponed.
+If nil, computations on numbers always yield numbers where possible.")
 
-;; Formatting function used for non-decimal numbers.
-;;(defvar calc-radix-formatter nil)
+  (calc-matrix-mode nil
+   "If `matrix', variables are assumed to be matrix-valued.
+If a number, variables are assumed to be NxN matrices.
+If `scalar', variables are assumed to be scalar-valued.
+If nil, symbolic math routines make no assumptions about variables.")
+
+  (calc-shift-prefix nil
+   "If non-nil, shifted letter keys are prefix keys rather than normal meanings.")
+
+  (calc-window-height 7
+   "Initial height of Calculator window.")
+
+  (calc-display-trail t
+   "If non-nil, M-x calc creates a window to display Calculator trail.")
+
+  (calc-show-selections t
+   "If non-nil, selected sub-formulas are shown by obscuring rest of formula.
+If nil, selected sub-formulas are highlighted by obscuring the sub-formulas.")
+
+  (calc-use-selections t
+   "If non-nil, commands operate only on selected portions of formulas.
+If nil, selections displayed but ignored.")
+
+  (calc-assoc-selections t
+   "If non-nil, selection hides deep structure of associative formulas.")
+
+  (calc-display-working-message lots
+   "If non-nil, display \"Working...\" for potentially slow Calculator commands.")
+
+  (calc-auto-why maybe
+   "If non-nil, automatically execute a \"why\" command to explain odd results.")
+
+  (calc-timing nil
+   "If non-nil, display timing information on each slow command.")
+
+  (calc-mode-save-mode local)
+
+  (calc-standard-date-formats
+   ("N"
+    "<H:mm:SSpp >Www Mmm D, YYYY"
+    "D Mmm YYYY<, h:mm:SS>"
+    "Www Mmm BD< hh:mm:ss> YYYY"
+    "M/D/Y< H:mm:SSpp>"
+    "D.M.Y< h:mm:SS>"
+    "M-D-Y< H:mm:SSpp>"
+    "D-M-Y< h:mm:SS>"
+    "j<, h:mm:SS>"
+    "YYddd< hh:mm:ss>"))
 
-;; Label to display at left of formula.
-;;(defvar calc-left-label "")
+  (calc-autorange-units nil)
+  
+  (calc-was-keypad-mode nil)
+  
+  (calc-full-mode nil)
 
-;; Label to display at right of formula.
-;;(defvar calc-right-label "")
+  (calc-user-parse-tables nil)
 
-;; Minimum number of bits per word, if any, for binary operations in calc-mode.
-;;(defvar calc-word-size 32)
+  (calc-gnuplot-default-device "default")
 
-;; Most recently used value of M in a modulo form.
-;;(defvar calc-previous-modulo nil)
+  (calc-gnuplot-default-output "STDOUT")
 
-;; Type of simplification applied to results.
-;; If 'none, results are not simplified when pushed on the stack.
-;; If 'num, functions are simplified only when args are constant.
-;; If nil, only fast simplifications are applied.
-;; If 'binary, math-clip is applied if appropriate.
-;; If 'alg, math-simplify is applied.
-;; If 'ext, math-simplify-extended is applied.
-;; If 'units, math-simplify-units is applied.
-;;(defvar calc-simplify-mode nil)
+  (calc-gnuplot-print-device "postscript")
+  
+  (calc-gnuplot-print-output "auto")
 
-;; If non-nil, recompute evalto's automatically when necessary.
-;;(defvar calc-auto-recompute t)
+  (calc-gnuplot-geometry nil)
 
-;; If non-nil, display shows unformatted Lisp exprs.  (For debugging)
-;;(defvar calc-display-raw nil)
+  (calc-graph-default-resolution 15)
 
-;; Number of digits of internal precision for calc-mode calculations.
-;;(defvar calc-internal-prec 12)
+  (calc-graph-default-resolution-3d 5)
+  
+  (calc-invocation-macro nil)
 
-;; If non-nil, next operation is Inverse.
-;;(defvar calc-inverse-flag nil)
+  (calc-show-banner t
+   "*If non-nil, show a friendly greeting above the stack."))
+  "List of variables (and default values) used in customizing GNU Calc.")
 
-;; If non-nil, next operation is Hyperbolic.
-;;(defvar calc-hyperbolic-flag nil)
-
-;; If non-nil, next operation should not remove its arguments from stack.
-;;(defvar calc-keep-args-flag nil)
-
-;; If deg, angles are in degrees; if rad, angles are in radians.
-;; If hms, angles are in degrees-minutes-seconds.
-;;(defvar calc-angle-mode 'deg)
-
-;; If non-nil, numeric entry accepts whole algebraic expressions.
-;; If nil, algebraic expressions must be preceded by "'".
-;;(defvar calc-algebraic-mode nil)
-
-;; Like calc-algebraic-mode except only affects ( and [ keys.
-;;(defvar calc-incomplete-algebraic-mode nil)
-
-;; If non-nil, inexact numeric computations like sqrt(2) are postponed.
-;; If nil, computations on numbers always yield numbers where possible.
-;;(defvar calc-symbolic-mode nil)
-
-;; If 'matrix, variables are assumed to be matrix-valued.
-;; If a number, variables are assumed to be NxN matrices.
-;; If 'scalar, variables are assumed to be scalar-valued.
-;; If nil, symbolic math routines make no assumptions about variables.
-;;(defvar calc-matrix-mode nil)
-
-;; If non-nil, shifted letter keys are prefix keys rather than normal meanings.
-;;(defvar calc-shift-prefix nil)
-
-;; Initial height of Calculator window.
-;;(defvar calc-window-height 7)
-
-;; If non-nil, M-x calc creates a window to display Calculator trail.
-;;(defvar calc-display-trail t)
-
-;; If non-nil, selected sub-formulas are shown by obscuring rest of formula.
-;; If nil, selected sub-formulas are highlighted by obscuring the sub-formulas.
-;;(defvar calc-show-selections t)
-
-;; If non-nil, commands operate only on selected portions of formulas.
-;; If nil, selections displayed but ignored.
-;;(defvar calc-use-selections t)
-
-;; If non-nil, selection hides deep structure of associative formulas.
-;;(defvar calc-assoc-selections t)
-
-;; If non-nil, display "Working..." for potentially slow Calculator commands.
-;;(defvar calc-display-working-message 'lots)
-
-;; If non-nil, automatically execute a "why" command to explain odd results.
-;;(defvar calc-auto-why nil)
-
-;; If non-nil, display timing information on each slow command.
-;;(defvar calc-timing nil)
-
-;; Floating-point numbers with this positive exponent or higher above the
-;; current precision are displayed in scientific notation in calc-mode.
-(defvar calc-display-sci-high 0)
-
-;; Floating-point numbers with this negative exponent or lower are displayed
-;; scientific notation in calc-mode.
-(defvar calc-display-sci-low -3)
-
-
-;; List of used-defined strings to append to Calculator mode line.
-(defvar calc-other-modes nil)
-
-;; List of strings for Y prefix help.
-(defvar calc-Y-help-msgs nil)
-
-;; t if calc-settings-file has been loaded yet.
-(defvar calc-loaded-settings-file nil)
-
-
-
-(defconst calc-mode-var-list '((calc-always-load-extensions nil)
-                              (calc-mode-save-mode local)
-                              (calc-line-numbering t)
-                              (calc-line-breaking t)
-                              (calc-display-just nil)
-                              (calc-display-origin nil)
-                              (calc-left-label "")
-                              (calc-right-label "")
-                              (calc-number-radix 10)
-                              (calc-leading-zeros nil)
-                              (calc-group-digits nil)
-                              (calc-group-char ",")
-                              (calc-point-char ".")
-                              (calc-frac-format (":" nil))
-                              (calc-prefer-frac nil)
-                              (calc-hms-format "%s@ %s' %s\"")
-                              (calc-date-format ((H ":" mm C SS pp " ")
-                                                 Www " " Mmm " " D ", " YYYY))
-                              (calc-standard-date-formats
-                               ("N"
-                                "<H:mm:SSpp >Www Mmm D, YYYY"
-                                "D Mmm YYYY<, h:mm:SS>"
-                                "Www Mmm BD< hh:mm:ss> YYYY"
-                                "M/D/Y< H:mm:SSpp>"
-                                "D.M.Y< h:mm:SS>"
-                                "M-D-Y< H:mm:SSpp>"
-                                "D-M-Y< h:mm:SS>"
-                                "j<, h:mm:SS>"
-                                "YYddd< hh:mm:ss>"))
-                              (calc-float-format (float 0))
-                              (calc-full-float-format (float 0))
-                              (calc-complex-format nil)
-                              (calc-matrix-just center)
-                              (calc-full-vectors t)
-                              (calc-full-trail-vectors t)
-                              (calc-break-vectors nil)
-                              (calc-vector-commas ",")
-                              (calc-vector-brackets "[]")
-                              (calc-matrix-brackets (R O))
-                              (calc-complex-mode cplx)
-                              (calc-infinite-mode nil)
-                              (calc-display-strings nil)
-                              (calc-simplify-mode nil)
-                              (calc-auto-recompute t)
-                              (calc-word-size 32)
-                              (calc-previous-modulo nil)
-                              (calc-display-raw nil)
-                              (calc-internal-prec 12)
-                              (calc-angle-mode deg)
-                              (calc-algebraic-mode nil)
-                              (calc-incomplete-algebraic-mode nil)
-                              (calc-symbolic-mode nil)
-                              (calc-matrix-mode nil)
-                              (calc-autorange-units nil)
-                              (calc-shift-prefix nil)
-                              (calc-window-height 7)
-                              (calc-was-keypad-mode nil)
-                              (calc-full-mode nil)
-                              (calc-language nil)
-                              (calc-language-option nil)
-                              (calc-user-parse-tables nil)
-                              (calc-show-selections t)
-                              (calc-use-selections t)
-                              (calc-assoc-selections t)
-                              (calc-display-trail t)
-                              (calc-display-working-message lots)
-                              (calc-auto-why 'maybe)
-                              (calc-timing nil)
-                              (calc-gnuplot-default-device "default")
-                              (calc-gnuplot-default-output "STDOUT")
-                              (calc-gnuplot-print-device "postscript")
-                              (calc-gnuplot-print-output "auto")
-                              (calc-gnuplot-geometry nil)
-                              (calc-graph-default-resolution 15)
-                              (calc-graph-default-resolution-3d 5)
-                              (calc-invocation-macro nil)
-                              (calc-show-banner t)))
+(mapcar (function (lambda (v)
+                    (or (boundp (car v))
+                        (set (car v) (nth 1 v)))
+                    (if (nth 2 v)
+                        (put (car v) 'variable-documentation (nth 2 v)))))
+        calc-mode-var-list)
 
 (defconst calc-local-var-list '(calc-stack
                                calc-stack-top
@@ -642,25 +652,31 @@ This can safely be nil as long as the Calc files are on the load-path.")
                                calc-word-size
                                calc-internal-prec))
 
+(defvar calc-mode-hook nil
+  "Hook run when entering calc-mode.")
 
-(defun calc-init-base ()
+(defvar calc-trail-mode-hook nil
+  "Hook run when entering calc-trail-mode.")
 
-  ;; Verify that Calc is running on the right kind of system.
-  (setq calc-emacs-type-epoch (and (fboundp 'epoch::version) epoch::version)
-       calc-emacs-type-19 (not (or calc-emacs-type-epoch
-                                   (string-lessp emacs-version "19")))
-       calc-emacs-type-lucid (not (not (string-match "Lucid" emacs-version)))
-       calc-emacs-type-gnu19 (and calc-emacs-type-19
-                                  (not calc-emacs-type-lucid)))
+(defvar calc-start-hook nil
+  "Hook run when calc is started.")
 
-  ;; Set up the standard keystroke (M-#) to run the Calculator, if that key
-  ;; has not yet been bound to anything.  For best results, the user should
-  ;; do this before Calc is even loaded, so that M-# can auto-load Calc.
-  (or (global-key-binding "\e#")
-      (global-set-key "\e#" 'calc-dispatch))
+(defvar calc-end-hook nil
+  "Hook run when calc is quit.")
 
-  ;; Set up the autoloading linkage.
-  (let ((name (and (fboundp 'calc-dispatch)
+(defvar calc-load-hook nil
+  "Hook run when calc.el is loaded.")
+
+;; Verify that Calc is running on the right kind of system.
+(defvar calc-emacs-type-lucid (not (not (string-match "Lucid" emacs-version))))
+
+;; Set up the standard keystroke (M-#) to run the Calculator, if that key
+;; has not yet been bound to anything.  For best results, the user should
+;; do this before Calc is even loaded, so that M-# can auto-load Calc.
+(or (global-key-binding "\e#") (global-set-key "\e#" 'calc-dispatch))
+
+;; Set up the autoloading linkage.
+(let ((name (and (fboundp 'calc-dispatch)
                   (eq (car-safe (symbol-function 'calc-dispatch)) 'autoload)
                   (nth 1 (symbol-function 'calc-dispatch))))
        (p load-path))
@@ -695,152 +711,147 @@ This can safely be nil as long as the Calc files are on the load-path.")
                                    (list (directory-file-name
                                           calc-autoload-directory)))))))
 
-  ;; The following modes use specially-formatted data.
-  (put 'calc-mode 'mode-class 'special)
-  (put 'calc-trail-mode 'mode-class 'special)
-  
-  ;; Define "inexact-result" as an e-lisp error symbol.
-  (put 'inexact-result 'error-conditions '(error inexact-result calc-error))
-  (put 'inexact-result 'error-message "Calc internal error (inexact-result)")
-  
-  ;; Define "math-overflow" and "math-underflow" as e-lisp error symbols.
-  (put 'math-overflow 'error-conditions '(error math-overflow calc-error))
-  (put 'math-overflow 'error-message "Floating-point overflow occurred")
-  (put 'math-underflow 'error-conditions '(error math-underflow calc-error))
-  (put 'math-underflow 'error-message "Floating-point underflow occurred")
-  
-  (setq calc-version "2.02g"
-       calc-version-date "Mon Nov 19 2001"
-       calc-trail-pointer nil          ; "Current" entry in trail buffer.
-        calc-trail-overlay nil         ; Value of overlay-arrow-string.
-        calc-undo-list nil             ; List of previous operations for undo.
-        calc-redo-list nil             ; List of recent undo operations.
-        calc-main-buffer nil           ; Pointer to Calculator buffer.
-       calc-trail-buffer nil           ; Pointer to Calc Trail buffer.
-        calc-why nil                   ; Explanations of most recent errors.
-        calc-next-why nil
-       calc-inverse-flag nil
-       calc-hyperbolic-flag nil
-       calc-keep-args-flag nil
-       calc-function-open "("
-       calc-function-close ")"
-       calc-language-output-filter nil
-       calc-language-input-filter nil
-       calc-radix-formatter nil
-        calc-last-kill nil             ; Last number killed in calc-mode.
-        calc-previous-alg-entry nil    ; Previous algebraic entry.
-        calc-dollar-values nil         ; Values to be used for '$'.
-        calc-dollar-used nil           ; Highest order of '$' that occurred.
-       calc-hashes-used nil            ; Highest order of '#' that occurred.
-        calc-quick-prev-results nil    ; Previous results from Quick Calc.
-       calc-said-hello nil             ; Has welcome message been said yet?
-       calc-executing-macro nil        ; Kbd macro executing from "K" key.
-       calc-any-selections nil         ; Nil means no selections present.
-       calc-help-phase 0               ; Count of consecutive "?" keystrokes.
-       calc-full-help-flag nil         ; Executing calc-full-help?
-       calc-refresh-count 0            ; Count of calc-refresh calls.
-       calc-display-dirty nil
-       calc-prepared-composition nil
-       calc-selection-cache-default-entry nil
-       calc-embedded-info nil
-       calc-embedded-active nil
-       calc-standalone-flag nil
-       var-EvalRules nil
-       math-eval-rules-cache-tag t
-       math-radix-explicit-format t
-       math-expr-function-mapping nil
-       math-expr-variable-mapping nil
-       math-read-expr-quotes nil
-       math-working-step nil
-       math-working-step-2 nil
-        var-i '(special-const (math-imaginary 1))
-        var-pi '(special-const (math-pi))
-        var-e '(special-const (math-e))
-       var-phi '(special-const (math-phi))
-        var-gamma '(special-const (math-gamma-const))
-       var-Modes '(special-const (math-get-modes-vec)))
-
-  (mapcar (function (lambda (v) (or (boundp (car v)) (set (car v) (nth 1 v)))))
-         calc-mode-var-list)
-  (mapcar (function (lambda (v) (or (boundp v) (set v nil))))
+;; The following modes use specially-formatted data.
+(put 'calc-mode 'mode-class 'special)
+(put 'calc-trail-mode 'mode-class 'special)
+
+;; Define "inexact-result" as an e-lisp error symbol.
+(put 'inexact-result 'error-conditions '(error inexact-result calc-error))
+(put 'inexact-result 'error-message "Calc internal error (inexact-result)")
+
+;; Define "math-overflow" and "math-underflow" as e-lisp error symbols.
+(put 'math-overflow 'error-conditions '(error math-overflow calc-error))
+(put 'math-overflow 'error-message "Floating-point overflow occurred")
+(put 'math-underflow 'error-conditions '(error math-underflow calc-error))
+(put 'math-underflow 'error-message "Floating-point underflow occurred")
+
+(defconst calc-version "2.02g")
+(defconst calc-version-date "Mon Nov 19 2001")
+(defvar calc-trail-pointer nil)                ; "Current" entry in trail buffer.
+(defvar calc-trail-overlay nil)                ; Value of overlay-arrow-string.
+(defvar calc-undo-list nil)            ; List of previous operations for undo.
+(defvar calc-redo-list nil)            ; List of recent undo operations.
+(defvar calc-main-buffer nil)          ; Pointer to Calculator buffer.
+(defvar calc-trail-buffer nil)         ; Pointer to Calc Trail buffer.
+(defvar calc-why nil)                  ; Explanations of most recent errors.
+(defvar calc-next-why nil)
+(defvar calc-inverse-flag nil
+  "If non-nil, next operation is Inverse.")
+(defvar calc-hyperbolic-flag nil
+  "If non-nil, next operation is Hyperbolic.")
+(defvar calc-keep-args-flag nil
+  "If non-nil, next operation should not remove its arguments from stack.")
+(defvar calc-function-open "("
+  "Open-parenthesis string for function call notation.")
+(defvar calc-function-close ")"
+  "Close-parenthesis string for function call notation.")
+(defvar calc-language-output-filter nil
+  "Function through which to pass strings after formatting.")
+(defvar calc-language-input-filter nil
+  "Function through which to pass strings before parsing.")
+(defvar calc-radix-formatter nil
+  "Formatting function used for non-decimal numbers.")
+
+(defvar calc-last-kill nil)            ; Last number killed in calc-mode.
+(defvar calc-previous-alg-entry nil)   ; Previous algebraic entry.
+(defvar calc-dollar-values nil)                ; Values to be used for '$'.
+(defvar calc-dollar-used nil)          ; Highest order of '$' that occurred.
+(defvar calc-hashes-used nil)          ; Highest order of '#' that occurred.
+(defvar calc-quick-prev-results nil)   ; Previous results from Quick Calc.
+(defvar calc-said-hello nil)           ; Has welcome message been said yet?
+(defvar calc-executing-macro nil)      ; Kbd macro executing from "K" key.
+(defvar calc-any-selections nil)       ; Nil means no selections present.
+(defvar calc-help-phase 0)             ; Count of consecutive "?" keystrokes.
+(defvar calc-full-help-flag nil)       ; Executing calc-full-help?
+(defvar calc-refresh-count 0)          ; Count of calc-refresh calls.
+(defvar calc-display-dirty nil)
+(defvar calc-prepared-composition nil)
+(defvar calc-selection-cache-default-entry nil)
+(defvar calc-embedded-info nil)
+(defvar calc-embedded-active nil)
+(defvar calc-standalone-flag nil)
+(defvar var-EvalRules nil)
+(defvar math-eval-rules-cache-tag t)
+(defvar math-radix-explicit-format t)
+(defvar math-expr-function-mapping nil)
+(defvar math-expr-variable-mapping nil)
+(defvar math-read-expr-quotes nil)
+(defvar math-working-step nil)
+(defvar math-working-step-2 nil)
+(defvar var-i '(special-const (math-imaginary 1)))
+(defvar var-pi '(special-const (math-pi)))
+(defvar var-e '(special-const (math-e)))
+(defvar var-phi '(special-const (math-phi)))
+(defvar var-gamma '(special-const (math-gamma-const)))
+(defvar var-Modes '(special-const (math-get-modes-vec)))
+
+(mapcar (lambda (v) (or (boundp v) (set v nil)))
          calc-local-var-list)
 
-  (unless (boundp 'calc-mode-map)
-    (setq calc-mode-map (make-keymap))
-    (suppress-keymap calc-mode-map t)
-    (define-key calc-mode-map "+" 'calc-plus)
-    (define-key calc-mode-map "-" 'calc-minus)
-    (define-key calc-mode-map "*" 'calc-times)
-    (define-key calc-mode-map "/" 'calc-divide)
-    (define-key calc-mode-map "%" 'calc-mod)
-    (define-key calc-mode-map "&" 'calc-inv)
-    (define-key calc-mode-map "^" 'calc-power)
-    (define-key calc-mode-map "\M-%" 'calc-percent)
-    (define-key calc-mode-map "e" 'calcDigit-start)
-    (define-key calc-mode-map "i" 'calc-info)
-    (define-key calc-mode-map "n" 'calc-change-sign)
-    (define-key calc-mode-map "q" 'calc-quit)
-    (define-key calc-mode-map "Y" 'nil)
-    (define-key calc-mode-map "Y?" 'calc-shift-Y-prefix-help)
-    (define-key calc-mode-map "?" 'calc-help)
-    (define-key calc-mode-map " " 'calc-enter)
-    (define-key calc-mode-map "'" 'calc-algebraic-entry)
-    (define-key calc-mode-map "$" 'calc-auto-algebraic-entry)
-    (define-key calc-mode-map "\"" 'calc-auto-algebraic-entry)
-    (define-key calc-mode-map "\t" 'calc-roll-down)
-    (define-key calc-mode-map "\M-\t" 'calc-roll-up)
-    (define-key calc-mode-map "\C-m" 'calc-enter)
-    (define-key calc-mode-map "\M-\C-m" 'calc-last-args-stub)
-    (define-key calc-mode-map "\C-j" 'calc-over)
-
-    (mapcar (function
-            (lambda (x)
-              (define-key calc-mode-map (char-to-string x) 'undefined)))
-           "lOW")
-    (mapcar (function
-            (lambda (x)
-              (define-key calc-mode-map (char-to-string x)
-                'calc-missing-key)))
-           (concat "ABCDEFGHIJKLMNPQRSTUVXZabcdfghjkmoprstuvwxyz"
-                   ":\\|!()[]<>{},;=~`\C-k\M-k\C-w\M-w\C-y\C-_"))
-    (mapcar (function
-            (lambda (x)
-              (define-key calc-mode-map (char-to-string x) 'calcDigit-start)))
-           "_0123456789.#@")
-
-    (setq calc-digit-map (make-keymap))
+(defvar calc-mode-map
+  (let ((map (make-keymap)))
+    (suppress-keymap map t)
+    (define-key map "+" 'calc-plus)
+    (define-key map "-" 'calc-minus)
+    (define-key map "*" 'calc-times)
+    (define-key map "/" 'calc-divide)
+    (define-key map "%" 'calc-mod)
+    (define-key map "&" 'calc-inv)
+    (define-key map "^" 'calc-power)
+    (define-key map "\M-%" 'calc-percent)
+    (define-key map "e" 'calcDigit-start)
+    (define-key map "i" 'calc-info)
+    (define-key map "n" 'calc-change-sign)
+    (define-key map "q" 'calc-quit)
+    (define-key map "Y" 'nil)
+    (define-key map "Y?" 'calc-shift-Y-prefix-help)
+    (define-key map "?" 'calc-help)
+    (define-key map " " 'calc-enter)
+    (define-key map "'" 'calc-algebraic-entry)
+    (define-key map "$" 'calc-auto-algebraic-entry)
+    (define-key map "\"" 'calc-auto-algebraic-entry)
+    (define-key map "\t" 'calc-roll-down)
+    (define-key map "\M-\t" 'calc-roll-up)
+    (define-key map "\C-m" 'calc-enter)
+    (define-key map "\M-\C-m" 'calc-last-args-stub)
+    (define-key map "\C-j" 'calc-over)
+
+    (mapc (lambda (x) (define-key map (char-to-string x) 'undefined))
+         "lOW")
+    (mapc (lambda (x) (define-key map (char-to-string x) 'calc-missing-key))
+         (concat "ABCDEFGHIJKLMNPQRSTUVXZabcdfghjkmoprstuvwxyz"
+                 ":\\|!()[]<>{},;=~`\C-k\M-k\C-w\M-w\C-y\C-_"))
+    (mapc (lambda (x) (define-key map (char-to-string x) 'calcDigit-start))
+         "_0123456789.#@")
+    map))
+
+(defvar calc-digit-map
+  (let ((map (make-keymap)))
     (if calc-emacs-type-lucid
        (map-keymap (function
                     (lambda (keys bind)
-                      (define-key calc-digit-map keys
+                      (define-key map keys
                         (if (eq bind 'undefined)
                             'undefined 'calcDigit-nondigit))))
                    calc-mode-map)
-      (let ((cmap (if calc-emacs-type-19 (nth 1 calc-mode-map) calc-mode-map))
-           (dmap (if calc-emacs-type-19 (nth 1 calc-digit-map)
-                   calc-digit-map))
+      (let ((cmap (nth 1 calc-mode-map))
+           (dmap (nth 1 map))
            (i 0))
        (while (< i 128)
          (aset dmap i
                (if (eq (aref cmap i) 'undefined)
                    'undefined 'calcDigit-nondigit))
          (setq i (1+ i)))))
-    (mapcar (function
-            (lambda (x)
-              (define-key calc-digit-map (char-to-string x)
-                'calcDigit-key)))
+    (mapcar (lambda (x) (define-key map (char-to-string x) 'calcDigit-key))
            "_0123456789.e+-:n#@oh'\"mspM")
-    (mapcar (function
-            (lambda (x)
-              (define-key calc-digit-map (char-to-string x)
-                'calcDigit-letter)))
+    (mapcar (lambda (x) (define-key map (char-to-string x) 'calcDigit-letter))
            "abcdfgijklqrtuvwxyzABCDEFGHIJKLNOPQRSTUVWXYZ")
-    (define-key calc-digit-map "'" 'calcDigit-algebraic)
-    (define-key calc-digit-map "`" 'calcDigit-edit)
-    (define-key calc-digit-map "\C-g" 'abort-recursive-edit)
+    (define-key map "'" 'calcDigit-algebraic)
+    (define-key map "`" 'calcDigit-edit)
+    (define-key map "\C-g" 'abort-recursive-edit)
+    map))
 
-    (mapcar (function
-            (lambda (x)
+(mapcar (lambda (x)
               (condition-case err
                   (progn
                     (define-key calc-digit-map x 'calcDigit-backspace)
@@ -856,22 +867,21 @@ This can safely be nil as long as the Calc files are on the load-path.")
                             (vconcat "\e" x))
                         (concat "\e" x))
                       'calc-pop-above))
-                (error nil))))
+           (error nil)))
            (if calc-scan-for-dels
                (append (where-is-internal 'delete-backward-char global-map)
                        (where-is-internal 'backward-delete-char global-map)
                        '("\C-d"))
              '("\177" "\C-d")))
 
-    (setq calc-dispatch-map (make-keymap))
-    (mapcar (function
-            (lambda (x)
-              (define-key calc-dispatch-map (char-to-string (car x)) (cdr x))
+(defvar calc-dispatch-map
+  (let ((map (make-keymap)))
+    (mapcar (lambda (x)
+             (define-key map (char-to-string (car x)) (cdr x))
               (when (string-match "abcdefhijklnopqrstuwxyz"
                                   (char-to-string (car x)))
-                (define-key calc-dispatch-map
-                  (char-to-string (- (car x) ?a -1)) (cdr x)))
-              (define-key calc-dispatch-map (format "\e%c" (car x)) (cdr x))))
+               (define-key map (char-to-string (- (car x) ?a -1)) (cdr x)))
+             (define-key map (format "\e%c" (car x)) (cdr x)))
            '( ( ?a . calc-embedded-activate )
               ( ?b . calc-big-or-small )
               ( ?c . calc )
@@ -905,51 +915,46 @@ This can safely be nil as long as the Calc files are on the load-path.")
               ( ?0 . calc-reset )
               ( ?# . calc-same-interface )
               ( ?? . calc-dispatch-help ) ))
-    )
+    map))
 
-  (autoload 'calc-extensions "calc-ext")
-  (autoload 'calc-need-macros "calc-macs")
+(autoload 'calc-extensions "calc-ext")
+(autoload 'calc-need-macros "calc-macs")
 
 ;;;; (Autoloads here)
-  (mapcar (function (lambda (x)
-    (mapcar (function (lambda (func)
-      (autoload func (car x)))) (cdr x))))
+(mapcar
+ (lambda (x) (dolist (func (cdr x)) (autoload func (car x))))
     '(
 
  ("calc-aent" calc-Need-calc-aent calc-alg-digit-entry calc-alg-entry
-calc-check-user-syntax calc-do-alg-entry calc-do-calc-eval
-calc-do-quick-calc calc-match-user-syntax math-build-parse-table
-math-find-user-tokens math-read-expr-list math-read-exprs math-read-if
-math-read-token math-remove-dashes)
-
- ("calc-misc" calc-Need-calc-misc 
-calc-do-handle-whys calc-do-refresh calc-num-prefix-name
-calc-record-list calc-record-why calc-report-bug calc-roll-down-stack
-calc-roll-up-stack calc-temp-minibuffer-message calcFunc-floor
-calcFunc-inv calcFunc-trunc math-concat math-constp math-div2
-math-div2-bignum math-do-working math-evenp math-fixnatnump
-math-fixnump math-floor math-imod math-ipow math-looks-negp math-mod
-math-negp math-posp math-pow math-read-radix-digit math-reject-arg
-math-trunc math-zerop)
-
-))
-
-  (mapcar (function (lambda (x)
-    (mapcar (function (lambda (cmd)
-      (autoload cmd (car x) nil t))) (cdr x))))
+    calc-check-user-syntax calc-do-alg-entry calc-do-calc-eval
+    calc-do-quick-calc calc-match-user-syntax math-build-parse-table
+    math-find-user-tokens math-read-expr-list math-read-exprs math-read-if
+    math-read-token math-remove-dashes)
+
+ ("calc-misc" calc-Need-calc-misc
+    calc-do-handle-whys calc-do-refresh calc-num-prefix-name
+    calc-record-list calc-record-why calc-report-bug calc-roll-down-stack
+    calc-roll-up-stack calc-temp-minibuffer-message calcFunc-floor
+    calcFunc-inv calcFunc-trunc math-concat math-constp math-div2
+    math-div2-bignum math-do-working math-evenp math-fixnatnump
+    math-fixnump math-floor math-imod math-ipow math-looks-negp math-mod
+    math-negp math-posp math-pow math-read-radix-digit math-reject-arg
+    math-trunc math-zerop)))
+
+(mapcar
+ (lambda (x) (dolist (cmd (cdr x)) (autoload cmd (car x) nil t)))
     '(
 
  ("calc-aent" calc-algebraic-entry calc-auto-algebraic-entry
-calcDigit-algebraic calcDigit-edit)
+    calcDigit-algebraic calcDigit-edit)
 
  ("calc-misc" another-calc calc-big-or-small calc-dispatch-help
-calc-help calc-info calc-info-summary calc-inv calc-last-args-stub
-calc-missing-key calc-mod calc-other-window calc-over calc-percent
-calc-pop-above calc-power calc-roll-down calc-roll-up
-calc-shift-Y-prefix-help calc-tutorial calcDigit-letter
-report-calc-bug))))
-
-(calc-init-base)
+    calc-help calc-info calc-info-goto-node calc-info-summary calc-inv 
+    calc-last-args-stub
+    calc-missing-key calc-mod calc-other-window calc-over calc-percent
+    calc-pop-above calc-power calc-roll-down calc-roll-up
+    calc-shift-Y-prefix-help calc-tutorial calcDigit-letter
+    report-calc-bug)))
 
 
 ;;;###autoload (global-set-key "\e#" 'calc-dispatch)
@@ -1000,9 +1005,7 @@ report-calc-bug))))
            (use-global-map map)
            (use-local-map nil)
            (read-key-sequence
-            (if (commandp (key-binding (if calc-emacs-type-19
-                                           (vector (cdr key))
-                                         (char-to-string (cdr key)))))
+            (if (commandp (key-binding (vector (cdr key))))
                 "" prompt2)))
        (use-global-map glob)
        (use-local-map loc)))))
@@ -1061,13 +1064,10 @@ Notations:  3.14e6     3.14 * 10^6
   (setq calc-stack-top (- (length calc-stack) calc-stack-top -1))
   (or calc-loaded-settings-file
       (null calc-settings-file)
-      (string-match "\\.emacs" calc-settings-file)
+      (equal calc-settings-file user-init-file)
       (progn
        (setq calc-loaded-settings-file t)
        (load calc-settings-file t)))   ; t = missing-ok
-  (if (and (eq window-system 'x) (boundp 'mouse-map))
-      (substitute-key-definition 'x-paste-text 'calc-x-paste-text
-                                mouse-map))
   (let ((p command-line-args))
     (while p
       (and (equal (car p) "-f")
@@ -1078,14 +1078,6 @@ Notations:  3.14e6     3.14 * 10^6
   (run-hooks 'calc-mode-hook)
   (calc-refresh t)
   (calc-set-mode-line)
-  ;; The calc-defs variable is a relic.  Use calc-define properties instead.
-  (when (and (boundp 'calc-defs)
-            calc-defs)
-    (message "Evaluating calc-defs...")
-    (calc-need-macros)
-    (eval (cons 'progn calc-defs))
-    (setq calc-defs nil)
-    (calc-set-mode-line))
   (calc-check-defines))
 
 (defvar calc-check-defines 'calc-check-defines)  ; suitable for run-hooks
@@ -1151,7 +1143,7 @@ commands given here will actually operate on the *Calculator* stack."
 ;;;###autoload
 (defun calc (&optional arg full-display interactive)
   "The Emacs Calculator.  Full documentation is listed under \"calc-mode\"."
-  (interactive "P")
+  (interactive "P\ni\np")
   (if arg
       (unless (eq arg 0)
        (calc-extensions)
@@ -1172,20 +1164,18 @@ commands given here will actually operate on the *Calculator* stack."
            (switch-to-buffer (current-buffer) t)
          (if (get-buffer-window (current-buffer))
              (select-window (get-buffer-window (current-buffer)))
-           (if (and (boundp 'calc-window-hook) calc-window-hook)
-               (run-hooks 'calc-window-hook)
-             (let ((w (get-largest-window)))
-               (if (and pop-up-windows
-                        (> (window-height w)
-                           (+ window-min-height calc-window-height 2)))
-                   (progn
-                     (setq w (split-window w
-                                           (- (window-height w)
-                                              calc-window-height 2)
-                                           nil))
-                     (set-window-buffer w (current-buffer))
-                     (select-window w))
-                 (pop-to-buffer (current-buffer)))))))
+            (let ((w (get-largest-window)))
+              (if (and pop-up-windows
+                       (> (window-height w)
+                          (+ window-min-height calc-window-height 2)))
+                  (progn
+                    (setq w (split-window w
+                                          (- (window-height w)
+                                             calc-window-height 2)
+                                          nil))
+                    (set-window-buffer w (current-buffer))
+                    (select-window w))
+                (pop-to-buffer (current-buffer))))))
        (save-excursion
          (set-buffer (calc-trail-buffer))
          (and calc-display-trail
@@ -1197,17 +1187,16 @@ commands given here will actually operate on the *Calculator* stack."
             (window-point full-display)
             (select-window full-display))
        (calc-check-defines)
-       (when (and calc-said-hello
-                  (or (interactive-p) interactive))
+       (when (and calc-said-hello interactive)
          (sit-for 2)
          (message ""))
        (setq calc-said-hello t)))))
 
 ;;;###autoload
-(defun full-calc ()
+(defun full-calc (&optional interactive)
   "Invoke the Calculator and give it a full-sized window."
-  (interactive)
-  (calc nil t (interactive-p)))
+  (interactive "p")
+  (calc nil t interactive))
 
 (defun calc-same-interface (arg)
   "Invoke the Calculator using the most recent interface (calc or calc-keypad)."
@@ -1224,8 +1213,8 @@ commands given here will actually operate on the *Calculator* stack."
          (calc arg calc-full-mode t))))))
 
 
-(defun calc-quit (&optional non-fatal)
-  (interactive)
+(defun calc-quit (&optional non-fatal interactive)
+  (interactive "i\np")
   (and calc-standalone-flag (not non-fatal)
        (save-buffers-kill-emacs nil))
   (if (and (equal (buffer-name) "*Gnuplot Trail*")
@@ -1235,7 +1224,7 @@ commands given here will actually operate on the *Calculator* stack."
       (calc-edit-cancel)
     (if (eq major-mode 'MacEdit-mode)
        (MacEdit-cancel-edit)
-      (if (and (interactive-p)
+      (if (and interactive
               calc-embedded-info
               (eq (current-buffer) (aref calc-embedded-info 0)))
          (calc-embedded nil)
@@ -1275,26 +1264,29 @@ or a list containing a character position and an error message in string form."
   (calc-do-calc-eval str separator args))
 
 ;;;###autoload
-(defun calc-keypad ()
+(defun calc-keypad (&optional interactive)
   "Invoke the Calculator in \"visual keypad\" mode.
 This is most useful in the X window system.
 In this mode, click on the Calc \"buttons\" using the left mouse button.
 Or, position the cursor manually and do M-x calc-keypad-press."
-  (interactive)
+  (interactive "p")
   (calc-extensions)
-  (calc-do-keypad calc-full-mode (interactive-p)))
+  (calc-do-keypad calc-full-mode interactive))
 
 ;;;###autoload
-(defun full-calc-keypad ()
+(defun full-calc-keypad (&optional interactive)
   "Invoke the Calculator in full-screen \"visual keypad\" mode.
 See calc-keypad for details."
-  (interactive)
+  (interactive "p")
   (calc-extensions)
-  (calc-do-keypad t (interactive-p)))
+  (calc-do-keypad t interactive))
 
 
 (defvar calc-aborted-prefix nil)
 (defvar calc-start-time nil)
+(defvar calc-command-flags)
+(defvar calc-final-point-line)
+(defvar calc-final-point-column)
 ;;; Note that modifications to this function may break calc-pass-errors.
 (defun calc-do (do-body &optional do-slow)
   (calc-check-defines)
@@ -1303,7 +1295,8 @@ See calc-keypad for details."
                               (calc-extensions)
                               (current-time-string)))
         (gc-cons-threshold (max gc-cons-threshold
-                                (if calc-timing 2000000 100000))))
+                                (if calc-timing 2000000 100000)))
+        calc-final-point-line calc-final-point-column)
     (setq calc-aborted-prefix "")
     (unwind-protect
        (condition-case err
@@ -1331,7 +1324,6 @@ See calc-keypad for details."
               (error "Computation got stuck or ran too long.  Type `M' to increase the limit")
             (setq calc-aborted-prefix nil)
             (signal (car err) (cdr err)))))
-      (setq calc-old-aborted-prefix calc-aborted-prefix)
       (when calc-aborted-prefix
        (calc-record "<Aborted>" calc-aborted-prefix))
       (and calc-start-time
@@ -1354,7 +1346,7 @@ See calc-keypad for details."
               (progn
                 (goto-line calc-final-point-line)
                 (move-to-column calc-final-point-column))
-            (save-excursion
+            (save-current-buffer
               (calc-select-buffer)
               (goto-line calc-final-point-line)
               (move-to-column calc-final-point-column))))
@@ -1623,6 +1615,7 @@ See calc-keypad for details."
                (delete-region (point) (point-max))))
            (calc-set-command-flag 'renum-stack))))))
 
+(defvar sel-mode)
 (defun calc-get-stack-element (x)
   (cond ((eq sel-mode 'entry)
         x)
@@ -1691,6 +1684,7 @@ See calc-keypad for details."
                  stack (cdr stack))))))
   (and calc-embedded-info (calc-embedded-stack-change)))
 
+(defvar calc-any-evaltos nil)
 (defun calc-refresh (&optional align)
   (interactive)
   (and (eq major-mode 'calc-mode)
@@ -1699,9 +1693,9 @@ See calc-keypad for details."
              (save-point (point))
              (save-mark (condition-case err (mark) (error nil)))
              (save-aligned (looking-at "\\.$"))
-             (thing calc-stack))
-        (setq calc-any-selections nil
-              calc-any-evaltos nil)
+             (thing calc-stack)
+             (calc-any-evaltos nil))
+        (setq calc-any-selections nil)
         (erase-buffer)
         (when calc-show-banner
           (insert (propertize "--- Emacs Calculator Mode ---\n"
@@ -1727,27 +1721,6 @@ See calc-keypad for details."
         (calc-refresh align)))
   (setq calc-refresh-count (1+ calc-refresh-count)))
 
-
-(defun calc-x-paste-text (arg)
-  "Move point to mouse position and insert window system cut buffer contents.
-If mouse is pressed in Calc window, push cut buffer contents onto the stack."
-  (x-mouse-select arg)
-  (if (memq major-mode '(calc-mode calc-trail-mode))
-      (progn
-       (calc-wrapper
-        (calc-extensions)
-        (let* ((buf (x-get-cut-buffer))
-               (val (math-read-exprs (calc-clean-newlines buf))))
-          (if (eq (car-safe val) 'error)
-              (progn
-                (setq val (math-read-exprs buf))
-                (if (eq (car-safe val) 'error)
-                    (error "%s in yanked data" (nth 2 val)))))
-          (calc-enter-result 0 "Xynk" val))))
-    (x-paste-text arg)))
-
-
-
 ;;;; The Calc Trail buffer.
 
 (defun calc-check-trail-aligned ()
@@ -1806,22 +1779,20 @@ If mouse is pressed in Calc window, push cut buffer contents onto the stack."
   val)
 
 
-(defun calc-trail-display (flag &optional no-refresh)
-  (interactive "P")
+(defun calc-trail-display (flag &optional no-refresh interactive)
+  (interactive "P\ni\np")
   (let ((win (get-buffer-window (calc-trail-buffer))))
     (if (setq calc-display-trail
              (not (if flag (memq flag '(nil 0)) win)))
        (if (null win)
            (progn
-             (if (and (boundp 'calc-trail-window-hook) calc-trail-window-hook)
-                 (run-hooks 'calc-trail-window-hook)
-               (let ((w (split-window nil (/ (* (window-width) 2) 3) t)))
-                 (set-window-buffer w calc-trail-buffer)))
+              (let ((w (split-window nil (/ (* (window-width) 2) 3) t)))
+                (set-window-buffer w calc-trail-buffer))
              (calc-wrapper
               (setq overlay-arrow-string calc-trail-overlay
                     overlay-arrow-position calc-trail-pointer)
               (or no-refresh
-                  (if (interactive-p)
+                  (if interactive
                       (calc-do-refresh)
                     (calc-refresh))))))
       (if win
@@ -1829,7 +1800,7 @@ If mouse is pressed in Calc window, push cut buffer contents onto the stack."
            (delete-window win)
            (calc-wrapper
             (or no-refresh
-                (if (interactive-p)
+                (if interactive
                     (calc-do-refresh)
                   (calc-refresh))))))))
   calc-trail-buffer)
@@ -1971,7 +1942,10 @@ If mouse is pressed in Calc window, push cut buffer contents onto the stack."
 
 
 ;;;; Reading a number using the minibuffer.
-
+(defvar calc-buffer)
+(defvar calc-prev-char)
+(defvar calc-prev-prev-char)
+(defvar calc-digit-value)
 (defun calcDigit-start ()
   (interactive)
   (calc-wrapper
@@ -2253,63 +2227,75 @@ If mouse is pressed in Calc window, push cut buffer contents onto the stack."
 ;;; Also, [Public] marks routines intended to be called from outside.
 ;;; [This notation has been neglected in many recent routines.]
 
+(defvar math-eval-rules-cache)
+(defvar math-eval-rules-cache-other)
 ;;; Reduce an object to canonical (normalized) form.  [O o; Z Z] [Public]
-(defun math-normalize (a)
+
+(defvar math-normalize-a)
+(defun math-normalize (math-normalize-a)
   (cond
-   ((not (consp a))
-    (if (integerp a)
-       (if (or (>= a 1000000) (<= a -1000000))
-           (math-bignum a)
-         a)
-      a))
-   ((eq (car a) 'bigpos)
-    (if (eq (nth (1- (length a)) a) 0)
-       (let* ((last (setq a (copy-sequence a))) (digs a))
+   ((not (consp math-normalize-a))
+    (if (integerp math-normalize-a)
+       (if (or (>= math-normalize-a 1000000) (<= math-normalize-a -1000000))
+           (math-bignum math-normalize-a)
+         math-normalize-a)
+      math-normalize-a))
+   ((eq (car math-normalize-a) 'bigpos)
+    (if (eq (nth (1- (length math-normalize-a)) math-normalize-a) 0)
+       (let* ((last (setq math-normalize-a 
+                           (copy-sequence math-normalize-a))) (digs math-normalize-a))
          (while (setq digs (cdr digs))
            (or (eq (car digs) 0) (setq last digs)))
          (setcdr last nil)))
-    (if (cdr (cdr (cdr a)))
-       a
+    (if (cdr (cdr (cdr math-normalize-a)))
+       math-normalize-a
       (cond
-       ((cdr (cdr a)) (+ (nth 1 a) (* (nth 2 a) 1000)))
-       ((cdr a) (nth 1 a))
+       ((cdr (cdr math-normalize-a)) (+ (nth 1 math-normalize-a) 
+                                        (* (nth 2 math-normalize-a) 1000)))
+       ((cdr math-normalize-a) (nth 1 math-normalize-a))
        (t 0))))
-   ((eq (car a) 'bigneg)
-    (if (eq (nth (1- (length a)) a) 0)
-       (let* ((last (setq a (copy-sequence a))) (digs a))
+   ((eq (car math-normalize-a) 'bigneg)
+    (if (eq (nth (1- (length math-normalize-a)) math-normalize-a) 0)
+       (let* ((last (setq math-normalize-a (copy-sequence math-normalize-a))) 
+               (digs math-normalize-a))
          (while (setq digs (cdr digs))
            (or (eq (car digs) 0) (setq last digs)))
          (setcdr last nil)))
-    (if (cdr (cdr (cdr a)))
-       a
+    (if (cdr (cdr (cdr math-normalize-a)))
+       math-normalize-a
       (cond
-       ((cdr (cdr a)) (- (+ (nth 1 a) (* (nth 2 a) 1000))))
-       ((cdr a) (- (nth 1 a)))
+       ((cdr (cdr math-normalize-a)) (- (+ (nth 1 math-normalize-a) 
+                                           (* (nth 2 math-normalize-a) 1000))))
+       ((cdr math-normalize-a) (- (nth 1 math-normalize-a)))
        (t 0))))
-   ((eq (car a) 'float)
-    (math-make-float (math-normalize (nth 1 a)) (nth 2 a)))
-   ((or (memq (car a) '(frac cplx polar hms date mod sdev intv vec var quote
-                            special-const calcFunc-if calcFunc-lambda
-                            calcFunc-quote calcFunc-condition
-                            calcFunc-evalto))
-       (integerp (car a))
-       (and (consp (car a)) (not (eq (car (car a)) 'lambda))))
+   ((eq (car math-normalize-a) 'float)
+    (math-make-float (math-normalize (nth 1 math-normalize-a)) 
+                     (nth 2 math-normalize-a)))
+   ((or (memq (car math-normalize-a) 
+              '(frac cplx polar hms date mod sdev intv vec var quote
+                     special-const calcFunc-if calcFunc-lambda
+                     calcFunc-quote calcFunc-condition
+                     calcFunc-evalto))
+       (integerp (car math-normalize-a))
+       (and (consp (car math-normalize-a)) 
+             (not (eq (car (car math-normalize-a)) 'lambda))))
     (calc-extensions)
-    (math-normalize-fancy a))
+    (math-normalize-fancy math-normalize-a))
    (t
     (or (and calc-simplify-mode
             (calc-extensions)
             (math-normalize-nonstandard))
-       (let ((args (mapcar 'math-normalize (cdr a))))
+       (let ((args (mapcar 'math-normalize (cdr math-normalize-a))))
          (or (condition-case err
-                 (let ((func (assq (car a) '( ( + . math-add )
-                                              ( - . math-sub )
-                                              ( * . math-mul )
-                                              ( / . math-div )
-                                              ( % . math-mod )
-                                              ( ^ . math-pow )
-                                              ( neg . math-neg )
-                                              ( | . math-concat ) ))))
+                 (let ((func 
+                         (assq (car math-normalize-a) '( ( + . math-add )
+                                                         ( - . math-sub )
+                                                         ( * . math-mul )
+                                                         ( / . math-div )
+                                                         ( % . math-mod )
+                                                         ( ^ . math-pow )
+                                                         ( neg . math-neg )
+                                                         ( | . math-concat ) ))))
                    (or (and var-EvalRules
                             (progn
                               (or (eq var-EvalRules math-eval-rules-cache-tag)
@@ -2317,51 +2303,54 @@ If mouse is pressed in Calc window, push cut buffer contents onto the stack."
                                     (calc-extensions)
                                     (math-recompile-eval-rules)))
                               (and (or math-eval-rules-cache-other
-                                       (assq (car a) math-eval-rules-cache))
+                                       (assq (car math-normalize-a) 
+                                              math-eval-rules-cache))
                                    (math-apply-rewrites
-                                    (cons (car a) args)
+                                    (cons (car math-normalize-a) args)
                                     (cdr math-eval-rules-cache)
                                     nil math-eval-rules-cache))))
                        (if func
                            (apply (cdr func) args)
-                         (and (or (consp (car a))
-                                  (fboundp (car a))
+                         (and (or (consp (car math-normalize-a))
+                                  (fboundp (car math-normalize-a))
                                   (and (not calc-extensions-loaded)
                                        (calc-extensions)
-                                       (fboundp (car a))))
-                              (apply (car a) args)))))
+                                       (fboundp (car math-normalize-a))))
+                              (apply (car math-normalize-a) args)))))
                (wrong-number-of-arguments
                 (calc-record-why "*Wrong number of arguments"
-                                 (cons (car a) args))
+                                 (cons (car math-normalize-a) args))
                 nil)
                (wrong-type-argument
-                (or calc-next-why (calc-record-why "Wrong type of argument"
-                                                   (cons (car a) args)))
+                (or calc-next-why 
+                     (calc-record-why "Wrong type of argument"
+                                      (cons (car math-normalize-a) args)))
                 nil)
                (args-out-of-range
-                (calc-record-why "*Argument out of range" (cons (car a) args))
+                (calc-record-why "*Argument out of range" 
+                                  (cons (car math-normalize-a) args))
                 nil)
                (inexact-result
                 (calc-record-why "No exact representation for result"
-                                 (cons (car a) args))
+                                 (cons (car math-normalize-a) args))
                 nil)
                (math-overflow
                 (calc-record-why "*Floating-point overflow occurred"
-                                 (cons (car a) args))
+                                 (cons (car math-normalize-a) args))
                 nil)
                (math-underflow
                 (calc-record-why "*Floating-point underflow occurred"
-                                 (cons (car a) args))
+                                 (cons (car math-normalize-a) args))
                 nil)
                (void-variable
                 (if (eq (nth 1 err) 'var-EvalRules)
                     (progn
                       (setq var-EvalRules nil)
-                      (math-normalize (cons (car a) args)))
+                      (math-normalize (cons (car math-normalize-a) args)))
                   (calc-record-why "*Variable is void" (nth 1 err)))))
-             (if (consp (car a))
+             (if (consp (car math-normalize-a))
                  (math-dimension-error)
-               (cons (car a) args))))))))
+               (cons (car math-normalize-a) args))))))))
 
 
 
@@ -2644,7 +2633,7 @@ If mouse is pressed in Calc window, push cut buffer contents onto the stack."
 (defun math-sub-bignum (a b)   ; [l l l]
   (if b
       (if a
-         (let* ((a (copy-sequence a)) (aa a) (borrow nil) sum)
+         (let* ((a (copy-sequence a)) (aa a) (borrow nil) sum diff)
            (while (and aa b)
              (if borrow
                  (if (>= (setq diff (- (car aa) (car b))) 1)
@@ -2966,7 +2955,7 @@ If mouse is pressed in Calc window, push cut buffer contents onto the stack."
 
 
 
-
+(defvar calc-selection-cache-entry)
 ;;; Format the number A as a string.  [X N; X Z] [Public]
 (defun math-format-stack-value (entry)
   (setq calc-selection-cache-entry calc-selection-cache-default-entry)
@@ -3021,30 +3010,33 @@ If mouse is pressed in Calc window, push cut buffer contents onto the stack."
     (if (eq calc-language 'big)
        (setq s (concat s "\n"))
       (when calc-line-numbering
-       (aset s 0 ?1)
-       (aset s 1 ?:)))
+       (setq s (concat "1:" (substring s 2)))))
     (setcar (cdr entry) (calc-count-lines s))
     s))
 
-(defun math-stack-value-offset (c)
+;; The variables math-svo-c, math-svo-wid and math-svo-off are local
+;; to math-stack-value-offset, but are used by math-stack-value-offset-fancy
+;; in calccomp.el.
+
+(defun math-stack-value-offset (math-svo-c)
   (let* ((num (if calc-line-numbering 4 0))
-        (wid (calc-window-width))
-        off)
+        (math-svo-wid (calc-window-width))
+        math-svo-off)
     (if calc-display-just
        (progn
          (calc-extensions)
          (math-stack-value-offset-fancy))
-      (setq off (or calc-display-origin 0))
+      (setq math-svo-off (or calc-display-origin 0))
       (when (integerp calc-line-breaking)
-       (setq wid calc-line-breaking)))
-    (cons (max (- off (length calc-left-label)) 0)
-         (+ wid num))))
+       (setq math-svo-wid calc-line-breaking)))
+    (cons (max (- math-svo-off (length calc-left-label)) 0)
+         (+ math-svo-wid num))))
 
 (defun calc-count-lines (s)
   (let ((pos 0)
        (num 1))
-    (while (setq newpos (string-match "\n" s pos))
-      (setq pos (1+ newpos)
+    (while (setq pos (string-match "\n" s pos))
+      (setq pos (1+ pos)
            num (1+ num)))
     num))
 
@@ -3418,11 +3410,8 @@ Also looks for the equivalent TeX words, \\gets and \\evalto."
           (let ((key (event-to-character event t t)))
             (or key optkey (error "Expected a plain keystroke"))
             (cons key event))))
-       (calc-emacs-type-gnu19
-        (let ((key (read-event)))
-          (cons key key)))
        (t
-        (let ((key (read-char)))
+        (let ((key (read-event)))
           (cons key key)))))
 
 (defun calc-unread-command (&optional input)
@@ -3433,7 +3422,7 @@ Also looks for the equivalent TeX words, \\gets and \\evalto."
     (push (or input last-command-event) unread-command-events)))
 
 (defun calc-clear-unread-commands ()
-  (if (featurep 'xemacs) 
+  (if (featurep 'xemacs)
        (calc-emacs-type-lucid (setq unread-command-event nil))
     (setq unread-command-events nil)))
 
@@ -3444,4 +3433,5 @@ Also looks for the equivalent TeX words, \\gets and \\evalto."
 
 (run-hooks 'calc-load-hook)
 
+;;; arch-tag: 0c3b170c-4ce6-4eaf-8d9b-5834d1fe938f
 ;;; calc.el ends here