aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1995-04-14 05:56:31 +0000
committerRichard M. Stallman1995-04-14 05:56:31 +0000
commit37a4f4b6b6669ddcd8723cc668984b3b6d91a7be (patch)
treec3d809faa30cb1e0bf9916ba6a45a43336cc53ba
parent2d7fc7e8f9f019d01a4f02ad28fb6b9abc8404dc (diff)
downloademacs-37a4f4b6b6669ddcd8723cc668984b3b6d91a7be.tar.gz
emacs-37a4f4b6b6669ddcd8723cc668984b3b6d91a7be.zip
(derived-mode-merge-keymaps): Recursively merge prefix key submaps also.
-rw-r--r--lisp/derived.el24
1 files changed, 23 insertions, 1 deletions
diff --git a/lisp/derived.el b/lisp/derived.el
index f48156a1010..a1cfe8485f8 100644
--- a/lisp/derived.el
+++ b/lisp/derived.el
@@ -297,8 +297,30 @@ Always merge its parent into it, since the merge is non-destructive."
297 297
298(defun derived-mode-merge-keymaps (old new) 298(defun derived-mode-merge-keymaps (old new)
299 "Merge an old keymap into a new one. 299 "Merge an old keymap into a new one.
300The old keymap is set to be the cdr of the new one, so that there will 300The old keymap is set to be the last cdr of the new one, so that there will
301be automatic inheritance." 301be automatic inheritance."
302 (let ((tail new))
303 ;; Scan the NEW map for prefix keys.
304 (while (consp tail)
305 (and (consp (car tail))
306 (let* ((key (vector (car (car tail))))
307 (subnew (lookup-key new key))
308 (subold (lookup-key old key)))
309 ;; If KEY is a prefix key in both OLD and NEW, merge them.
310 (and (keymapp subnew) (keymapp subold)
311 (derived-mode-merge-keymaps subold subnew))))
312 (and (vectorp (car tail))
313 ;; Search a vector of ASCII char bindings for prefix keys.
314 (let ((i (1- (length (car tail)))))
315 (while (>= i 0)
316 (let* ((key (vector i))
317 (subnew (lookup-key new key))
318 (subold (lookup-key old key)))
319 ;; If KEY is a prefix key in both OLD and NEW, merge them.
320 (and (keymapp subnew) (keymapp subold)
321 (derived-mode-merge-keymaps subold subnew)))
322 (setq i (1- i)))))
323 (setq tail (cdr tail))))
302 (setcdr (nthcdr (1- (length new)) new) old)) 324 (setcdr (nthcdr (1- (length new)) new) old))
303 325
304(defun derived-mode-merge-syntax-tables (old new) 326(defun derived-mode-merge-syntax-tables (old new)