Issue #301 open

`evil-define-key' for minor mode does not take effect until a state transition

Anonymous created an issue

Unit test. (you can change flyspell to any toggleble minor mode)

(require 'flyspell) (evil-define-key 'normal flyspell-mode-map [f5] (lambda () (interactive) (message "Hey")))

In scratch buffer

M-x: flyspell-mode

press F5, key is not bound. press i then esc, key is now bound

This is a problem because evil is enabled from find-file-hook. before major mode specific hooks are called. If major mode specific hooks enable any minor modes, evil is already initialized, and it does not see those minor modes until a state transition is made, so any bindings for them are in-active

Tested with

GNU Emacs 24.3.1 (x86_64-suse-linux-gnu, X toolkit, Xaw scroll bars) of 2013-05-26 on momoland

Evil from git 8f07f5b0b1fc888428b913e14944e89a0341e7b5

Comments (1)

  1. Frank Fischer repo owner
    • changed status to open

    I've been aware of this problem for some time now. I just do not know a solution. Evil uses special keymaps that hold the bindings, but in order to figure out which of these special keymaps to install Evil checks which other keymaps (flyspell-mode-map here) are active.

    This check is done in evil-normalize-keymaps and this function is run on each state transition. The problem is that I do not know of a reliable way to detect whether a certain command installed a new keymap (or if it enabled or disabled some minor-mode). The only way would be to call evil-normalize-keymaps from a post-command-hook, but normalizing keymaps might be quite expensive.

    I would be happy if some could tell me a good way to check fast when a certain minor-mode has been toggled.

  2. Log in to comment