I want to use evil mode with ggtags but evil mode keeps taking some of the bindings such as M-.. I'm new to emacs and I'm interested in learning what's going on. At first I tried explicitly setting the load order by using a lambda like this:

(add-hook 'prog-mode-hook
          '(lambda ()

             (when (derived-mode-p 'c-mode 'c++-mode 'java-mode 'rust-mode)
               (ggtags-mode 1))))

I then saw evil-overriding-maps and evil-intercept-maps but using them seemed to have no effect:

(add-to-list 'evil-overriding-maps '(ggtags-mode-map . nil) t)
(add-to-list 'evil-intercept-maps '(ggtags-mode-map . nil) t)

I realize that I could just explicitly bind to 'ggtags-find-tag-dwim in one of the evil maps, but like I said I'm learning emacs and I'm wondering what's going on here and more importantly if there's a way to make it work without redoing all of the bindings that got clobbered. I figured using evil-overriding-maps should do the trick but it doesn't seem to be. I did check the value of the variable with C-h v and it did get added to that list.


Similar questions have been asked so many times. Basically you want other minor-mode's keybindings take priority. No one can answer this question better than EVIL developer himself.

Here is the code

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

M-. is looked up in loads of keymaps and a possible command to use is found in evil-normal-state-map. The easiest way around this is unbinding it there to allow Emacs to continue looking it up in other possible keymaps:

(eval-after-load 'evil-maps
  '(define-key evil-normal-state-map (kbd "M-.") nil))
  • Since OP is just starting out with emacs, could you add a little description to the code, please?
    – Dan
    Jul 22 '15 at 11:10
  • I assumed that someone wielding more complex code than me would understand it immediately, but eh.
    – wasamasa
    Jul 22 '15 at 11:41
  • Thanks, this works of course but I wanted to know how to use the overriding system instead of manually unmapping each key that got clobbered. Jul 22 '15 at 22:38
  • Well, considering most of ggtags maps are used in special buffers and it's only relatively few keybindings Evil occupies, it makes more sense for me to selectively disable these instead of using the alternative hack for every package conflicting with it.
    – wasamasa
    Jul 22 '15 at 23:03

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.