-;; Calculator for GNU Emacs, part I
-;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
-;; Written by Dave Gillespie, daveg@synaptics.com.
+;;; calc.el --- the GNU Emacs calculator
+
+;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002 Free Software Foundation, Inc.
+
+;; Author: David Gillespie <daveg@synaptics.com>
+;; Maintainer: Colin Walters <walters@debian.org>
+;; Keywords: convenience, extensions
+;; Version: 2.02g
;; This file is part of GNU Emacs.
;; file named COPYING. Among other things, the copyright notice
;; and this notice must be preserved on all copies.
-
-
-;;; Calc is split into many files. This file is the main entry point.
-;;; This file includes autoload commands for various other basic Calc
-;;; facilities. The more advanced features are based in calc-ext, which
-;;; in turn contains autoloads for the rest of the Calc files. This
-;;; odd set of interactions is designed to make Calc's loading time
-;;; be as short as possible when only simple calculations are needed.
-
-;;; Suggested usage:
-;;;
-;;; (autoload 'calc-dispatch "calc" "Emacs Calculator" t nil)
-;;; (global-set-key "\e#" 'calc-dispatch)
-;;; Type `M-# M-#' to start.
-;;;
-;;; The Calc home directory must be added to the Emacs load-path:
-;;;
-;;; (setq load-path (cons "/x/y/z/calc" load-path))
-;;;
-;;; where "/x/y/z/calc" represents the full name of the Calc home directory.
-;;;
-;;; See the file INSTALL for a complete list of recommeded autoload
-;;; commands (though only calc-dispatch is absolutely necessary).
-
-
-;;; Author's address:
-;;; Dave Gillespie, daveg@synaptics.com, uunet!synaptx!daveg.
-;;; Synaptics, Inc., 2698 Orchard Parkway, San Jose, CA 95134.
-;;;
-;;; The old address daveg@csvax.cs.caltech.edu will continue to
-;;; work for the foreseeable future.
-;;;
-;;; The latest version of Calc is always available from anonymous FTP
-;;; on csvax.cs.caltech.edu [131.215.131.131]; look in ~ftp/pub/calc*.
-;;; It should also be available on prep.ai.mit.edu.
-;;;
-;;; Bug reports and suggestions are always welcome!
-
-
-;;; All functions, macros, and Lisp variables defined here begin with one
-;;; of the prefixes "math", "Math", or "calc", with the exceptions of
-;;; "full-calc", "full-calc-keypad", "another-calc", "quick-calc",
-;;; "report-calc-bug", and "defmath". User-accessible variables begin
-;;; with "var-".
-
-
+;;; Commentary:
+
+;; Calc is split into many files. This file is the main entry point.
+;; This file includes autoload commands for various other basic Calc
+;; facilities. The more advanced features are based in calc-ext, which
+;; in turn contains autoloads for the rest of the Calc files. This
+;; odd set of interactions is designed to make Calc's loading time
+;; be as short as possible when only simple calculations are needed.
+
+;; Original author's address:
+;; Dave Gillespie, daveg@synaptics.com, uunet!synaptx!daveg.
+;; Synaptics, Inc., 2698 Orchard Parkway, San Jose, CA 95134.
+;;
+;; The old address daveg@csvax.cs.caltech.edu will continue to
+;; work for the foreseeable future.
+;;
+;; Bug reports and suggestions are always welcome! (Type M-x
+;; report-calc-bug to send them).
+
+;; All functions, macros, and Lisp variables defined here begin with one
+;; of the prefixes "math", "Math", or "calc", with the exceptions of
+;; "full-calc", "full-calc-keypad", "another-calc", "quick-calc",
+;; "report-calc-bug", and "defmath". User-accessible variables begin
+;; with "var-".
+
+;;; TODO:
+
+;; Fix rewrite mechanism to do less gratuitous rearrangement of terms.
+;; Implement a pattern-based "refers" predicate.
+;;
+;; Make it possible to Undo a selection command.
+;; Figure out how to allow selecting rows of matrices.
+;; If cursor was in selection before, move it after j n, j p, j L, etc.
+;; Consider reimplementing calc-delete-selection using rewrites.
+;;
+;; Implement line-breaking in non-flat compositions (is this desirable?).
+;; Implement matrix formatting with multi-line components.
+;;
+;; Have "Z R" define a user command based on a set of rewrite rules.
+;; Support "incf" and "decf" in defmath definitions.
+;; Have defmath generate calls to calc-binary-op or calc-unary-op.
+;; Make some way to define algebraic functions using keyboard macros.
+;;
+;; Allow calc-word-size=0 => Common Lisp-style signed bitwise arithmetic.
+;; Consider digamma function (and thus arb. prec. Euler's gamma constant).
+;; May as well make continued-fractions stuff available to the user.
+;;
+;; How about matrix eigenvalues, SVD, pseudo-inverse, etc.?
+;; Should cache matrix inverses as well as decompositions.
+;; If dividing by a non-square matrix, use least-squares automatically.
+;; Consider supporting matrix exponentials.
+;;
+;; Have ninteg detect and work around singularities at the endpoints.
+;; Use an adaptive subdivision algorithm for ninteg.
+;; Provide nsum and nprod to go along with ninteg.
+;;
+;; Handle TeX-mode parsing of \matrix{ ... } where ... contains braces.
+;; Support AmS-TeX's \{d,t,}frac, \{d,t,}binom notations.
+;; Format and parse sums and products in Eqn and Math modes.
+;;
+;; Get math-read-big-expr to read sums, products, etc.
+;; Change calc-grab-region to use math-read-big-expr.
+;; Have a way to define functions using := in Embedded Mode.
+;;
+;; Support polar plotting with GNUPLOT.
+;; Make a calc-graph-histogram function.
+;;
+;; Replace hokey formulas for complex functions with formulas designed
+;; to minimize roundoff while maintaining the proper branch cuts.
+;; Test accuracy of advanced math functions over whole complex plane.
+;; Extend Bessel functions to provide arbitrary precision.
+;; Extend advanced math functions to handle error forms and intervals.
+;; Provide a better implementation for math-sin-cos-raw.
+;; Provide a better implementation for math-hypot.
+;; Provide a better implementation for math-make-frac.
+;; Provide a better implementation for calcFunc-prfac.
+;; Provide a better implementation for calcFunc-factor.
+;;
+;; Provide more examples in the tutorial section of the manual.
+;; Cover in the tutorial: simplification modes, declarations,
+;; bitwise stuff, selections, matrix mapping, financial functions.
+;; Provide more Lisp programming examples in the manual.
+;; Finish the Internals section of the manual (and bring it up to date).
+;;
+;; Tim suggests adding spreadsheet-like features.
+;; Implement language modes for Gnuplot, Lisp, Ada, APL, ...?
+;;
+;; For atan series, if x > tan(pi/12) (about 0.268) reduce using the identity
+;; atan(x) = atan((x * sqrt(3) - 1) / (sqrt(3) + x)) + pi/6.
+;;
+;; A better integration algorithm:
+;; Use breadth-first instead of depth-first search, as follows:
+;; The integral cache allows unfinished integrals in symbolic notation
+;; on the righthand side. An entry with no unfinished integrals on the
+;; RHS is "complete"; references to it elsewhere are replaced by the
+;; integrated value. More than one cache entry for the same integral
+;; may exist, though if one becomes complete, the others may be deleted.
+;; The integrator works by using every applicable rule (such as
+;; substitution, parts, linearity, etc.) to generate possible righthand
+;; sides, all of which are entered into the cache. Now, as long as the
+;; target integral is not complete (and the time limit has not run out)
+;; choose an incomplete integral from the cache and, for every integral
+;; appearing in its RHS's, add those integrals to the cache using the
+;; same substitition, parts, etc. rules. The cache should be organized
+;; as a priority queue, choosing the "simplest" incomplete integral at
+;; each step, or choosing randomly among equally simple integrals.
+;; Simplicity equals small size, and few steps removed from the original
+;; target integral. Note that when the integrator finishes, incomplete
+;; integrals can be left in the cache, so the algorithm can start where
+;; it left off if another similar integral is later requested.
+;; Breadth-first search would avoid the nagging problem of, e.g., whether
+;; to use parts or substitution first, and which decomposition is best.
+;; All are tried, and any path that diverges will quickly be put on the
+;; back burner by the priority queue.
+;; Note: Probably a good idea to call math-simplify-extended before
+;; measuring a formula's simplicity.
+
+;; From: "Robert J. Chassell" <bob@rattlesnake.com>
+;; 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
+;; initial information.)
+
+;;; Code:
(provide 'calc)
(require 'calc-macs)
-(defun calc-record-compilation-date ()
- (calc-record-compilation-date-macro))
-(calc-record-compilation-date)
-
-
;;; The "###autoload" comment will be used by Emacs version 19 for
;;; maintaining the loaddefs.el file automatically.
"*File name in which to look for the Calculator's Info documentation.")
;;;###autoload
-(defvar calc-settings-file "~/.emacs"
- "*File in which to record permanent settings; default is \"~/.emacs\".")
+(defvar calc-settings-file user-init-file
+ "*File in which to record permanent settings; default is `user-init-file'.")
;;;###autoload
(defvar calc-autoload-directory nil
(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 "daveg@synaptics.com")
+(defvar calc-bug-address "walters@debian.org")
-
-;; If T, scan keymaps to find all DEL-like keys.
-;; If NIL, only DEL itself is mapped to calc-pop.
+;; 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-extensions-loaded nil)
-
-
-;;; IDEAS:
-;;;
-;;; Fix rewrite mechanism to do less gratuitous rearrangement of terms.
-;;; Implement a pattern-based "refers" predicate.
-;;;
-;;; Make it possible to Undo a selection command.
-;;; Figure out how to allow selecting rows of matrices.
-;;; If cursor was in selection before, move it after j n, j p, j L, etc.
-;;; Consider reimplementing calc-delete-selection using rewrites.
-;;;
-;;; Implement line-breaking in non-flat compositions (is this desirable?).
-;;; Implement matrix formatting with multi-line components.
-;;;
-;;; Have "Z R" define a user command based on a set of rewrite rules.
-;;; Support "incf" and "decf" in defmath definitions.
-;;; Have defmath generate calls to calc-binary-op or calc-unary-op.
-;;; Make some way to define algebraic functions using keyboard macros.
-;;;
-;;; Allow calc-word-size=0 => Common Lisp-style signed bitwise arithmetic.
-;;; Consider digamma function (and thus arb. prec. Euler's gamma constant).
-;;; May as well make continued-fractions stuff available to the user.
-;;;
-;;; How about matrix eigenvalues, SVD, pseudo-inverse, etc.?
-;;; Should cache matrix inverses as well as decompositions.
-;;; If dividing by a non-square matrix, use least-squares automatically.
-;;; Consider supporting matrix exponentials.
-;;;
-;;; Have ninteg detect and work around singularities at the endpoints.
-;;; Use an adaptive subdivision algorithm for ninteg.
-;;; Provide nsum and nprod to go along with ninteg.
-;;;
-;;; Handle TeX-mode parsing of \matrix{ ... } where ... contains braces.
-;;; Support AmS-TeX's \{d,t,}frac, \{d,t,}binom notations.
-;;; Format and parse sums and products in Eqn and Math modes.
-;;;
-;;; Get math-read-big-expr to read sums, products, etc.
-;;; Change calc-grab-region to use math-read-big-expr.
-;;; Have a way to define functions using := in Embedded Mode.
-;;;
-;;; Support polar plotting with GNUPLOT.
-;;; Make a calc-graph-histogram function.
-;;;
-;;; Replace hokey formulas for complex functions with formulas designed
-;;; to minimize roundoff while maintaining the proper branch cuts.
-;;; Test accuracy of advanced math functions over whole complex plane.
-;;; Extend Bessel functions to provide arbitrary precision.
-;;; Extend advanced math functions to handle error forms and intervals.
-;;; Provide a better implementation for math-sin-cos-raw.
-;;; Provide a better implementation for math-hypot.
-;;; Provide a better implementation for math-make-frac.
-;;; Provide a better implementation for calcFunc-prfac.
-;;; Provide a better implementation for calcFunc-factor.
-;;;
-;;; Provide more examples in the tutorial section of the manual.
-;;; Cover in the tutorial: simplification modes, declarations,
-;;; bitwise stuff, selections, matrix mapping, financial functions.
-;;; Provide more Lisp programming examples in the manual.
-;;; Finish the Internals section of the manual (and bring it up to date).
-;;;
-;;; Tim suggests adding spreadsheet-like features.
-;;; Implement language modes for Gnuplot, Lisp, Ada, APL, ...?
-;;;
-
-
-;;; For atan series, if x > tan(pi/12) (about 0.268) reduce using the identity
-;;; atan(x) = atan((x * sqrt(3) - 1) / (sqrt(3) + x)) + pi/6.
-
-
-;;; A better integration algorithm:
-;;; Use breadth-first instead of depth-first search, as follows:
-;;; The integral cache allows unfinished integrals in symbolic notation
-;;; on the righthand side. An entry with no unfinished integrals on the
-;;; RHS is "complete"; references to it elsewhere are replaced by the
-;;; integrated value. More than one cache entry for the same integral
-;;; may exist, though if one becomes complete, the others may be deleted.
-;;; The integrator works by using every applicable rule (such as
-;;; substitution, parts, linearity, etc.) to generate possible righthand
-;;; sides, all of which are entered into the cache. Now, as long as the
-;;; target integral is not complete (and the time limit has not run out)
-;;; choose an incomplete integral from the cache and, for every integral
-;;; appearing in its RHS's, add those integrals to the cache using the
-;;; same substitition, parts, etc. rules. The cache should be organized
-;;; as a priority queue, choosing the "simplest" incomplete integral at
-;;; each step, or choosing randomly among equally simple integrals.
-;;; Simplicity equals small size, and few steps removed from the original
-;;; target integral. Note that when the integrator finishes, incomplete
-;;; integrals can be left in the cache, so the algorithm can start where
-;;; it left off if another similar integral is later requested.
-;;; Breadth-first search would avoid the nagging problem of, e.g., whether
-;;; to use parts or substitution first, and which decomposition is best.
-;;; All are tried, and any path that diverges will quickly be put on the
-;;; back burner by the priority queue.
-;;; Note: Probably a good idea to call math-simplify-extended before
-;;; measuring a formula's simplicity.
-
-
-
-
-
-
;; Calculator stack.
;; Entries are 3-lists: Formula, Height (in lines), Selection (or nil).
(defvar calc-stack '((top-of-stack 1 nil)))
;; 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.
+;; 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.
+;; 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.
+;; 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 nil, stack display is left-justified.
;; If 'right, stack display is right-justified.
;; If 'center, stack display is centered."
;;(defvar calc-display-just 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.
+;; 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 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)
;; 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.
+;; If non-nil, prefer fractional over floating-point results.
;;(defvar calc-prefer-frac nil)
;; Format of displayed hours-minutes-seconds angles, a format string.
;; Preferred form, either 'cplx or 'polar, for complex numbers.
;;(defvar calc-complex-mode 'cplx)
-;; If NIL, 1 / 0 is left unsimplified.
+;; 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.
+;; If non-nil, display vectors of byte-sized integers as strings.
;;(defvar calc-display-strings nil)
-;; If NIL, vector elements are left-justified.
+;; 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.
+;; 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.
+;; 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.
+;; 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.
+;; If non-nil, separate elements of displayed vectors with this string.
;;(defvar calc-vector-commas ",")
-;; If non-NIL, surround displayed vectors with these characters.
+;; If non-nil, surround displayed vectors with these characters.
;;(defvar calc-vector-brackets "[]")
;; A list of code-letter symbols that control "big" matrix display.
;; 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 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)
-;; If non-NIL, recompute evalto's automatically when necessary.
+;; If non-nil, recompute evalto's automatically when necessary.
;;(defvar calc-auto-recompute t)
-;; If non-NIL, display shows unformatted Lisp exprs. (For debugging)
+;; If non-nil, display shows unformatted Lisp exprs. (For debugging)
;;(defvar calc-display-raw nil)
;; Number of digits of internal precision for calc-mode calculations.
;;(defvar calc-internal-prec 12)
-;; If non-NIL, next operation is Inverse.
+;; If non-nil, next operation is Inverse.
;;(defvar calc-inverse-flag nil)
-;; If non-NIL, next operation is Hyperbolic.
+;; If non-nil, next operation is Hyperbolic.
;;(defvar calc-hyperbolic-flag nil)
-;; If non-NIL, next operation should not remove its arguments from stack.
+;; 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 "'".
+;; 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.
+;; 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.
+;; 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.
+;; 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.
+;; 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.
+;; 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.
+;; 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.
+;; 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.
+;; 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.
+;; 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.
+;; 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
;; List of strings for Y prefix help.
(defvar calc-Y-help-msgs nil)
-;; T if calc-settings-file has been loaded yet.
+;; t if calc-settings-file has been loaded yet.
(defvar calc-loaded-settings-file nil)
(put 'math-underflow 'error-conditions '(error math-underflow calc-error))
(put 'math-underflow 'error-message "Floating-point underflow occurred")
- (setq calc-version "2.02f"
- calc-version-date "Sun Dec 15 1996"
+ (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-was-split nil ; Had multiple windows before Calc.
(mapcar (function (lambda (v) (or (boundp v) (set v nil))))
calc-local-var-list)
- (if (boundp 'calc-mode-map)
- nil
+ (unless (boundp 'calc-mode-map)
(setq calc-mode-map (make-keymap))
(suppress-keymap calc-mode-map t)
(define-key calc-mode-map "+" 'calc-plus)
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)
-
-))
-)
+report-calc-bug))))
(calc-init-base)
;;;###autoload
(defun calc-dispatch (&optional arg)
- "Invoke the GNU Emacs Calculator. See calc-dispatch-help for details."
+ "Invoke the GNU Emacs Calculator. See `calc-dispatch-help' for details."
(interactive "P")
(sit-for echo-keystrokes)
(condition-case err ; look for other keys bound to calc-dispatch
(error nil))
(calc-do-dispatch arg))
+(defvar calc-dispatch-help nil)
(defun calc-do-dispatch (arg)
(let ((key (calc-read-key-sequence
(if calc-dispatch-help
(or (commandp key) (calc-extensions))
(call-interactively key))
(beep))))
-(setq calc-dispatch-help nil)
(defun calc-read-key-sequence (prompt map)
(let ((prompt2 (format "%s " (key-description (this-command-keys))))
1 nil))))))
(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)
(progn
(setq calc-loaded-settings-file t)
(calc-set-mode-line)))
(calc-check-defines))
+(defvar calc-check-defines 'calc-check-defines) ; suitable for run-hooks
(defun calc-check-defines ()
(if (symbol-plist 'calc-define)
(let ((plist (copy-sequence (symbol-plist 'calc-define))))
;; See if this has added any more calc-define properties.
(calc-check-defines))
(setplist 'calc-define nil)))))
-(setq calc-check-defines 'calc-check-defines) ; suitable for run-hooks
(defun calc-trail-mode (&optional buf)
"Calc Trail mode.
(setq calc-main-buffer buf)))
(if (= (buffer-size) 0)
(let ((buffer-read-only nil))
- (insert "Emacs Calculator v" calc-version " by Dave Gillespie, "
- "installed " calc-installed-date "\n")))
+ (insert "Emacs Calculator v" calc-version " by Dave Gillespie\n")))
(run-hooks 'calc-trail-mode-hook))
(defun calc-create-buffer ()
(and calc-display-trail
(= (window-width) (frame-width))
(calc-trail-display 1 t)))
- (message "Welcome to the GNU Emacs Calculator! Press `?' or `h' for help, `q' to quit.")
+ (message "Welcome to the GNU Emacs Calculator! Press `?' or `h' for help, `q' to quit")
(run-hooks 'calc-start-hook)
(and (windowp full-display)
(window-point full-display)
calc-embedded-info
(eq (current-buffer) (aref calc-embedded-info 0)))
(calc-embedded nil)
- (or (eq major-mode 'calc-mode)
- (calc-create-buffer))
+ (unless (eq major-mode 'calc-mode)
+ (calc-create-buffer))
(run-hooks 'calc-end-hook)
(setq calc-undo-list nil calc-redo-list nil)
(mapcar (function (lambda (v) (set-default v (symbol-value v))))
(calc-do-keypad t (interactive-p)))
+(defvar calc-aborted-prefix nil)
+(defvar calc-start-time nil)
;;; Note that modifications to this function may break calc-pass-errors.
(defun calc-do (do-body &optional do-slow)
(calc-check-defines)
(and (eq calc-algebraic-mode 'total)
(calc-extensions)
(use-local-map calc-alg-map))
- (and do-slow calc-display-working-message
- (progn
- (message "Working...")
- (calc-set-command-flag 'clear-message)))
+ (when (and do-slow calc-display-working-message)
+ (message "Working...")
+ (calc-set-command-flag 'clear-message))
(funcall do-body)
(setq calc-aborted-prefix nil)
- (and (memq 'renum-stack calc-command-flags)
- (calc-renumber-stack))
- (and (memq 'clear-message calc-command-flags)
- (message "")))
+ (when (memq 'renum-stack calc-command-flags)
+ (calc-renumber-stack))
+ (when (memq 'clear-message calc-command-flags)
+ (message "")))
(error
(if (and (eq (car err) 'error)
(stringp (nth 1 err))
(string-match "max-specpdl-size\\|max-lisp-eval-depth"
(nth 1 err)))
- (error "Computation got stuck or ran too long. Type `M' to increase the limit.")
+ (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)
- (and calc-aborted-prefix
- (calc-record "<Aborted>" calc-aborted-prefix))
+ (when calc-aborted-prefix
+ (calc-record "<Aborted>" calc-aborted-prefix))
(and calc-start-time
(let* ((calc-internal-prec 12)
(calc-date-format nil)
(calc-select-buffer)
(goto-line calc-final-point-line)
(move-to-column calc-final-point-column))))
- (or (memq 'keep-flags calc-command-flags)
- (save-excursion
- (calc-select-buffer)
- (setq calc-inverse-flag nil
- calc-hyperbolic-flag nil
- calc-keep-args-flag nil)))
- (and (memq 'do-edit calc-command-flags)
- (switch-to-buffer (get-buffer-create "*Calc Edit*")))
+ (unless (memq 'keep-flags calc-command-flags)
+ (save-excursion
+ (calc-select-buffer)
+ (setq calc-inverse-flag nil
+ calc-hyperbolic-flag nil
+ calc-keep-args-flag nil)))
+ (when (memq 'do-edit calc-command-flags)
+ (switch-to-buffer (get-buffer-create "*Calc Edit*")))
(calc-set-mode-line)
- (and calc-embedded-info
- (calc-embedded-finish-command))))
+ (when calc-embedded-info
+ (calc-embedded-finish-command))))
(identity nil)) ; allow a GC after timing is done
-(setq calc-aborted-prefix nil)
-(setq calc-start-time nil)
(defun calc-set-command-flag (f)
- (if (not (memq f calc-command-flags))
- (setq calc-command-flags (cons f calc-command-flags))))
+ (unless (memq f calc-command-flags)
+ (setq calc-command-flags (cons f calc-command-flags))))
(defun calc-select-buffer ()
(or (eq major-mode 'calc-mode)
(setq last-command-char (upcase last-command-char)))
(cond
((memq last-command-char '(?_ ?n))
- (goto-char (point-min))
+ (goto-char (minibuffer-prompt-end))
(if (and (search-forward " +/- " nil t)
(not (search-forward "e" nil t)))
(beep)
( ":=" calcFunc-assign 51 50 )
( "::" calcFunc-condition 45 46 )
( "=>" calcFunc-evalto 40 41 )
- ( "=>" calcFunc-evalto 40 -1 )
-))
-(setq math-expr-opers math-standard-opers)
-
+ ( "=>" calcFunc-evalto 40 -1 )))
+(defvar math-expr-opers math-standard-opers)
;;;###autoload
(defun calc-grab-region (top bot arg)