diff options
author | Richard M. Stallman <rms@gnu.org> | 1993-06-30 04:36:37 +0000 |
---|---|---|
committer | Richard M. Stallman <rms@gnu.org> | 1993-06-30 04:36:37 +0000 |
commit | c43a252ddb6b8638527cf912e8c9b03ec5dc15dc (patch) | |
tree | 1714278a423b702c00f63f18f213a7de2af80a0f /lisp/subr.el | |
parent | dbb0639a11c061d69c0acc465b0b853e4398880f (diff) | |
download | emacs-c43a252ddb6b8638527cf912e8c9b03ec5dc15dc.tar.gz |
(define-key-after): Delete duplicate bindings that come
after the new one. Do insert when we reach the end, if haven't before.
Diffstat (limited to 'lisp/subr.el')
-rw-r--r-- | lisp/subr.el | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index e7bc2e13a24..23e9da84592 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -189,7 +189,7 @@ of the map. The order matters when the keymap is used as a menu." (or (keymapp keymap) (signal 'wrong-type-argument (list 'keymapp keymap))) - (let ((tail keymap) done + (let ((tail keymap) done inserted (first (aref key 0))) (while (and (not done) tail) ;; Delete any earlier bindings for the same key. @@ -197,11 +197,20 @@ The order matters when the keymap is used as a menu." (setcdr tail (cdr (cdr tail)))) ;; When we reach AFTER's binding, insert the new binding after. ;; If we reach an inherited keymap, insert just before that. + ;; If we reach the end of this keymap, insert at the end. (if (or (eq (car-safe (car tail)) after) - (eq (car tail) 'keymap)) + (eq (car (cdr tail)) 'keymap) + (null (cdr tail))) (progn - (setcdr tail (cons (cons (aref key 0) definition) (cdr tail))) - (setq done t))) + ;; Stop the scan only if we find a parent keymap. + ;; Keep going past the inserted element + ;; so we can delete any duplications that come later. + (if (eq (car (cdr tail)) 'keymap) + (setq done t)) + ;; Don't insert more than once. + (or inserted + (setcdr tail (cons (cons (aref key 0) definition) (cdr tail)))) + (setq inserted t))) (setq tail (cdr tail))))) (defun keyboard-translate (from to) |