1

This question already has an answer here:

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?

marked as duplicate by nispio, paprika, Jonathan Leech-Pepin, nicael, Luke Oct 24 '14 at 19:47

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 3
    Related: How to override major mode bindings – Kaushal Modi Oct 24 '14 at 3:18
  • @kaushalmodi: +1 - My crystal ball tells me that's probably all that is involved here. – Drew Oct 24 '14 at 4:29
  • @kaushalmodi Thanks. That was the solution. If you pose it as such, I will be glad to approve it. – NVaughan Oct 24 '14 at 15:05
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:

  • Thanks. I use the bind-key.el solution, as directly creating a minor mode seemed too difficult. – NVaughan Oct 24 '14 at 15:50
5

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-mode-map (kbd "C-/") 'left-char)))

(I'm just guessing that there is an undo-tree-mode, with this map and this hook.)

  • 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
  • @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
0

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-_.

  • 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, <menu-bar> <edit> <undo>, <undo>." – NVaughan Oct 24 '14 at 3:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.