[PATCH] Fix for issue #301

Max Mikhanosha max at openchat.com
Mon Jun 3 00:07:06 CEST 2013

From e4b59630cf40106d9afaf3544094dc27e3a2e840 Mon Sep 17 00:00:00 2001
From: Max Mikhanosha <max at openchat.com>
Date: Sun, 2 Jun 2013 18:03:27 -0400
Subject: [PATCH] In (evil-define-key) is done for a minor mode, try to
 arrange for `evil-normalize-keymaps' to be called when mode
 is toggled

 evil-core.el | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/evil-core.el b/evil-core.el
index 18e88d6..662cf0e 100644
--- a/evil-core.el
+++ b/evil-core.el
@@ -866,6 +866,16 @@ (defun evil-overriding-keymap-state (map)
+(defun evil-maybe-hook-minor-mode (keymap)
+  "If KEYMAP belongs to a minor mode, add `evil-normalize-keymaps' to mode hook"
+  (when (and (symbolp keymap)
+             (string-match "^\\(.+\\)-\\(?:map\\|keymap\\)$"
+                           (symbol-name keymap)))
+    (let ((mode-symbol (intern (match-string 1 (symbol-name keymap)))))
+      (when (memq mode-symbol minor-mode-list) 
+        (let ((hook-symbol (intern (format "%s-hook" mode-symbol)))) 
+          (add-hook hook-symbol 'evil-normalize-keymaps))))))
 (defmacro evil-define-key (state keymap key def &rest bindings)
   "Create a STATE binding from KEY to DEF for KEYMAP.
 STATE is one of `normal', `insert', `visual', `replace',
@@ -898,7 +908,8 @@ (defmacro evil-define-key (state keymap key def &rest bindings)
             (setq key (pop bindings)
                   def (pop bindings)))
           ;; ensure the prompt string comes first
-          (evil-set-keymap-prompt aux (keymap-prompt aux)))
+          (evil-set-keymap-prompt aux (keymap-prompt aux))
+          (evil-maybe-hook-minor-mode ',keymap))
      'after-load-functions t nil
      (format "evil-define-key-in-%s"
              ',(if (symbolp keymap) keymap 'keymap))))

More information about the implementations-list mailing list