switching states via hooks

Leo Alekseyev dnquark at gmail.com
Mon Jan 16 01:25:32 CET 2012


>
> Evil chooses the initial state for the buffer on the basis on its
> major mode (well, it's usually the major mode -- minor modes can
> also be configured in this way). Because certain modes jump through
> some hoops as part of their initialization, Evil postpones its own
> initialization with `post-command-hook'. This only happens once, so
> when evaluating (my-switch-to-emacs-state-hook) by hand, after Evil's
> initialization is finished, the switch works.
>
> To set the initial state for a mode, use `evil-set-initial-state'.
> Alternatively, you can force the initialization process with an
> argument to `evil-initialize-state' (after commit 3b7d2e3):
>
>    (defun my-switch-to-emacs-state-hook ()
>      (when evil-mode (evil-initialize-state 'emacs)))
>
> This will immediately set the initial state for the buffer, instead
> of waiting for `post-command-hook'.

Well, I feel silly.  I didn't even try evil-set-initial-state with a
minor mode, but it works like a charm.

--l



More information about the implementations-list mailing list