4

I have a freshly installed spacemacs installation and I want to make it so that I ansi-term is in emacs mode. However, I try to add

(add-to-list 'evil-emacs-state-modes 'term-mode)

to my .spacemacs in the dotspacemacs/user-config and/or dotspacemacs/user-init function and it has no effect.

Is there a canonical way to do this in spacemacs?

wasamasa
  • 21,803
  • 1
  • 65
  • 97

2 Answers2

6

You can use this snippet in your dotspacemacs/user-config function:

(evil-set-initial-state 'term-mode 'emacs)
StreakyCobra
  • 326
  • 1
  • 5
2

Disclaimer: I assume this is in no way related to Spacemacs.

The evil-emacs-state-modes variable is initialized with a list of modes to start in Emacs state. This is a mishap as it makes it harder to customize it properly, any successful change to the variable will not take this value into account and Evil's code will not change it either because the variable is defined and initialized by then. In your example, nothing happens as add-to-list does only do something if the variable has already been defined. You can circumvent this by using a hook run after the package has been loaded up or with eval-after-load:

(eval-after-load 'evil-vars '(add-to-list 'evil-emacs-state-modes 'term-mode))

The official way of changing that list though is via evil-set-initial-state:

(eval-after-load 'evil-vars '(evil-set-initial-state 'term-mode 'emacs))
wasamasa
  • 21,803
  • 1
  • 65
  • 97
  • Great, this worked after putting it in the `dotspacemacs/user-config` (not `dotspacemacs/user-init` since I think spacemacs overrides the behaviour there) – Nathanael Farley Feb 02 '16 at 11:49