Search code examples
emacselisploadingkey-bindings

Emacs - Key Rebinding Not Working


I want to use Undo Tree Mode, and I have the undo/redo key bindings set up successfully.

However, when I try to overwrite the default C-/ binding with a commenting function I wrote, the combination is still bound to undo-tree-undo.

Here is what I tried:

(eval-after-load 'my-functions
  '(eval-after-load 'undo-tree
    '(define-key global-map (kbd "C-/") 'my-commenting-function)))

I have it load after my-functions so my-commenting-function can be called.

After trying this, with Undo Tree Mode enabled, C-/ is still bound to undo-tree-undo and not my-commenting-function.

How can I change the Undo Tree Mode key binding for C-/ to the function I want?


Solution

  • Do this to define a global binding:

    (global-set-key (kbd "C-/") 'my-commenting-function)
    

    Do this to stop a minor mode from overriding it:

    (define-key undo-tree-map (kbd "C-/") nil)