Search code examples
emacskeykeymappingkeymaps

Assign a keymap to a key in Emacs


Is there way in Emacs to assign a key to a keymap with all its bindings? I used to do following:

(defvar my-new-map)
(define-prefix-command 'my-new-map)
(global-set-key (kbd "C-~") my-new-map)
(cl-loop for code being the key-code of flyspell-mode-map
         using (key-bindings b)
         do
         (define-key my-new-map (vector code) b))

This creates a new keymap my-new-map with desired bindings. I would like to just assign C-~ to a flyspell-mode-map without creating a new keymap. Is it possible ?


Solution

  • Yes; you do exactly what you're doing now, just without creating and populating the new keymap.

    (global-set-key (kbd "C-~") flyspell-mode-map)
    

    will assign flyspell-mode-map to that key binding.