]> code.delx.au - gnu-emacs/blobdiff - lisp/calc/calc-misc.el
(ido-enable-prefix): Improve previous doc fix.
[gnu-emacs] / lisp / calc / calc-misc.el
index 8a388a447e00991231ec29fb48e8124501566c44..14bf3908b83e2e4b6cb198dec6234ef704657f51 100644 (file)
@@ -1,10 +1,10 @@
-;;; calc-misc.el --- miscellaenous functions for Calc
+;;; calc-misc.el --- miscellaneous functions for Calc
 
-;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
+;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004
+;;   2005, 2006 Free Software Foundation, Inc.
 
 ;; Author: David Gillespie <daveg@synaptics.com>
-;; Maintainers: D. Goel <deego@gnufans.org> 
-;;              Colin Walters <walters@debian.org>
+;; Maintainer: Jay Belanger <belanger@truman.edu>
 
 ;; This file is part of GNU Emacs.
 
 ;;; Code:
 
 ;; This file is autoloaded from calc.el.
-(require 'calc)
 
+(require 'calc)
 (require 'calc-macs)
 
-(defun calc-Need-calc-misc () nil)
-
-
 (defun calc-dispatch-help (arg)
-  "M-# is a prefix key; follow it with one of these letters:
+  "C-x* is a prefix key sequence; follow it with one of these letters:
 
 For turning Calc on and off:
   C  calc.  Start the Calculator in a window at the bottom of the screen.
@@ -76,8 +73,9 @@ Miscellaneous:
   M  read-kbd-macro.  Read a region of keystroke names as a keyboard macro.
   0  (zero) calc-reset.  Reset Calc stack and modes to default state.
 
-Press twice (`M-# M-#' or `M-# #') to turn Calc on or off using the same
-Calc user interface as before (either M-# C or M-# K; initially M-# C)."
+Press `*' twice (`C-x * *') to turn Calc on or off using the same
+Calc user interface as before (either C-x * C or C-x * K; initially C-x * C).
+"
   (interactive "P")
   (calc-check-defines)
   (if calc-dispatch-help
@@ -130,9 +128,9 @@ Calc user interface as before (either M-# C or M-# K; initially M-# C)."
                 "Now using full screen for Calc"
               "Now using partial screen for Calc"))))
 
-(defun calc-other-window ()
+(defun calc-other-window (&optional interactive)
   "Invoke the Calculator in another window."
-  (interactive)
+  (interactive "p")
   (if (memq major-mode '(calc-mode calc-trail-mode))
       (progn
        (other-window 1)
@@ -141,7 +139,7 @@ Calc user interface as before (either M-# C or M-# K; initially M-# C)."
     (if (get-buffer-window "*Calculator*")
        (calc-quit)
       (let ((win (selected-window)))
-       (calc nil win (interactive-p))))))
+       (calc nil win interactive)))))
 
 (defun another-calc ()
   "Create another, independent Calculator buffer."
@@ -160,21 +158,25 @@ Calc user interface as before (either M-# C or M-# K; initially M-# C)."
   (select-window (get-largest-window))
   (info "Calc"))
 
+(defun calc-info-goto-node (node)
+  "Go to a node in the Calculator info documentation."
+  (interactive)
+  (select-window (get-largest-window))
+  (info (concat "(Calc)" node)))
+
 (defun calc-tutorial ()
   "Run the Emacs Info system on the Calculator Tutorial."
   (interactive)
   (if (get-buffer-window "*Calculator*")
       (calc-quit))
-  (calc-info)
-  (Info-goto-node "Interactive Tutorial")
+  (calc-info-goto-node "Interactive Tutorial")
   (calc-other-window)
   (message "Welcome to the Calc Tutorial!"))
 
 (defun calc-info-summary ()
   "Run the Emacs Info system on the Calculator Summary."
   (interactive)
-  (calc-info)
-  (Info-goto-node "Summary"))
+  (calc-info-goto-node "Summary"))
 
 (defun calc-help ()
   (interactive)
@@ -228,6 +230,9 @@ Calc user interface as before (either M-# C or M-# K; initially M-# C)."
 
 ;;;; Stack and buffer management.
 
+;; The variable calc-last-why-command is set in calc-do-handly-whys
+;; and used in calc-why (in calc-stuff.el).
+(defvar calc-last-why-command)
 
 (defun calc-do-handle-whys ()
   (setq calc-why (sort calc-next-why
@@ -239,7 +244,7 @@ Calc user interface as before (either M-# C or M-# K; initially M-# C)."
                        (and (eq (car (car calc-why)) '*)
                             calc-auto-why)))
       (progn
-       (calc-extensions)
+       (require 'calc-ext)
        (calc-explain-why (car calc-why)
                          (if (eq calc-auto-why t)
                              (cdr calc-why)
@@ -325,14 +330,14 @@ Calc user interface as before (either M-# C or M-# K; initially M-# C)."
 
 (defun calc-last-args-stub (arg)
   (interactive "p")
-  (calc-extensions)
+  (require 'calc-ext)
   (calc-last-args arg))
 
 
 (defun calc-power (arg)
   (interactive "P")
   (calc-slow-wrapper
-   (if (and calc-extensions-loaded
+   (if (and (featurep 'calc-ext)
            (calc-is-inverse))
        (calc-binary-op "root" 'calcFunc-nroot arg nil nil)
      (calc-binary-op "^" 'calcFunc-pow arg nil nil '^))))
@@ -414,7 +419,7 @@ Calc user interface as before (either M-# C or M-# K; initially M-# C)."
 When this key is used, calc-ext (the Calculator extensions module) will be
 loaded and the keystroke automatically re-typed."
   (interactive "P")
-  (calc-extensions)
+  (require 'calc-ext)
   (if (keymapp (key-binding (char-to-string last-command-char)))
       (message "%s%c-" (calc-num-prefix-name n) last-command-char))
   (calc-unread-command)
@@ -422,7 +427,7 @@ loaded and the keystroke automatically re-typed."
 
 (defun calc-shift-Y-prefix-help ()
   (interactive)
-  (calc-extensions)
+  (require 'calc-ext)
   (calc-do-prefix-help calc-Y-help-msgs "other" ?Y))
 
 
@@ -461,7 +466,7 @@ loaded and the keystroke automatically re-typed."
 (defun math-concat (v1 v2)
   (if (stringp v1)
       (concat v1 v2)
-    (calc-extensions)
+    (require 'calc-ext)
     (if (and (or (math-objvecp v1) (math-known-scalarp v1))
             (or (math-objvecp v2) (math-known-scalarp v2)))
        (append (if (and (math-vectorp v1)
@@ -589,31 +594,39 @@ loaded and the keystroke automatically re-typed."
 
 
 ;;; Coerce A to be an integer (by truncation toward zero).  [I N] [Public]
-(defun math-trunc (a &optional prec)
-  (cond (prec
-        (calc-extensions)
-        (math-trunc-special a prec))
+
+;; The variable math-trunc-prec is local to math-trunc, but used by
+;; math-trunc-fancy in calc-arith.el, which is called by math-trunc.
+
+(defun math-trunc (a &optional math-trunc-prec)
+  (cond (math-trunc-prec
+        (require 'calc-ext)
+        (math-trunc-special a math-trunc-prec))
        ((Math-integerp a) a)
        ((Math-looks-negp a)
         (math-neg (math-trunc (math-neg a))))
        ((eq (car a) 'float)
         (math-scale-int (nth 1 a) (nth 2 a)))
-       (t (calc-extensions)
+       (t (require 'calc-ext)
           (math-trunc-fancy a))))
 (defalias 'calcFunc-trunc 'math-trunc)
 
 ;;; Coerce A to be an integer (by truncation toward minus infinity).  [I N]
-(defun math-floor (a &optional prec)    ;  [Public]
-  (cond (prec
-        (calc-extensions)
-        (math-floor-special a prec))
+
+;; The variable math-floor-prec is local to math-floor, but used by
+;; math-floor-fancy in calc-arith.el, which is called by math-floor.
+
+(defun math-floor (a &optional math-floor-prec)    ;  [Public]
+  (cond (math-floor-prec
+        (require 'calc-ext)
+        (math-floor-special a math-floor-prec))
        ((Math-integerp a) a)
        ((Math-messy-integerp a) (math-trunc a))
        ((Math-realp a)
         (if (Math-negp a)
             (math-add (math-trunc a) -1)
           (math-trunc a)))
-       (t (calc-extensions)
+       (t (require 'calc-ext)
           (math-floor-fancy a))))
 (defalias 'calcFunc-floor 'math-floor)
 
@@ -629,13 +642,16 @@ loaded and the keystroke automatically re-typed."
 (defun calcFunc-inv (m)
   (if (Math-vectorp m)
       (progn
-       (calc-extensions)
+       (require 'calc-ext)
        (if (math-square-matrixp m)
            (or (math-with-extra-prec 2 (math-matrix-inv-raw m))
                (math-reject-arg m "*Singular matrix"))
          (math-reject-arg m 'square-matrixp)))
-    (math-div 1 m)))
-
+    (if (and
+         (require 'calc-arith)
+         (math-known-matrixp m))
+        (math-pow m -1)
+      (math-div 1 m))))
 
 (defun math-do-working (msg arg)
   (or executing-kbd-macro
@@ -659,7 +675,7 @@ loaded and the keystroke automatically re-typed."
         (math-imod a b))
        ((and (Math-anglep a) (Math-anglep b))
         (math-sub a (math-mul (math-floor (math-div a b)) b)))
-       (t (calc-extensions)
+       (t (require 'calc-ext)
           (math-mod-fancy a b))))
 
 
@@ -672,7 +688,7 @@ loaded and the keystroke automatically re-typed."
        ((Math-zerop a)
         (if (and (Math-scalarp b) (Math-posp b))
             (if (math-floatp b) (math-float a) a)
-          (calc-extensions)
+          (require 'calc-ext)
           (math-pow-of-zero a b)))
        ((or (eq a 1) (eq b 1)) a)
        ((or (equal a '(float 1 0)) (equal b '(float 1 0))) a)
@@ -680,7 +696,7 @@ loaded and the keystroke automatically re-typed."
         (if (Math-scalarp a)
             (if (or (math-floatp a) (math-floatp b))
                 '(float 1 0) 1)
-          (calc-extensions)
+          (require 'calc-ext)
           (math-pow-zero a b)))
        ((and (Math-integerp b) (or (Math-numberp a) (Math-vectorp a)))
         (if (and (equal a '(float 1 1)) (integerp b))
@@ -688,7 +704,7 @@ loaded and the keystroke automatically re-typed."
           (math-with-extra-prec 2
             (math-ipow a b))))
        (t
-        (calc-extensions)
+        (require 'calc-ext)
         (math-pow-fancy a b))))
 
 (defun math-ipow (a n)   ; [O O I] [Public]
@@ -746,4 +762,7 @@ doing 'M-x toggle-debug-on-error', then reproducing the bug.
 " )))
 (defalias 'calc-report-bug 'report-calc-bug)
 
+(provide 'calc-misc)
+
+;;; arch-tag: 7984d9d0-62e5-41dc-afb8-e904b975f250
 ;;; calc-misc.el ends here