2

I am trying to remap globally C-/ but the undo-tree package hinders me from doing so. When calling this command (in my init file):

(global-set-key (kbd "C-/") 'left-char)

after having loaded undo-tree (of course), the binding still refers to the undo command.

Any ideas on how to override undo-tree's pervasiveness?

NVaughan
  • 1,481
  • 12
  • 27

3 Answers3

6

You can try this, if you want to remap all keys bound to undo-tree-undo.

 (global-set-key [remap undo-tree-undo] 'left-char)

You can also try making your binding in undo-tree-mode-map, assuming that is what is used by undo-tree-mode:

(add-hook 'undo-tree-mode-hook
          (lambda () (define-key undo-tree-map (kbd "C-/") 'left-char)))

(Usually there is a keymap [mode-name]-map like undo-tree-mode-map. In this case the name is actually undo-tree-map.)

Drew
  • 75,699
  • 9
  • 109
  • 225
  • Thanks. But I really not want either to lose all other bindings to the undo command, or to map them to my other command. – NVaughan Oct 24 '14 at 15:07
  • Do you need the hook? Or could you just modify the map once and for all? – nispio Oct 24 '14 at 15:45
  • 1
    @nispio: You don't need the hook if the library has already been loaded. If it has not been loaded then presumably `undo-tree-mode-map` is not yet defined (unbound variable). – Drew Oct 24 '14 at 15:54
  • @NVaughan: That's why I mentioned the second possibility: just bind that one key, `C-/`, and only do so on `undo-tree-mode-map`. – Drew Oct 24 '14 at 15:55
2

You solution can be achieved in one of the two ways:

  • You define your own minor mode whose key-bindings overrides the bindings set by all other minor/major modes.
  • You set that particular key-binding in that minor/major mode to nil.

These solutions can be implemented in multiple ways and they have been presented in detail in these Emacs SE and SO posts:

Kaushal Modi
  • 25,203
  • 3
  • 74
  • 179
1

I guess you're using Emacs under terminal? Check C-h k C-/ to see what it is.

In my case, when pressing C-/ in terminal, it actually invokes C-_.

kuanyui
  • 1,020
  • 6
  • 16
  • Not using it on terminal. And I get the following: "C-/ runs the command undo-tree-undo, which is an interactive compiled Lisp function in `undo-tree.el'. It is bound to C-_, C-/, C-z, , ." – NVaughan Oct 24 '14 at 03:31