2

I want two keymaps to be "roughly" the same in Emacs. In particular, I want the keymap for the "super" key to default to doing what the "meta" key does.

So, I would like to write some code that copies the contents of the meta-keymap to the super-keymap. Something like the following:

(defun copy-one-key (from-keymap to-keymap key-sequence)
   ;; don't bind keys already bound
   (unless (get-key-binding to-keymap key-sequence)
      (set-key-binding to-key-map key-sequence
         (get-key-binding from-keymap key-sequence)
         ) ; set
      ) ; when
   ) ; defun

(defun copy-keymap (from-keymap to-keymap)
   (mapcar from-keymap 
      (lambda key-sequence 
          (copy-one-key from-keymap to-keymap key-sequence)
          ) ; lambda
       ) ; mapcar
    ) ; defun

(copy-keymap meta-keymap super-keymap)

In a related issue. I don't know if there actually are named keymaps for the meta-keymap and super-keymap of if I somehow need to parse them out of the global-keymap looking for "M-" and changing it to "s-".

I forgot to add that I essentially want to add an advice to every function I copy.

intel_chris
  • 708
  • 1
  • 6
  • 17
  • 1
    Have you tried using the built-in function `copy-keymap` (`C-h f copy-keymap`)? – Drew May 13 '19 at 14:00
  • 1
    you can define a keymap with a prefix key using `define-prefix-command`. I would use `set-keymap-parent` as an efficient alternative to copying. BTW there is a function `map-keymap` as well – Rorschach May 13 '19 at 21:50

0 Answers0