2

I have a package (evil) that isn't playing nice with ansi-term. I am trying to have emacs disable evil-mode when term-mode is active. I am using the following command to try to do so

(add-hook 'term-mode-hook (lambda() (evil-mode -1)) )

However, this somehow disables evil mode in every mode except for term-mode once I open ansi-term. Any help would be appreciated.

phils
  • 71,335
  • 11
  • 153
  • 198
user1539179
  • 1,835
  • 2
  • 16
  • 28
  • Perhaps consider `C-z`, apparently this guy http://blog.binchen.org/?p=651 actually uses evil to solve a problem (unless I'm mistaken) – PascalVKooten Oct 27 '13 at 22:29

4 Answers4

5

A quick look at the code shows that evil-mode is a global minor mode, so it affects all buffers.

The functions turn-on-evil-mode and turn-off-evil-mode are provided to enable or disable evil for the current buffer only (these functions enable or disable evil-local-mode, which is the per-buffer mode), however global minor modes enable themselves after mode hooks have run (see automatically disable a global minor mode for a specific major mode) so it's best to see whether the global mode has some built-in support for disabling itself in specified circumstances.

In the case of evil-mode, it looks like the various "state" options facilitate this, with 'Emacs state' ("emacs") disabling all the Evil key-bindings, and (evil-set-initial-state MODE STATE) letting you configure the default state for a specified major mode.

So unless the incompatibility runs deeper than keybindings, I imagine that the following will do the trick, after loading the Evil library:

(evil-set-initial-state 'term-mode "emacs")
Community
  • 1
  • 1
phils
  • 71,335
  • 11
  • 153
  • 198
  • This gave me the error "Attempt to set a constant symbol: nil". I tried placing it in different parts of my .emacs file, but to no avail – user1539179 Oct 28 '13 at 23:31
  • I guess I must have misinterpreted something. I've added the evil-mode tag to the question; hopefully someone more knowledgeable will clarify. I'm not using Evil myself, so I'm not in a position to test any of this. You should be able to use the advice approach in the linked Q&A (with evil-local-mode), or append a custom after-change-major-mode hook, but it did look like there should be a nicer way. – phils Oct 29 '13 at 00:49
  • 2
    `(evil-set-initial-state 'term-mode 'emacs)` works for me – Nathanael Farley Jul 30 '15 at 13:47
5

I can't reproduce this on my setup (Emacs 24.3, latest Evil from MELPA). Try this:

(add-hook 'term-mode-hook 'evil-emacs-state)

or

(add-hook 'term-mode-hook 'evil-insert-state)

This works for me. (I usually use insert state because I can jump right into normal state quickly).

PythonNut
  • 6,182
  • 1
  • 25
  • 41
  • This (with `evil-emacs-state`) sounds like a working way of doing what I had thought my answer would do. – phils Nov 06 '13 at 22:53
4

I was surprised to reproduce this potential bug.

A solution is to use C-z in the term buffer; it will just break out of evil mode.

PascalVKooten
  • 20,643
  • 17
  • 103
  • 160
0

For vterm, this is what works for me:

(add-hook 'vterm-mode-hook 'evil-emacs-state)
Karlo Guidoni
  • 337
  • 3
  • 9