- (let (allbind bind minorbind localbind globalbind)
- (setq bind (key-binding keyseq))
- ;; If KEYSEQ is a prefix key, then BIND is either nil
- ;; or a symbol defined as a keymap (which satisfies keymapp).
- (if (keymapp bind)
- (setq bind nil))
- ;; If we have a non-keymap definition, return that.
- (or bind
- (progn
- ;; Otherwise, it is a prefix, so make a list of the subcommands.
- ;; Make a list of all the bindings in all the keymaps.
- ;; FIXME: we'd really like to just use `key-binding' now that it
- ;; returns a keymap that contains really all the bindings under that
- ;; prefix, but `keyseq' is always [menu-bar], so the desired order of
- ;; the bindings is difficult to recover.
- (setq minorbind (mapcar 'cdr (minor-mode-key-binding keyseq)))
- (setq localbind (local-key-binding keyseq))
- (setq globalbind (copy-sequence (cdr (global-key-binding keyseq))))
-
- ;; If items have been redefined/undefined locally, remove them from
- ;; the global list.
- (dolist (minor minorbind)
- (dolist (item (cdr minor))
- (setq globalbind (assq-delete-all (car-safe item) globalbind))))
- (dolist (item (cdr localbind))
- (setq globalbind (assq-delete-all (car-safe item) globalbind)))
-
- (setq globalbind (cons 'keymap globalbind))
- (setq allbind (cons globalbind (cons localbind minorbind)))
-
- ;; Merge all the elements of ALLBIND into one keymap.
- (dolist (in allbind)
- (if (and (symbolp in) (keymapp in))
- (setq in (symbol-function in)))
- (and in (keymapp in)
- (setq bind (if (keymapp bind)
- (nconc bind (copy-sequence (cdr in)))
- (copy-sequence in)))))
- ;; Return that keymap.
- bind))))