2

There are two bindings for undo-tree-undo(C-_ and C-/) and undo-tree-redo(M-_ and C-?) defined in undo-tree, but now I don't want those bindings(delete those), I just want to bind C-z to undo-tree-undo and C-S-z to undo-tree-redo(short and simple), I tried

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

or

(global-unset-key (kbd "C-_"))

to delete the bindings, they all doesn't work(only work for current session), if I restart Emacs, the C-_ will still be bound to undo-tree-undo.

But if I set above two lines at the same time, the binding will be gone, that's really weird, how can I use one line to delete the bound.

BTW, if you can delete the old bindings and set the new binding(C-z) at the same time, that would be better?

Drew
  • 75,699
  • 9
  • 109
  • 225
CodyChan
  • 2,599
  • 1
  • 19
  • 33
  • I'm going to suggest something that no forum participant will like: It may be time to take complete control of your libraries and modify them to suit your personal needs instead of trying to tweak them here and there. – lawlist Dec 07 '14 at 08:29

1 Answers1

6

To make these bindings persistent, put them into your init file. For them to be able to redefine the undo-tree keymap, undo-tree has to be active first. This can either be guaranteed by enabling undo-tree first (which only works after the packages have been enabled in the respective after-init-hook or after using package-initialize in your init file) or by applying them after its file has been loaded with eval-after-load.

As for rebinding existing functionality, you're able to remap a command to another or swap out a command for the keybinding in question. Neither of those are what you're after. Here's a snippet you can put in your init file that's using `eval-after-load' and explicitly rebinds everything:

(eval-after-load 'undo-tree
  '(progn
     (define-key undo-tree-map (kbd "C-/") nil)
     (define-key undo-tree-map (kbd "C-_") nil)
     (define-key undo-tree-map (kbd "C-?") nil)
     (define-key undo-tree-map (kbd "M-_") nil)
     (define-key undo-tree-map (kbd "C-z") 'undo-tree-undo)
     (define-key undo-tree-map (kbd "C-S-z") 'undo-tree-redo)))
wasamasa
  • 21,803
  • 1
  • 65
  • 97
  • I have `package-initialize` at the beginning of my init file. Although I got `C-/` bound to `helm-semantic-or-imenu` in my init file, `C-?` bound to `ispell-complete-word` in my init file, they still have to be `(define-key undo-tree-map (kbd "...") nil)`(or the manually binding to `helm..` and `ispell..` will not work), the two and `M-_` can be disable using only one line without `eval-after-load`, but the goddamn `C-_` is still there. I think maybe the `C-_` is builtin for `undo` in `emacs -q`, and `M-_` is not. – CodyChan Dec 07 '14 at 00:58
  • I'll just take special care of `C-_`, put the two lines at the same time if there is no better solution. But still thanks. – CodyChan Dec 07 '14 at 01:00