evil-mode: How to automatically switch to insert mode after certain commands?

Óscar Fuentes ofv at wanadoo.es
Fri Mar 20 00:34:36 CET 2015


max6166 <max6166 at hotmail.com> writes:

> Thank you very much, Oscar. The above code gives the error:
>
> add-hook: Wrong type argument: symbolp, (evil-visual-post-command
> linum-update-current t) [2 times]

That's because there is a missing quote. The correct call to add-hook
is:

(add-hook 'post-command-hook 'maybe-enter-insert-mode)

>

> Unfortunately, I am new to elisp & emacs so I have no idea how to figure out
> the problem.

The method does not work because post-command-hook is not called with
the expected (by me) value in `last-command' (nor `this-command').

Another approach is to advice `call-interactively'. Again, untested
code:

(defvar maybe-enter-insert-mode-commands
  '(org-insert-heading)
  "List of commands that trigger insert mode.")

(defun maybe-enter-insert-mode (command &rest args)
  (when (memq command maybe-enter-insert-mode-commands)
    (evil-insert-state nil)))

(advice-add 'call-interactively :after 'maybe-enter-insert-mode)


Be warned that this method is quite gross. If your Emacs starts behaving
strangely, the code above can be the cause.




More information about the implementations-list mailing list