Hi everyone! I’m looking for help and learning opportunity :) I am improving my emacs configuration following some tutorials, and right now I’m missing something important to understand how keybindings in emacs work. I’ve read Mickey Petersen blog post about this subject (https://www.masteringemacs.org/article/mastering-key-bindings-emacs), but I can’t apply it to my situation.

What I want to achieve

I use general, use-package and evil. I want to use evil keybindings in undo-tree-visualizer-mode to jump between nodes and branches using “j”, “k”, “h”, “l” keys in normal state.

My evil and general config

(use-package evil
  :init      ;; tweak evil's configuration before loading it
  (setq evil-want-integration t) ;; This is optional since it's already set to t by default.
  (setq evil-want-keybinding nil)
  (setq evil-vsplit-window-right t)
  (setq evil-split-window-below t)
  (setq evil-want-C-u-scroll t)
  (setq evil-want-C-i-jump nil)
  (setq evil-respect-visual-line-mode t)
  (setq evil-undo-system 'undo-tree)
  (evil-mode))

(use-package general
  :diminish
  :config
  (general-evil-setup)

What I have tried

  1. Defining keybindings with evil
(with-eval-after-load 'evil-maps
(evil-define-key 'normal undo-tree-visualizer-mode-map (kbd "k") 'undo-tree-visulize-undo)
(evil-define-key 'normal undo-tree-visualizer-mode-map (kbd "j") 'undo-tree-visulize-redo)
(evil-define-key 'normal undo-tree-visualizer-mode-map (kbd "h") 'undo-tree-visulize-switch-branch-left)
(evil-define-key 'normal undo-tree-visualizer-mode-map (kbd "l")
  1. use-package :bind
(use-package undo-tree
  :bind(:map undo-tree-visualizer-mode-map
             ("k" . undo-tree-visualize-undo)
             ("j" . undo-tree-visualize-redo)
             ("h" . undo-tree-visualize-switch-branch-left)
             ("l" . undo-tree-visualize-switch-branch-right))
  :init
  (global-undo-tree-mode 1))
  1. hook-mode
(use-package undo-tree     
  :init     (global-undo-tree-mode 1)     
  :config     
  (add-hook 'udno-tree-visualizer-hook
              (lambda()
              (add-to-list 'evil-previous-visual-line 'undo-tree-visualize-redo))))

I don’t get any errors with these solutions, but still it doesn’t remap keys as I wish to.

What I am missing here? What is the best approach to rebind these keys to undo-tree-visualizer-mode-map?

Will greatly appreciate help in understanding what I am doing wrong :)

  • teoten
    link
    fedilink
    arrow-up
    1
    ·
    10 months ago

    Hey, it seems that the channel is dead, I’m checking old posts out of curiosity and happen to know a thing or 2 about your question.

    It seems to me that your configs are fine, but you are missing a way to enter the undo-tree visualizer. It is bind to C-x u by default. If you want to re-bind it change of undo-tree-visualizd to a global keybinding and you can then use it.

    Id recommend you to stick with the option nr 2, using use-package and :bind, it’s the cleanest.

    Let me know if you still can manage and I’ll try it myself before answering again.