質問

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.

役に立ちましたか?

解決 2

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).

他のヒント

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")

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.

For vterm, this is what works for me:

(add-hook 'vterm-mode-hook 'evil-emacs-state)
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top