]> code.delx.au - gnu-emacs/blobdiff - lisp/calculator.el
(unload-feature): Handle (t . SYMBOL) entries in load history.
[gnu-emacs] / lisp / calculator.el
index 76ff4053c7f11ecc67bcea162a74b3a5d52c0978..53a3c96d948a71ccfa4a6f34fe3c761909f8866c 100644 (file)
@@ -1,10 +1,11 @@
 ;;; calculator.el --- a [not so] simple calculator for Emacs
 
-;; Copyright (C) 1998, 2000, 2001 by Free Software Foundation, Inc.
+;; Copyright (C) 1998, 2000, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: Eli Barzilay <eli@barzilay.org>
 ;; Keywords: tools, convenience
-;; Time-stamp: <2002-07-13 01:14:35 eli>
+;; Time-stamp: <2006-02-06 13:36:00 ttn>
 
 ;; This file is part of GNU Emacs.
 
@@ -20,8 +21,8 @@
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-;; MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+;; MA 02110-1301, USA.
 
 ;;;=====================================================================
 ;;; Commentary:
@@ -87,9 +88,9 @@ This determines the default behavior of unary operators."
 
 (defcustom calculator-prompt "Calc=%s> "
   "*The prompt used by the Emacs calculator.
-It should contain a \"%s\" somewhere that will indicate the i/o radixes,
-this string will be a two-character string as described in the
-documentation for `calculator-mode'."
+It should contain a \"%s\" somewhere that will indicate the i/o radixes;
+this will be a two-character string as described in the documentation
+for `calculator-mode'."
   :type  'string
   :group 'calculator)
 
@@ -105,15 +106,21 @@ at runtime."
   "*Use digit grouping in radix output mode.
 If this is set, chunks of `calculator-radix-grouping-digits' characters
 will be separated by `calculator-radix-grouping-separator' when in radix
-output mode is active (determined by `calculator-output-radix').")
+output mode is active (determined by `calculator-output-radix')."
+  :type  'boolean
+  :group 'calculator)
 
 (defcustom calculator-radix-grouping-digits 4
   "*The number of digits used for grouping display in radix modes.
-See `calculator-radix-grouping-mode'.")
+See `calculator-radix-grouping-mode'."
+  :type  'integer
+  :group 'calculator)
 
 (defcustom calculator-radix-grouping-separator "'"
   "*The separator used in radix grouping display.
-See `calculator-radix-grouping-mode'.")
+See `calculator-radix-grouping-mode'."
+  :type  'string
+  :group 'calculator)
 
 (defcustom calculator-remove-zeros t
   "*Non-nil value means delete all redundant zero decimal digits.
@@ -140,7 +147,8 @@ of digits displayed).
 
 An exception to the above is the case of the list (std C) where C is a
 character, in this case the `calculator-standard-displayer' function
-will be used with this character for a format string.")
+will be used with this character for a format string."
+  :group 'calculator)
 
 (defcustom calculator-displayers
   '(((std ?n) "Standard display, decimal point or scientific")
@@ -169,7 +177,9 @@ floats, otherwise the Emacs reader will fail on them."
   "*If non-nil, this is any value that can be used for
 `calculator-displayer', to format a string before copying it with
 `calculator-copy'.  If nil, then `calculator-displayer's normal value is
-used.")
+used."
+  :type  'boolean
+  :group 'calculator)
 
 (defcustom calculator-2s-complement nil
   "*If non-nil, show negative numbers in 2s complement in radix modes.
@@ -551,7 +561,7 @@ Used for repeating operations in calculator-repR/L.")
                                      calculator-output-radix)))]
             "---"
             ,@(mapcar 'car radix-selectors)
-            ("Seperate I/O"
+            ("Separate I/O"
              ,@(mapcar (lambda (x) (nth 1 x)) radix-selectors)
              "---"
              ,@(mapcar (lambda (x) (nth 2 x)) radix-selectors)))
@@ -671,7 +681,7 @@ more information.
   (setq major-mode 'calculator-mode)
   (setq mode-name "Calculator")
   (use-local-map calculator-mode-map)
-  (run-hooks 'calculator-mode-hook))
+  (run-mode-hooks 'calculator-mode-hook))
 
 (eval-when-compile (require 'electric) (require 'ehelp))
 
@@ -725,8 +735,42 @@ See the documentation for `calculator-mode' for more information."
            ;; `raised' modeline in Emacs 21
            (select-window
             (split-window-vertically
+             ;; If the modeline might interfere with the calculator buffer,
+             ;; use 3 lines instead.
              (if (and (fboundp 'face-attr-construct)
-                      (plist-get (face-attr-construct 'modeline) :box))
+                      (let* ((dh (plist-get (face-attr-construct 'default) :height))
+                             (mf (face-attr-construct 'modeline))
+                             (mh (plist-get mf :height)))
+                        ;; If the modeline is shorter than the default,
+                        ;; stick with 2 lines.  (It may be necessary to
+                        ;; check how much shorter.)
+                        (and
+                         (not
+                          (or (and (integerp dh)
+                                   (integerp mh)
+                                   (< mh dh))
+                              (and (numberp mh)
+                                   (not (integerp mh))
+                                   (< mh 1))))
+                         (or
+                          ;; If the modeline is taller than the default,
+                          ;; use 3 lines.
+                          (and (integerp dh)
+                               (integerp mh)
+                               (> mh dh))
+                          (and (numberp mh)
+                               (not (integerp mh))
+                               (> mh 1))
+                          ;; If the modeline has a box with non-negative line-width,
+                          ;; use 3 lines.
+                          (let* ((bx (plist-get mf :box))
+                                 (lh (plist-get bx :line-width)))
+                            (and bx
+                                 (or
+                                  (not lh)
+                                  (> lh 0))))
+                          ;; If the modeline has an overline, use 3 lines.
+                          (plist-get (face-attr-construct 'modeline) :overline)))))
                -3 -2)))
            (switch-to-buffer calculator-buffer)))
         ((not (eq (current-buffer) calculator-buffer))
@@ -1268,12 +1312,6 @@ arguments."
             (if Dbound (fset 'D Dsave) (fmakunbound 'D)))))
     (error 0)))
 
-(eval-when-compile ; silence the compiler
-  (or (fboundp 'event-key)
-      (defun event-key (&rest _) nil))
-  (or (fboundp 'key-press-event-p)
-      (defun key-press-event-p (&rest _) nil)))
-
 ;;;---------------------------------------------------------------------
 ;;; Input interaction
 
@@ -1292,8 +1330,9 @@ Optional string argument KEYS will force using it as the keys entered."
           (setq k (aref inp i))
           ;; if Emacs will someday have a event-key, then this would
           ;; probably be modified anyway
-          (and (fboundp 'event-key) (key-press-event-p k)
-               (event-key k) (setq k (event-key k)))
+          (and (if (fboundp 'key-press-event-p) (key-press-event-p k))
+              (if (fboundp 'event-key)
+                  (and (event-key k) (setq k (event-key k)))))
           ;; assume all symbols are translatable with an ascii-character
           (and (symbolp k)
                (setq k (or (get k 'ascii-character) ? )))
@@ -1590,7 +1629,7 @@ Optional string argument KEYS will force using it as the keys entered."
         (calculator-displayers
          (if calculator-copy-displayer nil calculator-displayers)))
     (calculator-enter)
-    ;; remove trailing spaces and and an index
+    ;; remove trailing spaces and an index
     (let ((s (cdr calculator-stack-display)))
       (and s
            (if (string-match "^\\([^ ]+\\) *\\(\\[[0-9/]+\\]\\)? *$" s)