hybrid-mode: Cleaner implementation

Using setf is better than using the previous advice, because it was
ignoring the arguments passed to evil-insert-state and the arguments
control whether the state message displays in the minibuffer. In this
version we just switch out the function definition for
evil-insert-state, and all arguments are handled perfectly.

spacemacs-core: Don't defer hybrid-mode

hybrid-mode is now extremely lightweight, and deferring it causes
problems if someone wants to bind keys in hybrid-mode but doesn't have
it selected as their editing style on startup. The reason is the
hybrid-mode keymap will not be available and an error will be thrown.
This requires using eval-after-load in this case, and this seems overly
complicated just to avoid loading this file.
This commit is contained in:
justbur 2015-09-11 13:19:50 -04:00 committed by syl20bnr
parent 3b7d66d118
commit 89443ad220
2 changed files with 8 additions and 15 deletions

View file

@ -55,11 +55,8 @@
(evil-move-cursor-back))))))
(define-key evil-hybrid-state-map [escape] 'evil-normal-state)
(defadvice evil-insert-state (around hybrid-state-advice disable)
"In Hybrid style this advice is run to switch to hybrid
state instead of insert state."
(evil-hybrid-state))
(setf (symbol-function 'hybrid-mode--evil-insert-state-backup)
(symbol-function 'evil-insert-state))
;;;###autoload
(define-minor-mode hybrid-mode
@ -69,10 +66,9 @@ with `evil-hybrid-state-map'."
:lighter " Hy"
:group 'spacemacs
(if hybrid-mode
(progn
(ad-enable-advice 'evil-insert-state 'around 'hybrid-state-advice)
(ad-activate 'evil-insert-state))
(ad-disable-advice 'evil-insert-state 'around 'hybrid-state-advice)
(ad-activate 'evil-insert-state)))
(setf (symbol-function 'evil-insert-state)
(symbol-function 'evil-hybrid-state))
(setf (symbol-function 'evil-insert-state)
(symbol-function 'hybrid-mode--evil-insert-state-backup))))
(provide 'hybrid-mode)

View file

@ -955,8 +955,7 @@ ARG non nil means that the editing style is `vim'."
(defun spacemacs-core/init-hybrid-mode ()
(use-package hybrid-mode
:commands hybrid-mode
:init
:config
(progn
(when (eq 'hybrid dotspacemacs-editing-style) (hybrid-mode))
(spacemacs|add-toggle hybrid-mode
@ -964,9 +963,7 @@ ARG non nil means that the editing style is `vim'."
:on (hybrid-mode)
:off (hybrid-mode -1)
:documentation "Globally toggle hybrid mode."
:evil-leader "E Y"))
:config
(progn
:evil-leader "E Y")
(eval-after-load 'evil-leader
'(define-key evil-hybrid-state-map
(kbd dotspacemacs-emacs-leader-key) evil-leader--default-map)))))