diff options
| author | Richard M. Stallman | 1993-06-30 04:36:37 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1993-06-30 04:36:37 +0000 |
| commit | 113d28a8a0590b47854ff9bd53996e47940e1ca2 (patch) | |
| tree | 26428c4f9b73ad71942de7d30286f1114ad2ce29 | |
| parent | 31beb30ec1ad25dd362e9807df190df94e1f664c (diff) | |
| download | emacs-113d28a8a0590b47854ff9bd53996e47940e1ca2.tar.gz emacs-113d28a8a0590b47854ff9bd53996e47940e1ca2.zip | |
(define-key-after): Delete duplicate bindings that come
after the new one. Do insert when we reach the end, if haven't before.
| -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. | |||
| 189 | The order matters when the keymap is used as a menu." | 189 | The order matters when the keymap is used as a menu." |
| 190 | (or (keymapp keymap) | 190 | (or (keymapp keymap) |
| 191 | (signal 'wrong-type-argument (list 'keymapp keymap))) | 191 | (signal 'wrong-type-argument (list 'keymapp keymap))) |
| 192 | (let ((tail keymap) done | 192 | (let ((tail keymap) done inserted |
| 193 | (first (aref key 0))) | 193 | (first (aref key 0))) |
| 194 | (while (and (not done) tail) | 194 | (while (and (not done) tail) |
| 195 | ;; Delete any earlier bindings for the same key. | 195 | ;; Delete any earlier bindings for the same key. |
| @@ -197,11 +197,20 @@ The order matters when the keymap is used as a menu." | |||
| 197 | (setcdr tail (cdr (cdr tail)))) | 197 | (setcdr tail (cdr (cdr tail)))) |
| 198 | ;; When we reach AFTER's binding, insert the new binding after. | 198 | ;; When we reach AFTER's binding, insert the new binding after. |
| 199 | ;; If we reach an inherited keymap, insert just before that. | 199 | ;; If we reach an inherited keymap, insert just before that. |
| 200 | ;; If we reach the end of this keymap, insert at the end. | ||
| 200 | (if (or (eq (car-safe (car tail)) after) | 201 | (if (or (eq (car-safe (car tail)) after) |
| 201 | (eq (car tail) 'keymap)) | 202 | (eq (car (cdr tail)) 'keymap) |
| 203 | (null (cdr tail))) | ||
| 202 | (progn | 204 | (progn |
| 203 | (setcdr tail (cons (cons (aref key 0) definition) (cdr tail))) | 205 | ;; Stop the scan only if we find a parent keymap. |
| 204 | (setq done t))) | 206 | ;; Keep going past the inserted element |
| 207 | ;; so we can delete any duplications that come later. | ||
| 208 | (if (eq (car (cdr tail)) 'keymap) | ||
| 209 | (setq done t)) | ||
| 210 | ;; Don't insert more than once. | ||
| 211 | (or inserted | ||
| 212 | (setcdr tail (cons (cons (aref key 0) definition) (cdr tail)))) | ||
| 213 | (setq inserted t))) | ||
| 205 | (setq tail (cdr tail))))) | 214 | (setq tail (cdr tail))))) |
| 206 | 215 | ||
| 207 | (defun keyboard-translate (from to) | 216 | (defun keyboard-translate (from to) |