How do I disable evil-mode in a buffer in which git-timemachine is activated?

  • 1
    evil-mode is a global minor mode, what you're probably after is not disabling it alltogether (since that would disable it anywhere else, too). – wasamasa Mar 5 '15 at 15:10

This answer is directly from the EVIL developer Frank Fischer,

I tested on Emacs24.4 with latest evil1.0.9+. Most evil key bindings still works, but we let git-timemachine's hotkeys take priority.

;; @see https://bitbucket.org/lyro/evil/issue/511/let-certain-minor-modes-key-bindings
(eval-after-load 'git-timemachine
     (evil-make-overriding-map git-timemachine-mode-map 'normal)
     ;; force update evil keymaps after git-timemachine-mode loaded
     (add-hook 'git-timemachine-mode-hook #'evil-normalize-keymaps)))

This piece of advice will toggle evil-local-mode: disabling it when you enable git-timemachine-mode, and enabling it when you turn off git-timemachine-mode:

(defadvice git-timemachine-mode (after toggle-evil activate)
  "Turn off `evil-local-mode' when enabling
`git-timemachine-mode', and turn it back on when disabling
  (evil-local-mode (if git-timemachine-mode -1 1)))
  • Thanks, this is exactly what I was looking for. Sadly it's not working though. Could it be because git-timemachine-mode is activated by calling git-timemachine (i.e. without -mode at the end)? – lukerandall Mar 7 '15 at 17:02

If you want evil to be in emacs mode when you launch git-timemachine, try that: http://wikemacs.org/wiki/Evil#Enter_an_emacs_mode_in_a_given_state

In a nutshell, try

(evil-set-initial-state 'git-timemachine 'emacs)
  • I'm not sure this will work if, as @wasamusa notes, git-timemachine is a minor mode rather than a major mode. – Dan Mar 6 '15 at 14:50
  • That's totally not what I was hinting at. But thanks for the information, that calls for a different way of solving it. – wasamasa Mar 6 '15 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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