]> code.delx.au - gnu-emacs/blobdiff - lisp/calc/calc.el
Merge from emacs-24; up to 2012-05-04T19:17:01Z!monnier@iro.umontreal.ca
[gnu-emacs] / lisp / calc / calc.el
index 72ddddeb32d372859b463a47f85376f478469096..3e6ae1c7404e83293b277a87843621e9b262f497 100644 (file)
@@ -1,6 +1,6 @@
 ;;; calc.el --- the GNU Emacs calculator
 
-;; Copyright (C) 1990-1993, 2001-2011  Free Software Foundation, Inc.
+;; Copyright (C) 1990-1993, 2001-2012  Free Software Foundation, Inc.
 
 ;; Author: David Gillespie <daveg@synaptics.com>
 ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
 ;;     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
+;;     same substitution, 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
 
 
 (defgroup calc nil
-  "GNU Calc."
+  "Advanced desk calculator and mathematical tool."
   :prefix "calc-"
   :tag    "Calc"
   :group  'applications)
@@ -418,6 +418,13 @@ in normal mode."
   :group 'calc
   :type 'boolean)
 
+(defcustom calc-ensure-consistent-units
+  nil
+  "If non-nil, make sure new units are consistent with current units
+when converting units."
+  :group 'calc
+  :type 'boolean)
+
 (defcustom calc-undo-length
   100
   "The number of undo steps that will be preserved when Calc is quit."
@@ -428,27 +435,36 @@ in normal mode."
   nil
   "If non-nil, use a separate face to indicate selected sub-formulas.
 If `calc-show-selections' is non-nil, then selected sub-formulas are shown
-by displaying the rest of the formula in `calc-nonselected-face'.  
+by displaying the rest of the formula in `calc-nonselected-face'.
 If `calc-show-selections' is nil, then selected sub-formulas are shown
 by displaying the sub-formula in `calc-selected-face'."
+  :version "24.1"
   :group 'calc
   :type 'boolean)
 
-(defcustom calc-logunits-field-reference
+(defcustom calc-lu-field-reference
   "20 uPa"
   "The default reference level for logarithmic units (field)."
+  :version "24.1"
   :group 'calc
   :type '(string))
 
-(defcustom calc-logunits-power-reference
+(defcustom calc-lu-power-reference
   "mW"
   "The default reference level for logarithmic units (power)."
+  :version "24.1"
   :group 'calc
   :type '(string))
 
+(defcustom calc-note-threshold "1"
+  "The number of cents that a frequency should be near a note
+to be identified as that note."
+  :version "24.1"
+  :type 'string
+  :group 'calc)
 
 (defface calc-nonselected-face
-  '((t :inherit shadow       
+  '((t :inherit shadow
        :slant italic))
   "Face used to show the non-selected portion of a formula."
   :group 'calc)
@@ -682,11 +698,11 @@ If `C' is present, display outer brackets for matrices (centered).")
 (defcalcmodevar calc-previous-modulo nil
   "Most recently used value of M in a modulo form.")
 
-(defcalcmodevar calc-simplify-mode nil
+(defcalcmodevar calc-simplify-mode 'alg
   "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 limited simplifications are applied.
 If `binary', `math-clip' is applied if appropriate.
 If `alg', `math-simplify' is applied.
 If `ext', `math-simplify-extended' is applied.
@@ -808,7 +824,7 @@ If nil, selections displayed but ignored.")
 Used by `calc-user-invocation'.")
 
 (defcalcmodevar calc-show-banner t
-  "*If non-nil, show a friendly greeting above the stack.")
+  "If non-nil, show a friendly greeting above the stack.")
 
 (defconst calc-local-var-list '(calc-stack
                                calc-stack-top
@@ -898,7 +914,7 @@ Used by `calc-user-invocation'.")
 
 ;; Set up the autoloading linkage.
 (let ((name (and (fboundp 'calc-dispatch)
-                 (eq (car-safe (symbol-function 'calc-dispatch)) 'autoload)
+                 (autoloadp (symbol-function 'calc-dispatch))
                  (nth 1 (symbol-function 'calc-dispatch))))
       (p load-path))
 
@@ -998,7 +1014,7 @@ Used by `calc-user-invocation'.")
 (defvar calc-quick-prev-results nil
   "Previous results from Quick Calc.")
 (defvar calc-said-hello nil
-  "Non-nil if the welcomd message has been displayed.")
+  "Non-nil if the welcome message has been displayed.")
 (defvar calc-executing-macro nil
   "Non-nil if a keyboard macro is executing from the \"K\" key.")
 (defvar calc-any-selections nil
@@ -1079,7 +1095,7 @@ Used by `calc-user-invocation'.")
           "lOW")
     (mapc (lambda (x) (define-key map (char-to-string x) 'calc-missing-key))
           (concat "ABCDEFGHIJKLMNOPQRSTUVXZabcdfghjkmoprstuvwxyz"
-                  ":\\|!()[]<>{},;=~`\C-k\C-w\C-_"))
+                  ":\\|!()[]<>{},;=~`\C-k\C-w"))
     (define-key map "\M-w" 'calc-missing-key)
     (define-key map "\M-k" 'calc-missing-key)
     (define-key map "\M-\C-w" 'calc-missing-key)
@@ -1230,7 +1246,8 @@ Used by `calc-user-invocation'.")
        (glob (current-global-map))
        (loc (current-local-map)))
     (or (input-pending-p) (message "%s" prompt))
-    (let ((key (calc-read-key t)))
+    (let ((key (calc-read-key t))
+         (input-method-function nil))
       (calc-unread-command (cdr key))
       (unwind-protect
          (progn
@@ -1288,19 +1305,20 @@ the trail buffer."
     (if (not info-list)
         (progn
           (setq calc-buffer-list (delete cb calc-buffer-list))
-          (with-current-buffer calc-trail-buffer
-            (if (eq cb calc-main-buffer)
-                ;; If there are other Calc stacks, make another one
-                ;; the calc-main-buffer ...
-                (if calc-buffer-list
-                    (setq calc-main-buffer (car calc-buffer-list))
-                  ;; ... otherwise kill the trail and its windows.
-                  (let ((wl (get-buffer-window-list calc-trail-buffer)))
-                    (while wl
-                      (delete-window (car wl))
-                      (setq wl (cdr wl))))
-                  (kill-buffer calc-trail-buffer)
-                  (setq calc-trail-buffer nil))))
+          (if (buffer-live-p calc-trail-buffer)
+              (with-current-buffer calc-trail-buffer
+                (if (eq cb calc-main-buffer)
+                    ;; If there are other Calc stacks, make another one
+                    ;; the calc-main-buffer ...
+                    (if calc-buffer-list
+                        (setq calc-main-buffer (car calc-buffer-list))
+                      ;; ... otherwise kill the trail and its windows.
+                      (let ((wl (get-buffer-window-list calc-trail-buffer)))
+                        (while wl
+                          (delete-window (car wl))
+                          (setq wl (cdr wl))))
+                      (kill-buffer calc-trail-buffer)))))
+          (setq calc-trail-buffer nil)
           t))))
 
 (defun calc-mode ()
@@ -1739,10 +1757,10 @@ See calc-keypad for details."
                           ((eq calc-simplify-mode 'num) "NumSimp ")
                           ((eq calc-simplify-mode 'binary)
                            (format "BinSimp%d " calc-word-size))
-                          ((eq calc-simplify-mode 'alg) "AlgSimp ")
+                          ((eq calc-simplify-mode 'alg) "")
                           ((eq calc-simplify-mode 'ext) "ExtSimp ")
                           ((eq calc-simplify-mode 'units) "UnitSimp ")
-                          (t ""))
+                          (t "BasicSimp "))
 
                     ;; Display modes
                     (cond ((= calc-number-radix 10) "")
@@ -2565,7 +2583,11 @@ largest Emacs integer.")
 ;;; Reduce an object to canonical (normalized) form.  [O o; Z Z] [Public]
 
 (defvar math-normalize-a)
+(defvar math-normalize-error nil
+  "Non-nil if the last call the `math-normalize' returned an error.")
+
 (defun math-normalize (math-normalize-a)
+  (setq math-normalize-error nil)
   (cond
    ((not (consp math-normalize-a))
     (if (integerp math-normalize-a)
@@ -2654,31 +2676,38 @@ largest Emacs integer.")
                                        (fboundp (car math-normalize-a))))
                               (apply (car math-normalize-a) args)))))
                (wrong-number-of-arguments
+                 (setq math-normalize-error t)
                 (calc-record-why "*Wrong number of arguments"
                                  (cons (car math-normalize-a) args))
                 nil)
                (wrong-type-argument
+                 (setq math-normalize-error t)
                 (or calc-next-why
                      (calc-record-why "Wrong type of argument"
                                       (cons (car math-normalize-a) args)))
                 nil)
                (args-out-of-range
+                 (setq math-normalize-error t)
                 (calc-record-why "*Argument out of range"
                                   (cons (car math-normalize-a) args))
                 nil)
                (inexact-result
+                 (setq math-normalize-error t)
                 (calc-record-why "No exact representation for result"
                                  (cons (car math-normalize-a) args))
                 nil)
                (math-overflow
+                 (setq math-normalize-error t)
                 (calc-record-why "*Floating-point overflow occurred"
                                  (cons (car math-normalize-a) args))
                 nil)
                (math-underflow
+                 (setq math-normalize-error t)
                 (calc-record-why "*Floating-point underflow occurred"
                                  (cons (car math-normalize-a) args))
                 nil)
                (void-variable
+                 (setq math-normalize-error t)
                 (if (eq (nth 1 err) 'var-EvalRules)
                     (progn
                       (setq var-EvalRules nil)