emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 6148555: * lisp/calculator.el (calculator-define-ke


From: Stefan Monnier
Subject: [Emacs-diffs] master 6148555: * lisp/calculator.el (calculator-define-key): Undo last change
Date: Mon, 07 Dec 2015 14:09:19 +0000

branch: master
commit 6148555ee5a3d0139ae517803718b3e0357933c7
Author: Stefan Monnier <address@hidden>
Commit: Stefan Monnier <address@hidden>

    * lisp/calculator.el (calculator-define-key): Undo last change
    
    Make map argument mandatory instead (bug#22106).
    (calculator-add-operators): Pass the argument that's not optional any more.
---
 lisp/calculator.el |   67 ++++++++++++++++++++++++++-------------------------
 1 files changed, 34 insertions(+), 33 deletions(-)

diff --git a/lisp/calculator.el b/lisp/calculator.el
index 1d3715b..4f1ad76 100644
--- a/lisp/calculator.el
+++ b/lisp/calculator.el
@@ -379,6 +379,39 @@ Used for repeating operations in calculator-repR/L.")
 ;;;---------------------------------------------------------------------
 ;;; Key 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))
+         (omap (keymap-parent map)))
+    (define-key map key cmd)
+    ;; "other" map, used for case-flipped bindings
+    (unless omap
+      (setq omap (make-sparse-keymap))
+      (suppress-keymap omap t)
+      (set-keymap-parent map omap))
+    (let ((m omap))
+      ;; Bind all case-flipped versions.
+      (dotimes (i (length key))
+        (let* ((c (aref key i))
+               (k (vector c))
+               (b (lookup-key m k))
+               (defkey (lambda (x)
+                         (define-key m k x)
+                         (when (and (characterp c)
+                                    (or (<= ?A c ?Z) (<= ?a c ?z)))
+                           (define-key m (vector (logxor 32 c)) x)))))
+          (cond ((= i (1- (length key)))
+                 ;; Prefer longer sequences.
+                 (unless (keymapp b) (funcall defkey cmd)))
+                ((keymapp b) (setq m b))
+                (t (let ((sub (make-sparse-keymap)))
+                     (funcall defkey sub)
+                     (setq m sub)))))))))
+
 (defvar calculator-mode-map
   (let ((map (make-sparse-keymap)))
     (suppress-keymap map t)
@@ -562,38 +595,6 @@ Used for repeating operations in calculator-repR/L.")
     map)
   "The calculator key map.")
 
-(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).
-  (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
-    (unless omap
-      (setq omap (make-sparse-keymap))
-      (suppress-keymap omap t)
-      (set-keymap-parent map omap))
-    (let ((m omap))
-      ;; Bind all case-flipped versions.
-      (dotimes (i (length key))
-        (let* ((c (aref key i))
-               (k (vector c))
-               (b (lookup-key m k))
-               (defkey (lambda (x)
-                         (define-key m k x)
-                         (when (and (characterp c)
-                                    (or (<= ?A c ?Z) (<= ?a c ?z)))
-                           (define-key m (vector (logxor 32 c)) x)))))
-          (cond ((= i (1- (length key)))
-                 ;; Prefer longer sequences.
-                 (unless (keymapp b) (funcall defkey cmd)))
-                ((keymapp b) (setq m b))
-                (t (let ((sub (make-sparse-keymap)))
-                     (funcall defkey sub)
-                     (setq m sub)))))))))
-
 ;;;---------------------------------------------------------------------
 ;;; Startup and mode stuff
 
@@ -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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]