Function: derived-mode-merge-keymaps

derived-mode-merge-keymaps is a byte-compiled function defined in derived.el.gz.

Signature

(derived-mode-merge-keymaps OLD NEW)

Documentation

Merge an OLD keymap into a NEW one.

The old keymap is set to be the last cdr of the new one, so that there will be automatic inheritance.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/derived.el.gz
;; Functions to merge maps and tables.

(defun derived-mode-merge-keymaps (old new)
  "Merge an OLD keymap into a NEW one.
The old keymap is set to be the last cdr of the new one, so that there will
be automatic inheritance."
  ;; ?? Can this just use `set-keymap-parent'?
  (let ((tail new))
    ;; Scan the NEW map for prefix keys.
    (while (consp tail)
      (and (consp (car tail))
	   (let* ((key (vector (car (car tail))))
		  (subnew (lookup-key new key))
		  (subold (lookup-key old key)))
	     ;; If KEY is a prefix key in both OLD and NEW, merge them.
	     (and (keymapp subnew) (keymapp subold)
		  (derived-mode-merge-keymaps subold subnew))))
      (and (vectorp (car tail))
	   ;; Search a vector of ASCII char bindings for prefix keys.
	   (let ((i (1- (length (car tail)))))
	     (while (>= i 0)
	       (let* ((key (vector i))
		      (subnew (lookup-key new key))
		      (subold (lookup-key old key)))
		 ;; If KEY is a prefix key in both OLD and NEW, merge them.
		 (and (keymapp subnew) (keymapp subold)
		      (derived-mode-merge-keymaps subold subnew)))
	       (setq i (1- i)))))
      (setq tail (cdr tail))))
  (setcdr (nthcdr (1- (length new)) new) old))