Globally override key binding in Emacs

后端 未结 8 2329
栀梦
栀梦 2020-11-22 06:51

How can I set a key binding that globally overrides and takes precedence over all other bindings for that key? I want to override all major/minor mode maps and make sure my

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 07:32

    If you want to "always use the keybinds in the map, unless I explicitly override them for a specific mode-map", and assuming you are using scottfrazier's approach, you want:

    (defun locally-override (key cmd)
      (unless (local-variable-p 'my-keys-minor-mode-map)
        (set (make-variable-buffer-local 'my-keys-minor-mode-map)
             (make-sparse-keymap))
        (set-keymap-parent my-keys-minor-mode-map 
                           (default-value 'my-keys-minor-mode-map)))
      (define-key my-keys-minor-mode-map key cmd))
    

    So

    (locally-override "\C-i" nil)
    

    should remove the "\C-i" binding from the minor mode in the current buffer only. Warning: this is completely untested, but seems like the right approach. The point of setting the parent rather than just coping the global value of my-keys-minor-mode-map is so any later changes to the global value are automatically reflected in the local value.

提交回复
热议问题