Globally override key binding in Emacs

后端 未结 8 2141
栀梦
栀梦 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:50

    Unless you really want to do this yourself, you should check around and see if anyone else already has done it.

    There is a package for Emacs which gives your windows-like keybindings. You should be able to find it through google.

    0 讨论(0)
  • 2020-11-22 07:54

    As an addition to scottfrazer's answer, I've written the following so that my keybindings retain precedence, even if subsequently-loaded libraries bring in new keymaps of their own.

    Because keymaps can be generated at compile time, load seemed like the best place to do this.

    (add-hook 'after-load-functions 'my-keys-have-priority)
    
    (defun my-keys-have-priority (_file)
      "Try to ensure that my keybindings retain priority over other minor modes.
    
    Called via the `after-load-functions' special hook."
      (unless (eq (caar minor-mode-map-alist) 'my-keys-minor-mode)
        (let ((mykeys (assq 'my-keys-minor-mode minor-mode-map-alist)))
          (assq-delete-all 'my-keys-minor-mode minor-mode-map-alist)
          (add-to-list 'minor-mode-map-alist mykeys))))
    
    0 讨论(0)
提交回复
热议问题