]> code.delx.au - gnu-emacs/blobdiff - lisp/calculator.el
Merge from origin/emacs-25
[gnu-emacs] / lisp / calculator.el
index f2e6a888c09d605deecdd49441e646b0b6f0d3ea..523bf98180ab6e46847a7cedbaf709f22a00b763 100644 (file)
@@ -1,6 +1,6 @@
 ;;; calculator.el --- a calculator for Emacs  -*- lexical-binding: t -*-
 
-;; Copyright (C) 1998, 2000-2015 Free Software Foundation, Inc.
+;; Copyright (C) 1998, 2000-2016 Free Software Foundation, Inc.
 
 ;; Author: Eli Barzilay <eli@barzilay.org>
 ;; Keywords: tools, convenience
@@ -379,12 +379,13 @@ Used for repeating operations in calculator-repR/L.")
 ;;;---------------------------------------------------------------------
 ;;; Key bindings
 
-(defun calculator-define-key (key cmd &optional map)
-  ;; arranges for unbound alphabetic keys to be used as their un/shifted
-  ;; versions if those are bound (mimics the usual Emacs global
-  ;; bindings)
+(defun calculator-define-key (key cmd map)
+  ;; Arranges for unbound alphabetic keys to be used as their un/shifted
+  ;; versions if those are bound (mimics the usual Emacs global bindings).
+  ;; FIXME: We should adjust Emacs's native "fallback to unshifted binding"
+  ;; such that it can also be used here, rather than having to use a hack like
+  ;; this one.
   (let* ((key  (if (stringp key) (kbd key) key))
-         (map  (or map calculator-mode-map))
          (omap (keymap-parent map)))
     (define-key map key cmd)
     ;; "other" map, used for case-flipped bindings
@@ -393,7 +394,7 @@ Used for repeating operations in calculator-repR/L.")
       (suppress-keymap omap t)
       (set-keymap-parent map omap))
     (let ((m omap))
-      ;; bind all case-flipped versions
+      ;; Bind all case-flipped versions.
       (dotimes (i (length key))
         (let* ((c (aref key i))
                (k (vector c))
@@ -404,7 +405,7 @@ Used for repeating operations in calculator-repR/L.")
                                     (or (<= ?A c ?Z) (<= ?a c ?z)))
                            (define-key m (vector (logxor 32 c)) x)))))
           (cond ((= i (1- (length key)))
-                 ;; prefer longer sequences
+                 ;; Prefer longer sequences.
                  (unless (keymapp b) (funcall defkey cmd)))
                 ((keymapp b) (setq m b))
                 (t (let ((sub (make-sparse-keymap)))
@@ -801,7 +802,7 @@ Adds MORE-OPS to `calculator-operator', called initially to handle
   (let ((added-ops nil))
     (dolist (op more-ops)
       (unless (eq (car op) 'nobind)
-        (calculator-define-key (car op) 'calculator-op))
+        (calculator-define-key (car op) 'calculator-op calculator-mode-map))
       (push (if (eq (car op) 'nobind) (cdr op) op)
             added-ops))
     ;; added-ops come first, but in correct order