 
 (require-package 'evil)
 (require 'evil)
+(evil-mode)
+
+(cl-loop for mode in dotemacs-evil/emacs-state-minor-modes
+         do (let ((hook (concat (symbol-name mode) "-hook")))
+              (add-hook (intern hook) `(lambda ()
+                                         (if ,mode
+                                             (evil-emacs-state)
+                                           (evil-normal-state))))))
+
+(cl-loop for hook in dotemacs-evil/emacs-state-hooks
+         do (add-hook hook #'evil-emacs-state))
+
+(cl-loop for mode in dotemacs-evil/emacs-state-major-modes
+         do (evil-set-initial-state mode 'emacs))
+ 
 
 (when dotemacs-evil/emacs-insert-mode

(defadvice evil-ex-search-previous (after advice-for-evil-ex-search-previous activate)
  (recenter))

(after 'edebug
  (add-hook 'edebug-mode-hook (lambda ()
                                (if edebug-mode
                                    (evil-emacs-state)
                                  (evil-normal-state)))))

(after 'paren
  (ad-enable-advice #'show-paren-function 'around 'evil)
  (ad-activate #'show-paren-function))

(after 'wgrep
  (defadvice wgrep-change-to-wgrep-mode (before wgrep-change-to-wgrep-mode/before activate)
    (turn-on-evil-mode))
  (defadvice wgrep-to-original-mode (before wgrep-change-to-wgrep-mode/before activate)
    (turn-off-evil-mode)))


(provide 'init-evil)

  "Configuration options for evil-mode."
  :group 'dotemacs
  :prefix 'dotemacs-evil)

(defcustom dotemacs-evil/emacs-state-hooks
  '(org-log-buffer-setup-hook org-capture-mode-hook)
